Uwev2/src/inc/wrapper.js

38 lines
826 B
JavaScript
Raw Normal View History

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) {
switch (cfg.client[srv].type) {
2017-11-18 10:53:58 +00:00
case "irc":
clients.push({
name: cfg.client[srv].network,
type: "irc",
client: new irclib(cfg.client[srv])
});
break;
case "tg":
clients.push({
name: "tg",
type: "tg",
client: new tglib(cfg.client[srv])
});
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 };