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"
|
"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": {
|
"is-binary-path": {
|
||||||
"version": "1.0.1",
|
"version": "1.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/is-binary-path/-/is-binary-path-1.0.1.tgz",
|
"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",
|
"resolved": "https://registry.npmjs.org/isarray/-/isarray-1.0.0.tgz",
|
||||||
"integrity": "sha1-u5NdSFgsuhaMBoNJV6VKPgcSTxE="
|
"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": {
|
"isobject": {
|
||||||
"version": "2.1.0",
|
"version": "2.1.0",
|
||||||
"resolved": "https://registry.npmjs.org/isobject/-/isobject-2.1.0.tgz",
|
"resolved": "https://registry.npmjs.org/isobject/-/isobject-2.1.0.tgz",
|
||||||
|
@ -2249,12 +2269,12 @@
|
||||||
"dev": true
|
"dev": true
|
||||||
},
|
},
|
||||||
"through2": {
|
"through2": {
|
||||||
"version": "0.5.1",
|
"version": "0.6.5",
|
||||||
"resolved": "https://registry.npmjs.org/through2/-/through2-0.5.1.tgz",
|
"resolved": "https://registry.npmjs.org/through2/-/through2-0.6.5.tgz",
|
||||||
"integrity": "sha1-390BLrnHAOIyP9M084rGIqs3Lac=",
|
"integrity": "sha1-QaucZ7KdVyCQcUEOHXp6lozTrUg=",
|
||||||
"requires": {
|
"requires": {
|
||||||
"readable-stream": "1.0.34",
|
"readable-stream": "1.0.34",
|
||||||
"xtend": "3.0.0"
|
"xtend": "4.0.1"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"isarray": {
|
"isarray": {
|
||||||
|
@ -2287,6 +2307,43 @@
|
||||||
"requires": {
|
"requires": {
|
||||||
"inherits": "2.0.3",
|
"inherits": "2.0.3",
|
||||||
"through2": "0.5.1"
|
"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": {
|
"to-fast-properties": {
|
||||||
|
@ -2367,9 +2424,9 @@
|
||||||
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
"integrity": "sha1-tSQ9jz7BqjXxNkYFvA0QNuMKtp8="
|
||||||
},
|
},
|
||||||
"xtend": {
|
"xtend": {
|
||||||
"version": "3.0.0",
|
"version": "4.0.1",
|
||||||
"resolved": "https://registry.npmjs.org/xtend/-/xtend-3.0.0.tgz",
|
"resolved": "https://registry.npmjs.org/xtend/-/xtend-4.0.1.tgz",
|
||||||
"integrity": "sha1-XM50B7r2Qsunvs2laBEcST9ZZlo="
|
"integrity": "sha1-pcbVMr5lbiPbgg77lDofBJmNY68="
|
||||||
},
|
},
|
||||||
"youtube-dl": {
|
"youtube-dl": {
|
||||||
"version": "1.12.2",
|
"version": "1.12.2",
|
||||||
|
|
|
@ -14,7 +14,6 @@
|
||||||
"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"
|
||||||
},
|
},
|
||||||
|
|
|
@ -1,8 +1,7 @@
|
||||||
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) {
|
||||||
|
@ -20,7 +19,6 @@ 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: {},
|
sasl: {},
|
||||||
|
@ -39,16 +37,62 @@ class irc {
|
||||||
this.send("CAP LS");
|
this.send("CAP LS");
|
||||||
//this.send("CAP REQ sasl");
|
//this.send("CAP REQ sasl");
|
||||||
}
|
}
|
||||||
}).pipe(this.stream);
|
});
|
||||||
this.socket.setEncoding("utf-8");
|
this.socket.setEncoding("utf-8");
|
||||||
this.stream.on("data", msg => {
|
this.socket.on("data", msg => {
|
||||||
//msg = this.parse(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 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
|
||||||
|
@ -101,14 +145,12 @@ class irc {
|
||||||
if (tmpuser.channels)
|
if (tmpuser.channels)
|
||||||
tmpchan = tmpuser.channels;
|
tmpchan = tmpuser.channels;
|
||||||
}
|
}
|
||||||
|
|
||||||
chans = msg.params[2].trim().split(" ");
|
chans = msg.params[2].trim().split(" ");
|
||||||
for (let chan in chans) {
|
for (let chan in chans) {
|
||||||
chan = chans[chan].split("#");
|
chan = chans[chan].split("#");
|
||||||
tmpchan.set(`#${chan[1]}`, chan[0]);
|
tmpchan.set(`#${chan[1]}`, chan[0]);
|
||||||
}
|
}
|
||||||
tmpuser.channels = tmpchan;
|
tmpuser.channels = tmpchan;
|
||||||
|
|
||||||
this.server.user.set(msg.params[1], tmpuser);
|
this.server.user.set(msg.params[1], tmpuser);
|
||||||
break;
|
break;
|
||||||
case "330": // Quarknet
|
case "330": // Quarknet
|
||||||
|
@ -196,55 +238,11 @@ class irc {
|
||||||
break;
|
break;
|
||||||
case "900":
|
case "900":
|
||||||
this.send("CAP END");
|
this.send("CAP END");
|
||||||
this.join(this.options.channels); // tmp
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
||||||
break;
|
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) {
|
reply(tmp) {
|
||||||
return {
|
return {
|
||||||
|
@ -283,14 +281,9 @@ class irc {
|
||||||
}
|
}
|
||||||
whois(user, force = false) {
|
whois(user, force = false) {
|
||||||
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(user, "already cached");
|
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
}
|
|
||||||
//console.log("get whois for", user);
|
|
||||||
this.send(`WHOIS ${user}`);
|
this.send(`WHOIS ${user}`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user