2017-11-18 10:53:58 +00:00
|
|
|
import { cfg } from "./cfg.js";
|
2017-11-08 11:56:04 +00:00
|
|
|
|
2017-11-18 10:53:58 +00:00
|
|
|
const irclib = require("./clients/irc.js");
|
|
|
|
const tglib = require("./clients/tg.js");
|
|
|
|
const util = require("util");
|
2017-11-08 11:56:04 +00:00
|
|
|
|
2017-11-18 10:53:58 +00:00
|
|
|
const EventEmitter = require("events").EventEmitter;
|
2017-11-09 14:34:21 +00:00
|
|
|
const clients = [];
|
2017-11-08 11:56:04 +00:00
|
|
|
|
2017-11-09 11:21:40 +00:00
|
|
|
const wrapper = function () {
|
|
|
|
for (let srv in cfg.client) {
|
2017-11-22 04:44:02 +00:00
|
|
|
if(cfg.client[srv].val.enabled) {
|
|
|
|
switch (cfg.client[srv].val.type) {
|
2017-11-19 09:19:17 +00:00
|
|
|
case "irc":
|
|
|
|
clients.push({
|
2017-11-22 04:44:02 +00:00
|
|
|
name: cfg.client[srv].val.network,
|
2017-11-19 09:19:17 +00:00
|
|
|
type: "irc",
|
2017-11-22 04:44:02 +00:00
|
|
|
client: new irclib(cfg.client[srv].val)
|
2017-11-19 09:19:17 +00:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
case "tg":
|
|
|
|
clients.push({
|
|
|
|
name: "tg",
|
|
|
|
type: "tg",
|
2017-11-22 04:44:02 +00:00
|
|
|
client: new tglib(cfg.client[srv].val)
|
2017-11-19 09:19:17 +00:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
2017-11-08 20:40:59 +00:00
|
|
|
}
|
|
|
|
}
|
2017-11-08 11:56:04 +00:00
|
|
|
|
2017-11-08 19:30:21 +00:00
|
|
|
clients.forEach(client => {
|
2017-11-09 14:34:21 +00:00
|
|
|
client.client.on("data", e => {
|
|
|
|
this.emit(e[0], e[1]);
|
2017-11-08 19:30:21 +00:00
|
|
|
});
|
|
|
|
});
|
2017-11-08 11:56:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
util.inherits(wrapper, EventEmitter);
|
2017-11-08 21:29:43 +00:00
|
|
|
export default { wrapper, clients };
|