This commit is contained in:
Flummi 2017-11-08 20:30:21 +01:00
parent f5c6a14def
commit a76563a7bc
3 changed files with 49 additions and 46 deletions

View File

@ -4,7 +4,6 @@ import { wrapper } from './inc/wrapper.js';
read().then(() => {
let bot = new wrapper();
bot.on('message', e => {
//console.log( e );
e.reply( e.message );
console.log( e );
});
});

View File

@ -3,7 +3,7 @@ var tls = require("tls");
var EventEmitter = require("events").EventEmitter;
var util = require("util");
function Client(options) {
function irc(options) {
EventEmitter.call(this);
this.options = options || {};
this.options.channels = this.options.channels || [];
@ -46,13 +46,13 @@ function Client(options) {
});
}
Client.prototype.send = function send() {
irc.prototype.send = function send() {
for(let i = 0; i < arguments.length; i++)
this.socket.write(arguments[i]);
this.socket.write('\n');
}
Client.prototype.parse = function parse(data) {
irc.prototype.parse = function parse(data) {
var raw = data;
if(data.charAt(0) === ':') {
var i = data.indexOf(' ');
@ -79,7 +79,7 @@ Client.prototype.parse = function parse(data) {
};
}
Client.prototype.reply = function(tmp) { // prefix: 'Flummi!~bark@bark',
irc.prototype.reply = function(tmp) { // prefix: 'Flummi!~bark@bark',
let usertmp = tmp.prefix.split("!");
let hosttmp = usertmp[1].split("@");
let user = {
@ -87,8 +87,8 @@ Client.prototype.reply = function(tmp) { // prefix: 'Flummi!~bark@bark',
username: hosttmp[0],
hostname: hosttmp[1]
};
console.log(tmp);
return {
type: "irc",
network: this.network,
channel: tmp.params[0],
user: user,
@ -97,14 +97,15 @@ Client.prototype.reply = function(tmp) { // prefix: 'Flummi!~bark@bark',
reply: msg => {
this.send(`PRIVMSG ${tmp.params[0]} ${msg}`);
},
/*replyAction: msg => {
rpc.emit('call', this.network, 'privmsg', [this.channel, '\u0001' + 'ACTION ' + msg + '\u0001']);
replyAction: msg => {
this.send(`PRIVMSG ${tmp.params[0]} \u0001ACTION ${msg}\u0001`);
},
replyNotice: msg => {
rpc.emit('call', this.network, 'notice', [this.channel, msg]);
}*/
this.send(`NOTICE ${tmp.params[0]} ${msg}`);
//rpc.emit('call', this.network, 'notice', [this.channel, msg]);
}
};
};
module.exports = Client;
util.inherits(Client, EventEmitter);
module.exports = irc;
util.inherits(irc, EventEmitter);

View File

@ -8,43 +8,46 @@ const util = require('util');
//const ytdl = util.promisify(require('youtube-dl').getInfo);
var EventEmitter = require('events').EventEmitter;
let clients = [];
const wrapper = function() {
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 });
irc.on("message", (msg) => {
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}` );
//}
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"
]
})
});
/*tg.on('message', msg => {
this.emit('message', msg);
//let e = replytg(tg, msg);
//console.log( `TG: (${e.time}) ${e.channel} -> ${e.user.nick}: ${e.message}` );
});*/
clients.push({
name: "tg",
type: "tg",
client: new (require('node-telegram-bot-api'))('381368731:AAFalG-LknIbtBDuOvRXcxHUEK9Jg_o1UCw', { polling: true })
});
clients.forEach(client => {
client.client.on("message", e => {
if(client.type === "tg")
e = replytg(client.client, e);
this.emit('message', e);
});
});
};
const replytg = (bot, tmp) => {
const replytg = (bot, tmp) => { // muss noch hier raus
return {
type: "tg",
channel: tmp.chat.title,
channelid: tmp.chat.id,
user: {
@ -54,13 +57,13 @@ const replytg = (bot, tmp) => {
message: tmp.text,
time: tmp.date,
reply: function(msg) {
bot.sendMessage(this.channelid, msg);
}.bind(this),
bot.sendMessage(tmp.chat.id, msg);
},
replyAction: function(msg) {
bot.sendMessage(this.channelid, msg);
bot.sendMessage(tmp.chat.id, msg);
},
replyNotice: function(msg) {
bot.sendMessage(this.channelid, msg);
bot.sendMessage(tmp.chat.id, msg);
}
};
};