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(), trigger: trigger }; fs.readdirSync(`${__dirname}/inc/trigger/`).forEach(file => { if(file.substr(-3, 3) === ".js") { logger.info(`(main) loading trigger: ${file}`); require(`${__dirname}/inc/trigger/${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`); }); }); function trigger(args) { this.call = args.call; this.level = args.level || 0; this.active = args.hasOwnProperty("active") ? args.active : true; this.clients = args.clients || ["irc", "tg"]; this.f = args.f; }