fick ircparser.. fix'd
This commit is contained in:
parent
9553ce1701
commit
08eb84842a
71
package-lock.json
generated
71
package-lock.json
generated
|
@ -1424,6 +1424,21 @@
|
|||
"loose-envify": "1.3.1"
|
||||
}
|
||||
},
|
||||
"irc-message": {
|
||||
"version": "3.0.2",
|
||||
"resolved": "https://registry.npmjs.org/irc-message/-/irc-message-3.0.2.tgz",
|
||||
"integrity": "sha1-U3eyNcVMTjzlZTbJ1AxSkXmN+d8=",
|
||||
"requires": {
|
||||
"irc-prefix-parser": "1.0.1",
|
||||
"iso8601-convert": "1.0.0",
|
||||
"through2": "0.6.5"
|
||||
}
|
||||
},
|
||||
"irc-prefix-parser": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/irc-prefix-parser/-/irc-prefix-parser-1.0.1.tgz",
|
||||
"integrity": "sha1-Vs5g148w6bgLD88SP075+PLmLgs="
|
||||
},
|
||||
"is-binary-path": {
|
||||
"version": "1.0.1",
|
||||
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-1.0.1.tgz",
|
||||
|
@ -1545,6 +1560,11 @@
|
|||
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
|
||||
},
|
||||
"iso8601-convert": {
|
||||
"version": "1.0.0",
|
||||
"resolved": "https://registry.npmjs.org/iso8601-convert/-/iso8601-convert-1.0.0.tgz",
|
||||
"integrity": "sha1-inCYB8mOYEZtnnlNgRJlyQpBVjU="
|
||||
},
|
||||
"isobject": {
|
||||
"version": "2.1.0",
|
||||
"resolved": "https://registry.npmjs.org/isobject/-/isobject-2.1.0.tgz",
|
||||
|
@ -2249,12 +2269,12 @@
|
|||
"dev": true
|
||||
},
|
||||
"through2": {
|
||||
"version": "0.5.1",
|
||||
"resolved": "https://registry.npmjs.org/through2/-/through2-0.5.1.tgz",
|
||||
"integrity": "sha1-390BLrnHAOIyP9M084rGIqs3Lac=",
|
||||
"version": "0.6.5",
|
||||
"resolved": "https://registry.npmjs.org/through2/-/through2-0.6.5.tgz",
|
||||
"integrity": "sha1-QaucZ7KdVyCQcUEOHXp6lozTrUg=",
|
||||
"requires": {
|
||||
"readable-stream": "1.0.34",
|
||||
"xtend": "3.0.0"
|
||||
"xtend": "4.0.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"isarray": {
|
||||
|
@ -2287,6 +2307,43 @@
|
|||
"requires": {
|
||||
"inherits": "2.0.3",
|
||||
"through2": "0.5.1"
|
||||
},
|
||||
"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": {
|
||||
"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"
|
||||
}
|
||||
},
|
||||
"xtend": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-3.0.0.tgz",
|
||||
"integrity": "sha1-XM50B7r2Qsunvs2laBEcST9ZZlo="
|
||||
}
|
||||
}
|
||||
},
|
||||
"to-fast-properties": {
|
||||
|
@ -2367,9 +2424,9 @@
|
|||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
||||
},
|
||||
"xtend": {
|
||||
"version": "3.0.0",
|
||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-3.0.0.tgz",
|
||||
"integrity": "sha1-XM50B7r2Qsunvs2laBEcST9ZZlo="
|
||||
"version": "4.0.1",
|
||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",
|
||||
"integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68="
|
||||
},
|
||||
"youtube-dl": {
|
||||
"version": "1.12.2",
|
||||
|
|
|
@ -14,7 +14,6 @@
|
|||
"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"
|
||||
},
|
||||
|
|
|
@ -1,8 +1,7 @@
|
|||
const net = require("net")
|
||||
, tls = require("tls")
|
||||
, EventEmitter = require("events").EventEmitter
|
||||
, util = require("util")
|
||||
, parser = require("parse-irc");
|
||||
, util = require("util");
|
||||
|
||||
class irc {
|
||||
constructor(options) {
|
||||
|
@ -20,7 +19,6 @@ 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: {},
|
||||
|
@ -39,16 +37,62 @@ class irc {
|
|||
this.send("CAP LS");
|
||||
//this.send("CAP REQ sasl");
|
||||
}
|
||||
}).pipe(this.stream);
|
||||
});
|
||||
this.socket.setEncoding("utf-8");
|
||||
this.stream.on("data", msg => {
|
||||
//msg = this.parse(msg);
|
||||
this.socket.on("data", msg => {
|
||||
msg = msg.replace("\r", "").split(/\n/);
|
||||
for(let tmp in msg)
|
||||
if(msg[tmp].length > 0)
|
||||
this.cmd(this.parse(msg[tmp]));
|
||||
});
|
||||
}
|
||||
send() {
|
||||
let args = "";
|
||||
for (let i = 0; i < arguments.length; i++) {
|
||||
this.socket.write(arguments[i]);
|
||||
args += arguments[i];
|
||||
}
|
||||
console.log(this.options.network, "send", args);
|
||||
this.socket.write("\n");
|
||||
}
|
||||
parse(data) {
|
||||
//let raw = data
|
||||
let i = 0
|
||||
, prefix = "";
|
||||
if (data.charAt(0) === ":") {
|
||||
i = data.indexOf(" ");
|
||||
prefix = data.slice(1, i);
|
||||
data = data.slice(i + 1);
|
||||
}
|
||||
i = data.indexOf(" ");
|
||||
if (i === -1)
|
||||
i = data.length;
|
||||
var command = data.slice(0, i);
|
||||
data = data.slice(i + 1);
|
||||
var params = [];
|
||||
while (data && data.charAt(0) !== ":") {
|
||||
i = data.indexOf(" ");
|
||||
if (i === -1)
|
||||
i = data.length;
|
||||
params.push(data.slice(0, i));
|
||||
data = data.slice(i + 1);
|
||||
}
|
||||
if (data) {
|
||||
data = data.replace(/\r?\n|\r/g, "");
|
||||
params.push(data.slice(1));
|
||||
}
|
||||
return {
|
||||
//raw: raw,
|
||||
prefix: prefix,
|
||||
command: command,
|
||||
params: params
|
||||
};
|
||||
}
|
||||
cmd(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
|
||||
|
@ -101,14 +145,12 @@ class irc {
|
|||
if (tmpuser.channels)
|
||||
tmpchan = tmpuser.channels;
|
||||
}
|
||||
|
||||
chans = msg.params[2].trim().split(" ");
|
||||
for (let chan in chans) {
|
||||
chan = chans[chan].split("#");
|
||||
tmpchan.set(`#${chan[1]}`, chan[0]);
|
||||
}
|
||||
tmpuser.channels = tmpchan;
|
||||
|
||||
this.server.user.set(msg.params[1], tmpuser);
|
||||
break;
|
||||
case "330": // Quarknet
|
||||
|
@ -196,55 +238,11 @@ class irc {
|
|||
break;
|
||||
case "900":
|
||||
this.send("CAP END");
|
||||
this.join(this.options.channels); // tmp
|
||||
break;
|
||||
default:
|
||||
|
||||
break;
|
||||
}
|
||||
});
|
||||
}
|
||||
send() {
|
||||
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) {
|
||||
let raw = data;
|
||||
let i = 0;
|
||||
let prefix = "";
|
||||
if (data.charAt(0) === ":") {
|
||||
i = data.indexOf(" ");
|
||||
prefix = data.slice(1, i);
|
||||
data = data.slice(i + 1);
|
||||
}
|
||||
i = data.indexOf(" ");
|
||||
if (i === -1)
|
||||
i = data.length;
|
||||
var command = data.slice(0, i);
|
||||
data = data.slice(i + 1);
|
||||
var params = [];
|
||||
while (data && data.charAt(0) !== ":") {
|
||||
i = data.indexOf(" ");
|
||||
if (i === -1)
|
||||
i = data.length;
|
||||
params.push(data.slice(0, i));
|
||||
data = data.slice(i + 1);
|
||||
}
|
||||
if (data) {
|
||||
data = data.replace(/\r?\n|\r/g, "");
|
||||
params.push(data.slice(1));
|
||||
}
|
||||
return {
|
||||
raw: raw,
|
||||
prefix: prefix,
|
||||
command: command,
|
||||
params: params
|
||||
};
|
||||
}
|
||||
reply(tmp) {
|
||||
return {
|
||||
|
@ -283,14 +281,9 @@ class irc {
|
|||
}
|
||||
whois(user, force = false) {
|
||||
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");
|
||||
if(this.server.user.hasi(user) && !force)
|
||||
if(this.server.user.geti(user).cached >= ~~(Date.now() / 1000) - this._recachetime)
|
||||
return;
|
||||
}
|
||||
}
|
||||
//console.log("get whois for", user);
|
||||
this.send(`WHOIS ${user}`);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user