2017-12-04 11:22:53 +00:00
|
|
|
import { cfg } from "./cfg";
|
2017-12-04 12:12:02 +00:00
|
|
|
import { irc as irclib } from "../clients/irc";
|
|
|
|
import { tg as tglib } from "../clients/tg";
|
2017-12-04 11:22:53 +00:00
|
|
|
|
|
|
|
import util from "util";
|
|
|
|
import EventEmitter from "events";
|
2017-11-08 11:56:04 +00:00
|
|
|
|
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-12-04 11:22:53 +00:00
|
|
|
export { wrapper, clients };
|