2017-11-08 11:56:04 +00:00
|
|
|
import { cfg, read } from './cfg.js';
|
|
|
|
import { loadEvents } from './lib.js';
|
|
|
|
|
2017-11-08 21:52:20 +00:00
|
|
|
let irclib = require('./clients/irc.js');
|
|
|
|
let tglib = require('./clients/tg.js')
|
|
|
|
//let tglib = require('node-telegram-bot-api');
|
2017-11-08 18:43:08 +00:00
|
|
|
//const safeEval = require('safe-eval');
|
2017-11-08 11:56:04 +00:00
|
|
|
const util = require('util');
|
2017-11-08 18:43:08 +00:00
|
|
|
//const fs = require('fs');
|
|
|
|
//const ytdl = util.promisify(require('youtube-dl').getInfo);
|
2017-11-08 11:56:04 +00:00
|
|
|
|
|
|
|
var EventEmitter = require('events').EventEmitter;
|
2017-11-08 19:30:21 +00:00
|
|
|
let clients = [];
|
2017-11-08 11:56:04 +00:00
|
|
|
|
|
|
|
const wrapper = function() {
|
2017-11-08 20:40:59 +00:00
|
|
|
for(let srv in cfg.client) {
|
|
|
|
switch(cfg.client[srv].type) {
|
|
|
|
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",
|
2017-11-08 21:52:20 +00:00
|
|
|
client: new tglib(cfg.client[srv])
|
2017-11-08 20:40:59 +00:00
|
|
|
});
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
2017-11-08 11:56:04 +00:00
|
|
|
|
2017-11-08 19:30:21 +00:00
|
|
|
clients.forEach(client => {
|
|
|
|
client.client.on("message", e => {
|
|
|
|
this.emit('message', e);
|
|
|
|
});
|
|
|
|
});
|
2017-11-08 11:56:04 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
util.inherits(wrapper, EventEmitter);
|
2017-11-08 21:29:43 +00:00
|
|
|
export default { wrapper, clients };
|