2019-04-25 01:20:20 +00:00
|
|
|
import cfg from "../config.json";
|
2020-04-02 02:35:28 +00:00
|
|
|
import cuffeo from "cuffeo";
|
|
|
|
import { promises as fs } from "fs";
|
2018-09-02 10:07:40 +00:00
|
|
|
|
2020-04-02 02:35:28 +00:00
|
|
|
import "./websrv.mjs";
|
2019-04-25 18:00:47 +00:00
|
|
|
|
2019-04-25 01:20:20 +00:00
|
|
|
(async () => {
|
2020-04-02 02:35:28 +00:00
|
|
|
const self = {
|
2018-09-02 10:07:40 +00:00
|
|
|
_trigger: new Map(),
|
|
|
|
trigger: function trigger(args) {
|
|
|
|
this.call = args.call;
|
|
|
|
this.help = args.help || false;
|
|
|
|
this.level = args.level || 0;
|
2021-01-25 19:30:39 +00:00
|
|
|
this.name = args.name;
|
2018-09-02 10:07:40 +00:00
|
|
|
this.active = args.hasOwnProperty("active") ? args.active : true;
|
2020-04-02 02:35:28 +00:00
|
|
|
this.clients = args.clients || [ "irc", "tg", "slack" ];
|
2018-09-02 10:07:40 +00:00
|
|
|
this.f = args.f;
|
|
|
|
},
|
2020-04-02 02:35:28 +00:00
|
|
|
bot: await new cuffeo(cfg.clients)
|
|
|
|
};
|
|
|
|
|
|
|
|
console.time("loading");
|
|
|
|
const modules = {
|
|
|
|
events: (await fs.readdir("./src/inc/events")).filter(f => f.endsWith(".mjs")),
|
|
|
|
trigger: (await fs.readdir("./src/inc/trigger")).filter(f => f.endsWith(".mjs"))
|
2018-09-02 10:07:40 +00:00
|
|
|
};
|
2019-04-25 01:20:20 +00:00
|
|
|
|
2020-04-02 02:35:28 +00:00
|
|
|
console.timeLog("loading", "directories");
|
|
|
|
const blah = (await Promise.all(Object.entries(modules).map(async ([dir, mods]) => ({
|
|
|
|
[dir]: (await Promise.all(mods.map(async mod => {
|
|
|
|
const res = await Promise.race([
|
|
|
|
(await import(`./inc/${dir}/${mod}`)).default(self),
|
|
|
|
new Promise((_, rej) => setTimeout(() => rej(false), timeout))
|
|
|
|
]);
|
|
|
|
console.timeLog("loading", `${dir}/${mod}`);
|
|
|
|
return res;
|
|
|
|
}))).flat(2)
|
|
|
|
})))).reduce((a, b) => ({...a, ...b}));
|
|
|
|
|
|
|
|
blah.events.forEach(event => {
|
|
|
|
console.timeLog("loading", `registering event > ${event.name}`);
|
|
|
|
self.bot.on(event.listener, event.f);
|
|
|
|
});
|
|
|
|
|
|
|
|
blah.trigger.forEach(trigger => {
|
|
|
|
console.timeLog("loading", `registering trigger > ${trigger.name}`);
|
|
|
|
self._trigger.set(trigger.name, new self.trigger(trigger));
|
|
|
|
});
|
|
|
|
|
|
|
|
console.timeEnd("loading");
|
|
|
|
|
2019-04-25 01:20:20 +00:00
|
|
|
})();
|