2017-12-04 11:22:53 +00:00
|
|
|
import { logger } from "./inc/log";
|
|
|
|
import { read, cfg } from "./inc/cfg";
|
|
|
|
import { wrapper } from "./inc/wrapper";
|
|
|
|
|
|
|
|
import triggers from "./inc/trigger/main";
|
2017-11-07 17:22:41 +00:00
|
|
|
|
|
|
|
read().then(() => {
|
2017-11-08 11:56:04 +00:00
|
|
|
let bot = new wrapper();
|
2017-11-20 16:30:20 +00:00
|
|
|
|
|
|
|
const self = {
|
2017-11-26 23:00:54 +00:00
|
|
|
_trigger: new Map(),
|
|
|
|
trigger: trigger
|
2017-11-20 16:30:20 +00:00
|
|
|
};
|
|
|
|
|
2017-12-04 13:59:42 +00:00
|
|
|
triggers.forEach(mod => mod(self));
|
2017-11-20 16:30:20 +00:00
|
|
|
|
2017-12-04 12:03:21 +00:00
|
|
|
bot.on("message", e => {
|
2017-11-20 16:30:20 +00:00
|
|
|
for (var [name, trigger] of self._trigger.entries()) {
|
|
|
|
if (!trigger.call.exec(e.message))
|
|
|
|
continue;
|
|
|
|
if (!trigger.clients.includes(e.type))
|
|
|
|
continue;
|
2017-11-08 21:29:43 +00:00
|
|
|
|
2017-11-20 16:30:20 +00:00
|
|
|
let active = false;
|
2017-11-22 04:44:02 +00:00
|
|
|
if (e.type === "irc" && cfg.trigger[e.network + e.channel]) {
|
2017-11-20 16:30:20 +00:00
|
|
|
if (cfg.trigger[e.network + e.channel][trigger.name])
|
|
|
|
active = true;
|
2017-11-09 14:34:21 +00:00
|
|
|
}
|
2017-11-20 16:30:20 +00:00
|
|
|
else
|
|
|
|
active = trigger.active;
|
|
|
|
if (!active)
|
|
|
|
continue;
|
|
|
|
|
2017-11-25 12:31:26 +00:00
|
|
|
if (trigger.level > e.user.level.level) {
|
|
|
|
e.reply(`no permission, min level ${trigger.level} required`);
|
|
|
|
break;
|
|
|
|
}
|
2017-11-27 00:29:09 +00:00
|
|
|
|
|
|
|
e = Object.assign(e, parseArgs(e.message));
|
2017-11-20 16:30:20 +00:00
|
|
|
trigger.f(e);
|
2017-11-10 09:21:38 +00:00
|
|
|
}
|
2017-11-19 22:03:13 +00:00
|
|
|
logger.info(`${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}`);
|
2017-11-08 11:56:04 +00:00
|
|
|
});
|
2017-11-19 22:03:13 +00:00
|
|
|
|
2017-11-18 10:53:58 +00:00
|
|
|
bot.on("ctcp:version", e => {
|
2017-11-28 15:39:11 +00:00
|
|
|
const versions = [
|
|
|
|
"AmIRC.1 (8 Bit) for Commodore Amiga 500",
|
|
|
|
"HexChat 0.72 [x86] / Windows 95c [500MHz]"
|
|
|
|
];
|
|
|
|
e.write(`notice ${e.user.nick} :\u0001VERSION ${versions[~~(Math.random() * versions.length)]}\u0001`);
|
2017-11-09 14:34:21 +00:00
|
|
|
});
|
2017-11-28 01:27:25 +00:00
|
|
|
})
|
|
|
|
.catch(err => {
|
2017-12-03 16:55:36 +00:00
|
|
|
logger.error(`(main) ${err.message}`);
|
2017-11-26 23:00:54 +00:00
|
|
|
});
|
|
|
|
|
2017-11-26 23:09:41 +00:00
|
|
|
function trigger(args) {
|
2017-11-26 23:00:54 +00:00
|
|
|
this.call = args.call;
|
2017-12-04 16:40:24 +00:00
|
|
|
this.help = args.help || false;
|
2017-11-26 23:00:54 +00:00
|
|
|
this.level = args.level || 0;
|
2017-11-26 23:09:41 +00:00
|
|
|
this.active = args.hasOwnProperty("active") ? args.active : true;
|
2018-02-27 08:24:32 +00:00
|
|
|
this.clients = args.clients || ["irc", "tg", "discord"];
|
2017-11-26 23:00:54 +00:00
|
|
|
this.f = args.f;
|
2017-11-27 00:29:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const parseArgs = (msg) => {
|
|
|
|
let args = msg.trim().split(" ");
|
|
|
|
let cmd = args.shift();
|
|
|
|
return {
|
|
|
|
cmd: cmd.replace(/^(\.|\/|\!)/, ""),
|
|
|
|
args: args
|
|
|
|
};
|
|
|
|
};
|