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" "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": { "path-is-absolute": {
"version": "1.0.1", "version": "1.0.1",
"resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz", "resolved": "https://registry.npmjs.org/path-is-absolute/-/path-is-absolute-1.0.1.tgz",
@ -2239,6 +2248,47 @@
"integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=", "integrity": "sha1-U10EXOa2Nj+kARcIRimZXp3zJMc=",
"dev": true "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": { "to-fast-properties": {
"version": "1.0.3", "version": "1.0.3",
"resolved": "https://registry.npmjs.org/to-fast-properties/-/to-fast-properties-1.0.3.tgz", "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", "resolved": "https://registry.npmjs.org/wrappy/-/wrappy-1.0.2.tgz",
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8=" "integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
}, },
"xtend": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/xtend/-/xtend-3.0.0.tgz",
"integrity": "sha1-XM50B7r2Qsunvs2laBEcST9ZZlo="
},
"youtube-dl": { "youtube-dl": {
"version": "1.12.2", "version": "1.12.2",
"resolved": "https://registry.npmjs.org/youtube-dl/-/youtube-dl-1.12.2.tgz", "resolved": "https://registry.npmjs.org/youtube-dl/-/youtube-dl-1.12.2.tgz",

View File

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

View File

@ -9,21 +9,23 @@ const clients = [];
const wrapper = function () { const wrapper = function () {
for (let srv in cfg.client) { for (let srv in cfg.client) {
switch (cfg.client[srv].type) { if(cfg.client[srv].enabled) {
case "irc": switch (cfg.client[srv].type) {
clients.push({ case "irc":
name: cfg.client[srv].network, clients.push({
type: "irc", name: cfg.client[srv].network,
client: new irclib(cfg.client[srv]) type: "irc",
}); client: new irclib(cfg.client[srv])
break; });
case "tg": break;
clients.push({ case "tg":
name: "tg", clients.push({
type: "tg", name: "tg",
client: new tglib(cfg.client[srv]) type: "tg",
}); client: new tglib(cfg.client[srv])
break; });
break;
}
} }
} }