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(() => { read().then(() => {
let bot = new wrapper(); let bot = new wrapper();
bot.on('message', e => { bot.on('message', e => {
//console.log( e ); console.log( e );
e.reply( e.message );
}); });
}); });

View File

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

View File

@ -8,9 +8,13 @@ const util = require('util');
//const ytdl = util.promisify(require('youtube-dl').getInfo); //const ytdl = util.promisify(require('youtube-dl').getInfo);
var EventEmitter = require('events').EventEmitter; var EventEmitter = require('events').EventEmitter;
let clients = [];
const wrapper = function() { const wrapper = function() {
let irc = new irclib({ clients.push({
name: "n0xy",
type: "irc",
client: new irclib({
network: "n0xy", network: "n0xy",
host: "31.172.14.83", host: "31.172.14.83",
port: 6669, //6669, port: 6669, //6669,
@ -23,28 +27,27 @@ const wrapper = function() {
channels: [ channels: [
"#kbot-dev" "#kbot-dev"
] ]
})
}); });
//const tg = new (require('node-telegram-bot-api'))('381368731:AAFalG-LknIbtBDuOvRXcxHUEK9Jg_o1UCw', { polling: true }); clients.push({
name: "tg",
irc.on("message", (msg) => { type: "tg",
this.emit('message', msg); client: new (require('node-telegram-bot-api'))('381368731:AAFalG-LknIbtBDuOvRXcxHUEK9Jg_o1UCw', { polling: true })
//if( msg.event[1] === "privmsg" ) {
// let e = reply( msg );
// console.log( `IRC: (${e.time}) ${e.network} -> ${e.channel} -> ${e.user.nick}: ${e.message}` );
//}
}); });
/*tg.on('message', msg => { clients.forEach(client => {
this.emit('message', msg); client.client.on("message", e => {
//let e = replytg(tg, msg); if(client.type === "tg")
//console.log( `TG: (${e.time}) ${e.channel} -> ${e.user.nick}: ${e.message}` ); e = replytg(client.client, e);
});*/ this.emit('message', e);
});
});
}; };
const replytg = (bot, tmp) => { const replytg = (bot, tmp) => { // muss noch hier raus
return { return {
type: "tg",
channel: tmp.chat.title, channel: tmp.chat.title,
channelid: tmp.chat.id, channelid: tmp.chat.id,
user: { user: {
@ -54,13 +57,13 @@ const replytg = (bot, tmp) => {
message: tmp.text, message: tmp.text,
time: tmp.date, time: tmp.date,
reply: function(msg) { reply: function(msg) {
bot.sendMessage(this.channelid, msg); bot.sendMessage(tmp.chat.id, msg);
}.bind(this), },
replyAction: function(msg) { replyAction: function(msg) {
bot.sendMessage(this.channelid, msg); bot.sendMessage(tmp.chat.id, msg);
}, },
replyNotice: function(msg) { replyNotice: function(msg) {
bot.sendMessage(this.channelid, msg); bot.sendMessage(tmp.chat.id, msg);
} }
}; };
}; };