Uwev2/src/inc/wrapper.js

39 lines
900 B
JavaScript
Raw Normal View History

2017-11-08 11:56:04 +00:00
import { cfg, read } from './cfg.js';
2017-11-11 22:13:47 +00:00
//import { loadEvents } from './lib.js';
2017-11-08 11:56:04 +00:00
2017-11-09 14:34:21 +00:00
const irclib = require('./clients/irc.js');
const tglib = require('./clients/tg.js')
2017-11-08 11:56:04 +00:00
const util = require('util');
2017-11-09 14:34:21 +00:00
const EventEmitter = require('events').EventEmitter;
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-08 20:40:59 +00:00
case "irc":
clients.push({
name: cfg.client[srv].network,
type: "irc",
client: new irclib(cfg.client[srv])
});
2017-11-09 11:21:40 +00:00
break;
2017-11-08 20:40:59 +00:00
case "tg":
clients.push({
name: "tg",
type: "tg",
2017-11-08 21:52:20 +00:00
client: new tglib(cfg.client[srv])
2017-11-08 20:40:59 +00:00
});
2017-11-09 11:21:40 +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 };