import { logger } from "../log"; import { read, cfg } from "../cfg"; const parseArgs = (msg) => { let args = msg.trim().split(" "); let cmd = args.shift(); return { cmd: cmd.replace(/^(\.|\/|\!)/, ""), args: args }; }; export default self => { self.bot.on("message", e => { 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 ((e.self.set !== "all" && e.self.set !== trigger.set) && trigger.set !== "all") continue; if (trigger.level > e.user.level.level) { e.reply(`no permission, min level ${trigger.level} required`); break; } e = Object.assign(e, parseArgs(e.message)); trigger.f(e); } logger.info(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}`); }); };