This commit is contained in:
Flummi 2018-03-01 07:02:33 +01:00
parent 95d76163e3
commit a225922753
2 changed files with 44 additions and 51 deletions

View File

@ -6,28 +6,20 @@ import triggers from "./inc/trigger";
import events from "./inc/events"; import events from "./inc/events";
read().then(() => { read().then(() => {
let bot = new wrapper();
const self = { const self = {
_trigger: new Map(), _trigger: new Map(),
trigger: trigger, trigger: function trigger(args) {
bot: bot 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", "discord"];
this.f = args.f;
},
bot: new wrapper()
}; };
triggers.forEach(mod => mod(self)); triggers.forEach(mod => mod(self));
events.forEach(event => event(self)); events.forEach(event => event(self));
}).catch(err => logger.error(`(main) ${err.message}`));
})
.catch(err => {
logger.error(`(main) ${err.message}`);
});
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", "discord"];
this.f = args.f;
}

View File

@ -3,46 +3,47 @@ import { irc as irclib } from "../clients/irc";
import { tg as tglib } from "../clients/tg"; import { tg as tglib } from "../clients/tg";
import { discord as discordlib } from "../clients/discord"; import { discord as discordlib } from "../clients/discord";
import util from "util";
import EventEmitter from "events"; import EventEmitter from "events";
const clients = []; const clients = [];
const wrapper = function () { const wrapper = class wrapper extends EventEmitter {
for (let srv in cfg.client) { constructor() {
if(cfg.client[srv].val.enabled) { super();
switch (cfg.client[srv].val.type) { for (let srv in cfg.client) {
case "irc": if(cfg.client[srv].val.enabled) {
clients.push({ switch (cfg.client[srv].val.type) {
name: cfg.client[srv].val.network, case "irc":
type: "irc", clients.push({
client: new irclib(cfg.client[srv].val) name: cfg.client[srv].val.network,
}); type: "irc",
break; client: new irclib(cfg.client[srv].val)
case "tg": });
clients.push({ break;
name: "tg", case "tg":
type: "tg", clients.push({
client: new tglib(cfg.client[srv].val) name: "tg",
}); type: "tg",
break; client: new tglib(cfg.client[srv].val)
case "discord": });
clients.push({ break;
name: "discord", case "discord":
type: "discord", clients.push({
client: new discordlib(cfg.client[srv].val) name: "discord",
}); type: "discord",
break; client: new discordlib(cfg.client[srv].val)
});
break;
}
} }
} }
}
clients.forEach(client => { clients.forEach(client => {
client.client.on("data", e => { client.client.on("data", e => {
this.emit(e[0], e[1]); this.emit(e[0], e[1]);
});
}); });
}); }
}; };
util.inherits(wrapper, EventEmitter);
export { wrapper, clients }; export { wrapper, clients };