Uwev2/src/inc/wrapper.js

72 lines
1.7 KiB
JavaScript
Raw Normal View History

2017-11-08 11:56:04 +00:00
import { cfg, read } from './cfg.js';
import { loadEvents } from './lib.js';
2017-11-08 18:43:08 +00:00
let irclib = require('./irc/irc.js');
//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 19:30:21 +00:00
clients.push({
name: "n0xy",
type: "irc",
client: new irclib({
network: "n0xy",
host: "31.172.14.83",
port: 6669, //6669,
ssl: true,
selfSigned: true,
nickname: "kbotv3",
username: "kbotv2/n0xy",
password: "blah",
realname: "kbotv3",
channels: [
"#kbot-dev"
]
})
2017-11-08 18:43:08 +00:00
});
2017-11-08 11:56:04 +00:00
2017-11-08 19:30:21 +00:00
clients.push({
name: "tg",
type: "tg",
client: new (require('node-telegram-bot-api'))('381368731:AAFalG-LknIbtBDuOvRXcxHUEK9Jg_o1UCw', { polling: true })
2017-11-08 11:56:04 +00:00
});
2017-11-08 19:30:21 +00:00
clients.forEach(client => {
client.client.on("message", e => {
if(client.type === "tg")
e = replytg(client.client, e);
this.emit('message', e);
});
});
2017-11-08 11:56:04 +00:00
};
2017-11-08 19:30:21 +00:00
const replytg = (bot, tmp) => { // muss noch hier raus
2017-11-08 11:56:04 +00:00
return {
2017-11-08 19:30:21 +00:00
type: "tg",
2017-11-08 11:56:04 +00:00
channel: tmp.chat.title,
channelid: tmp.chat.id,
user: {
nick: tmp.from.first_name,
username: tmp.from.username
},
message: tmp.text,
time: tmp.date,
reply: function(msg) {
2017-11-08 19:30:21 +00:00
bot.sendMessage(tmp.chat.id, msg);
},
2017-11-08 11:56:04 +00:00
replyAction: function(msg) {
2017-11-08 19:30:21 +00:00
bot.sendMessage(tmp.chat.id, msg);
2017-11-08 11:56:04 +00:00
},
replyNotice: function(msg) {
2017-11-08 19:30:21 +00:00
bot.sendMessage(tmp.chat.id, msg);
2017-11-08 11:56:04 +00:00
}
};
};
util.inherits(wrapper, EventEmitter);
export default { wrapper };