Uwev2/src/inc/wrapper.js

77 lines
1.9 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;
const wrapper = function() {
2017-11-08 18:43:08 +00:00
let irc = 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"
]
});
//const tg = new (require('node-telegram-bot-api'))('381368731:AAFalG-LknIbtBDuOvRXcxHUEK9Jg_o1UCw', { polling: true });
2017-11-08 11:56:04 +00:00
2017-11-08 18:43:08 +00:00
irc.on("message", (msg) => {
2017-11-08 11:56:04 +00:00
this.emit('message', msg);
//if( msg.event[1] === "privmsg" ) {
// let e = reply( msg );
// console.log( `IRC: (${e.time}) ${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}` );
//}
});
2017-11-08 18:43:08 +00:00
/*tg.on('message', msg => {
2017-11-08 11:56:04 +00:00
this.emit('message', msg);
//let e = replytg(tg, msg);
//console.log( `TG: (${e.time}) ${e.channel} -> ${e.user.nick}: ${e.message}` );
2017-11-08 18:43:08 +00:00
});*/
2017-11-08 11:56:04 +00:00
};
const replytg = (bot, tmp) => {
return {
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) {
bot.sendMessage(this.channelid, msg);
}.bind(this),
replyAction: function(msg) {
bot.sendMessage(this.channelid, msg);
},
replyNotice: function(msg) {
bot.sendMessage(this.channelid, msg);
}
};
};
const loadIRC = () => {
for(let srv in cfg.irc) {
rpc.emit('createClient', srv, cfg.irc[srv]);
console.log('Loading server', srv);
}
console.log('All servers have been loaded successfully');
};
util.inherits(wrapper, EventEmitter);
export default { wrapper };