This commit is contained in:
Flummi
2020-04-02 04:35:28 +02:00
parent 5ff96cdf5e
commit d39deeb038
100 changed files with 34498 additions and 1100 deletions

View File

@ -1,28 +1,51 @@
import cfg from "../config.json";
import { cuffeo } from "cuffeo";
import cuffeo from "cuffeo";
import { promises as fs } from "fs";
import triggers from "./inc/trigger";
import events from "./inc/events";
import "./websrv";
import "./websrv.mjs";
(async () => {
// Chatbots
/*const self = {
const self = {
_trigger: new Map(),
trigger: function trigger(args) {
this.call = args.call;
this.help = args.help || false;
this.level = args.level || 0;
this.active = args.hasOwnProperty("active") ? args.active : true;
this.set = args.set || "all"; // uwe, nxy, f0ck, all
this.clients = args.clients || ["irc", "tg"];
this.clients = args.clients || [ "irc", "tg", "slack" ];
this.f = args.f;
},
bot: new cuffeo(cfg.clients)
bot: await new cuffeo(cfg.clients)
};
triggers.forEach(mod => mod(self));
events.forEach(event => event(self));*/
//
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"))
};
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");
})();