import { logger } from "./inc/log.js"; import { read, cfg } from "./inc/cfg.js"; import { wrapper, clients } from "./inc/wrapper.js"; const fs = require("fs"); read().then(() => { let bot = new wrapper(); const self = { _trigger: new Map() }; const files = fs.readdirSync(`${__dirname}/inc/trigger/`); for (let file in files) { if (files[file].substr(-3, 3) === ".js") { logger.info(`(main) loading trigger: ${files[file]}`); require(`${__dirname}/inc/trigger/${files[file]}`)(self); } } bot.on("message", e => { // Todo: eventhandler for (var [name, trigger] of self._trigger.entries()) { if (!trigger.call.exec(e.message)) continue; if (!trigger.clients.includes(e.type)) continue; let active = false; if (e.type === "irc" && cfg.trigger[e.network + e.channel]) { if (cfg.trigger[e.network + e.channel][trigger.name]) active = true; } else active = trigger.active; if (!active) continue; if (trigger.level > e.user.level.level) { e.reply(`no permission, min level ${trigger.level} required`); break; } trigger.f(e); } logger.info(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}`); }); bot.on("ctcp:version", e => { e.write(`notice ${e.user.nick} :\u0001VERSION Pimmel 2.1\u0001`); }); });