es6ify
This commit is contained in:
parent
95d76163e3
commit
a225922753
30
src/bot.mjs
30
src/bot.mjs
@ -6,28 +6,20 @@ import triggers from "./inc/trigger";
|
||||
import events from "./inc/events";
|
||||
|
||||
read().then(() => {
|
||||
let bot = new wrapper();
|
||||
|
||||
const self = {
|
||||
_trigger: new Map(),
|
||||
trigger: trigger,
|
||||
bot: bot
|
||||
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", "discord"];
|
||||
this.f = args.f;
|
||||
},
|
||||
bot: new wrapper()
|
||||
};
|
||||
|
||||
triggers.forEach(mod => mod(self));
|
||||
events.forEach(event => event(self));
|
||||
|
||||
})
|
||||
.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;
|
||||
}
|
||||
}).catch(err => logger.error(`(main) ${err.message}`));
|
||||
|
@ -3,46 +3,47 @@ import { irc as irclib } from "../clients/irc";
|
||||
import { tg as tglib } from "../clients/tg";
|
||||
import { discord as discordlib } from "../clients/discord";
|
||||
|
||||
import util from "util";
|
||||
import EventEmitter from "events";
|
||||
|
||||
const clients = [];
|
||||
|
||||
const wrapper = function () {
|
||||
for (let srv in cfg.client) {
|
||||
if(cfg.client[srv].val.enabled) {
|
||||
switch (cfg.client[srv].val.type) {
|
||||
case "irc":
|
||||
clients.push({
|
||||
name: cfg.client[srv].val.network,
|
||||
type: "irc",
|
||||
client: new irclib(cfg.client[srv].val)
|
||||
});
|
||||
break;
|
||||
case "tg":
|
||||
clients.push({
|
||||
name: "tg",
|
||||
type: "tg",
|
||||
client: new tglib(cfg.client[srv].val)
|
||||
});
|
||||
break;
|
||||
case "discord":
|
||||
clients.push({
|
||||
name: "discord",
|
||||
type: "discord",
|
||||
client: new discordlib(cfg.client[srv].val)
|
||||
});
|
||||
break;
|
||||
const wrapper = class wrapper extends EventEmitter {
|
||||
constructor() {
|
||||
super();
|
||||
for (let srv in cfg.client) {
|
||||
if(cfg.client[srv].val.enabled) {
|
||||
switch (cfg.client[srv].val.type) {
|
||||
case "irc":
|
||||
clients.push({
|
||||
name: cfg.client[srv].val.network,
|
||||
type: "irc",
|
||||
client: new irclib(cfg.client[srv].val)
|
||||
});
|
||||
break;
|
||||
case "tg":
|
||||
clients.push({
|
||||
name: "tg",
|
||||
type: "tg",
|
||||
client: new tglib(cfg.client[srv].val)
|
||||
});
|
||||
break;
|
||||
case "discord":
|
||||
clients.push({
|
||||
name: "discord",
|
||||
type: "discord",
|
||||
client: new discordlib(cfg.client[srv].val)
|
||||
});
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
clients.forEach(client => {
|
||||
client.client.on("data", e => {
|
||||
this.emit(e[0], e[1]);
|
||||
clients.forEach(client => {
|
||||
client.client.on("data", e => {
|
||||
this.emit(e[0], e[1]);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
util.inherits(wrapper, EventEmitter);
|
||||
export { wrapper, clients };
|
Loading…
Reference in New Issue
Block a user