Uwev2/src/bot.js

50 lines
1.4 KiB
JavaScript
Raw Normal View History

2017-11-19 22:03:13 +00:00
import { logger } from "./inc/log.js";
2017-11-20 16:30:20 +00:00
import { read, cfg } from "./inc/cfg.js";
2017-11-18 10:53:58 +00:00
import { wrapper, clients } from "./inc/wrapper.js";
2017-11-20 16:30:20 +00:00
const fs = require("fs");
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 = {
_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);
}
}
2017-11-18 10:53:58 +00:00
bot.on("message", e => { // Todo: eventhandler
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-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 => {
e.write(`notice ${e.user.nick} :\u0001VERSION Pimmel 2.1\u0001`);
2017-11-09 14:34:21 +00:00
});
2017-11-08 18:43:08 +00:00
});