This commit is contained in:
Flummi 2017-11-19 10:19:17 +01:00
parent 93407fba43
commit 9553ce1701
5 changed files with 135 additions and 28 deletions

55
package-lock.json generated
View File

@ -1839,6 +1839,15 @@
"is-glob": "2.0.1"
}
},
"parse-irc": {
"version": "0.2.4",
"resolved": "https://registry.npmjs.org/parse-irc/-/parse-irc-0.2.4.tgz",
"integrity": "sha1-BcVBeVmA2724Z9dGRhfF0FGaXvk=",
"requires": {
"inherits": "2.0.3",
"through2-objectify": "0.1.1"
}
},
"path-is-absolute": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
@ -2239,6 +2248,47 @@
"integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=",
"dev": true
},
"through2": {
"version": "0.5.1",
"resolved": "https://registry.npmjs.org/through2/-/through2-0.5.1.tgz",
"integrity": "sha1-390BLrnHAOIyP9M084rGIqs3Lac=",
"requires": {
"readable-stream": "1.0.34",
"xtend": "3.0.0"
},
"dependencies": {
"isarray": {
"version": "0.0.1",
"resolved": "https://registry.npmjs.org/isarray/-/isarray-0.0.1.tgz",
"integrity": "sha1-ihis/Kmo9Bd+Cav8YDiTmwXR7t8="
},
"readable-stream": {
"version": "1.0.34",
"resolved": "https://registry.npmjs.org/readable-stream/-/readable-stream-1.0.34.tgz",
"integrity": "sha1-Elgg40vIQtLyqq+v5MKRbuMsFXw=",
"requires": {
"core-util-is": "1.0.2",
"inherits": "2.0.3",
"isarray": "0.0.1",
"string_decoder": "0.10.31"
}
},
"string_decoder": {
"version": "0.10.31",
"resolved": "https://registry.npmjs.org/string_decoder/-/string_decoder-0.10.31.tgz",
"integrity": "sha1-YuIDvEF2bGwoyfyEMB2rHFMQ+pQ="
}
}
},
"through2-objectify": {
"version": "0.1.1",
"resolved": "https://registry.npmjs.org/through2-objectify/-/through2-objectify-0.1.1.tgz",
"integrity": "sha1-oHQaR4vLeRY3b5eSQRgaGwZEvBk=",
"requires": {
"inherits": "2.0.3",
"through2": "0.5.1"
}
},
"to-fast-properties": {
"version": "1.0.3",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz",
@ -2316,6 +2366,11 @@
"resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
},
"xtend": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-3.0.0.tgz",
"integrity": "sha1-XM50B7r2Qsunvs2laBEcST9ZZlo="
},
"youtube-dl": {
"version": "1.12.2",
"resolved": "https://registry.npmjs.org/youtube-dl/-/youtube-dl-1.12.2.tgz",

View File

@ -14,6 +14,7 @@
"dependencies": {
"node-telegram-bot-api": "^0.29.0",
"nodejs-mysql": "^0.1.3",
"parse-irc": "^0.2.4",
"safe-eval": "^0.3.0",
"youtube-dl": "^1.12.2"
},

16
partjoin.txt Normal file
View File

@ -0,0 +1,16 @@
part { raw: ':Flummi!~bark@bark.bark.bark PART #f0ck :test\r\n',
prefix: 'Flummi!~bark@bark.bark.bark',
command: 'PART',
params: [ '#f0ck', 'test' ] }
join { raw: ':Flummi!~bark@bark.bark.bark JOIN :#f0ck\r\n',
prefix: 'Flummi!~bark@bark.bark.bark',
command: 'JOIN',
params: [ '#f0ck' ] }
nick { raw: ':Flummi!~bark@bark NICK flummi\r\n',
prefix: 'Flummi!~bark@bark',
command: 'NICK',
params: [ 'flummi\r\n' ] }

View File

@ -1,7 +1,8 @@
const net = require("net")
, tls = require("tls")
, EventEmitter = require("events").EventEmitter
,util = require("util");
, util = require("util")
, parser = require("parse-irc");
class irc {
constructor(options) {
@ -19,8 +20,10 @@ class irc {
this.realname = this.options.realname || "test";
this.channels = this.options.channels || [];
this._recachetime = 60 * 5; // 10 minutes
this.stream = parser();
this.server = {
motd: "",
sasl: {},
me: {},
channel: [],
user: new Map()
@ -32,14 +35,20 @@ class irc {
}, () => {
this.send(`NICK ${this.nickname}`);
this.send(`USER ${this.username} 0 * : ${this.realname}`);
});
if(this.options.sasl) {
this.send("CAP LS");
//this.send("CAP REQ sasl");
}
}).pipe(this.stream);
this.socket.setEncoding("utf-8");
this.socket.on("data", msg => {
msg = this.parse(msg);
this.stream.on("data", msg => {
//msg = this.parse(msg);
let tmpuser = {};
let tmpchan = {};
let chans = [];
let prefix = "";
if(msg.command != "372")
console.log(msg);
switch (msg.command) { // auslagern!
// WHOIS BEGIN
case "307": // Rizon Account
@ -127,7 +136,7 @@ class irc {
this.whois(msg.params[5]);
break;
case "315": // who_end
console.log(this.server.channel);
//console.log(this.server.channel);
break;
case "372": // motd
this.server.motd += `${msg.params[1]}\n`;
@ -140,18 +149,16 @@ class irc {
this.emit("data", ["motd", this.server.motd]);
break;
case "464": // Password required
if (this.options.password.length > 0)
if (this.options.password.length > 0 && !this.options.sasl)
this.send(`PASS ${this.options.password}`); // pwd
break;
case "PING":
this.send(`PONG ${msg.params.join``}`);
break;
case "JOIN":
console.log("join", msg);
this.send(`WHO ${msg.params[0]}`);
break;
case "PART":
console.log("part", msg);
delete this.server.user[msg.params[0]];
//this.whois(msg.params[0], true); // force whois
break;
@ -170,15 +177,40 @@ class irc {
this.server.user.deli(prefix.nick);
this.whois(msg.params[0], true); // force
break;
/* CAPKACKE */
case "CAP":
console.log("CAP", msg);
switch(msg.params[1]) {
case "LS":
this.server.sasl.ls = msg.params[2].split(" ");
this.send(`CAP REQ :${this.server.sasl.ls.join(" ")}`);
break;
case "ACK": // success
this.send("AUTHENTICATE PLAIN");
break;
}
break;
case "AUTHENTICATE":
if(msg.params[0].match(/\+/))
this.send(`AUTHENTICATE ${new Buffer(this.username+"\u0000"+this.username+"\u0000"+this.options.password).toString("base64")}`);
break;
case "900":
this.send("CAP END");
this.join(this.options.channels); // tmp
break;
default:
console.log(msg);
break;
}
});
}
send() {
for (let i = 0; i < arguments.length; i++)
let args = "";
for (let i = 0; i < arguments.length; i++) {
this.socket.write(arguments[i]);
args += arguments[i];
}
console.log(this.options.network, "sending", args);
this.socket.write("\n");
}
parse(data) {
@ -235,6 +267,7 @@ class irc {
// act chan
_chan: this.server.channel[tmp.params[0]],
_user: this.server.user,
sasl: this.server.sasl,
// commands
join: chan => this.join(chan),
part: (chan, msg) => this.part(chan, msg),
@ -252,12 +285,12 @@ class irc {
user = user.toLowerCase();
if(this.server.user.hasi(user) && !force) {
if(this.server.user.geti(user).cached >= ~~(Date.now() / 1000) - this._recachetime) {
console.log(this.server.user.geti(user).cached, ~~(Date.now() / 1000) - this._recachetime);
console.log(user, "already cached");
//console.log(this.server.user.geti(user).cached, ~~(Date.now() / 1000) - this._recachetime);
//console.log(user, "already cached");
return;
}
}
console.log("get whois for", user);
//console.log("get whois for", user);
this.send(`WHOIS ${user}`);
}
}

View File

@ -9,6 +9,7 @@ const clients = [];
const wrapper = function () {
for (let srv in cfg.client) {
if(cfg.client[srv].enabled) {
switch (cfg.client[srv].type) {
case "irc":
clients.push({
@ -26,6 +27,7 @@ const wrapper = function () {
break;
}
}
}
clients.forEach(client => {
client.client.on("data", e => {