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,43 +8,46 @@ 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({
network: "n0xy", name: "n0xy",
host: "31.172.14.83", type: "irc",
port: 6669, //6669, client: new irclib({
ssl: true, network: "n0xy",
selfSigned: true, host: "31.172.14.83",
nickname: "kbotv3", port: 6669, //6669,
username: "kbotv2/n0xy", ssl: true,
password: "blah", selfSigned: true,
realname: "kbotv3", nickname: "kbotv3",
channels: [ username: "kbotv2/n0xy",
"#kbot-dev" 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}` );
//}
}); });
/*tg.on('message', msg => { clients.push({
this.emit('message', msg); name: "tg",
//let e = replytg(tg, msg); type: "tg",
//console.log( `TG: (${e.time}) ${e.channel} -> ${e.user.nick}: ${e.message}` ); 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 { 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);
} }
}; };
}; };