diff --git a/package.json b/package.json index c3a9e97..cdbddfc 100644 --- a/package.json +++ b/package.json @@ -6,7 +6,8 @@ "scripts": { "build": "./node_modules/.bin/babel src --presets=env --plugins=add-module-exports --out-dir dist", "debug": "node --inspect=9229 dist/bot.js", - "start": "npm run build && node dist/bot.js" + "start": "npm run build && node dist/bot.js", + "inspect": "npm run build && node --inspect=9229 dist/bot.js" }, "author": "Flummi & jkhsjdhjs", "license": "WTFPL", diff --git a/src/inc/clients/irc.js b/src/inc/clients/irc.js index df11ef7..2e76ebc 100644 --- a/src/inc/clients/irc.js +++ b/src/inc/clients/irc.js @@ -1,7 +1,7 @@ -var net = require("net"); -var tls = require("tls"); -var EventEmitter = require("events").EventEmitter; -var util = require("util"); +const net = require("net") + , tls = require("tls") + , EventEmitter = require("events").EventEmitter + ,util = require("util"); class irc { constructor(options) { @@ -39,37 +39,38 @@ class irc { let tmpuser = {}; let tmpchan = {}; let chans = []; + let prefix = ""; switch (msg.command) { // auslagern! // WHOIS BEGIN case "307": // Rizon Account tmpuser = {}; - if(this.server.user.has( msg.params[1].toLowerCase() )) - tmpuser = this.server.user.get( msg.params[1].toLowerCase() ); - tmpuser.account = msg.params[1].toLowerCase(); + if(this.server.user.hasi( msg.params[1] )) + tmpuser = this.server.user.geti( msg.params[1] ); + tmpuser.account = msg.params[1]; tmpuser.registered = true; - this.server.user.set( msg.params[1].toLowerCase(), tmpuser ); + this.server.user.set( msg.params[1], tmpuser ); break; case "311": // first tmpuser = {}; - if (this.server.user.has( msg.params[1].toLowerCase() )) - tmpuser = this.server.user.get( msg.params[1].toLowerCase() ); - tmpuser.nickname = msg.params[1].toLowerCase(); + if (this.server.user.hasi( msg.params[1] )) + tmpuser = this.server.user.geti( msg.params[1] ); + tmpuser.nickname = msg.params[1]; tmpuser.username = msg.params[2]; tmpuser.hostname = msg.params[3]; tmpuser.realname = msg.params[5]; - this.server.user.set( msg.params[1].toLowerCase(), tmpuser ); + this.server.user.set( msg.params[1], tmpuser ); break; case "313": // Oper tmpuser = {}; - if (this.server.user.has( msg.params[1].toLowerCase() )) - tmpuser = this.server.user.get( msg.params[1].toLowerCase() ); + if (this.server.user.hasi( msg.params[1] )) + tmpuser = this.server.user.geti( msg.params[1] ); tmpuser.oper = true; - this.server.user.set( msg.params[1].toLowerCase(), tmpuser ); + this.server.user.set( msg.params[1], tmpuser ); break; case "318": // last (check Data) tmpuser = {}; - if (this.server.user.has( msg.params[1].toLowerCase() )) - tmpuser = this.server.user.get( msg.params[1].toLowerCase() ); + if (this.server.user.hasi( msg.params[1] )) + tmpuser = this.server.user.geti( msg.params[1] ); tmpuser = { nickname: tmpuser.nickname || false, username: tmpuser.username || false, @@ -81,13 +82,13 @@ class irc { channels: tmpuser.channels || [], cached: ~~(Date.now() / 1000) }; - this.server.user.set( msg.params[1].toLowerCase(), tmpuser ); + this.server.user.set( msg.params[1], tmpuser ); break; case "319": // Chanlist Todo tmpchan = new Map(); tmpuser = {}; - if (this.server.user.has( msg.params[1].toLowerCase() )) { - tmpuser = this.server.user.get( msg.params[1].toLowerCase() ); + if (this.server.user.hasi( msg.params[1] )) { + tmpuser = this.server.user.geti( msg.params[1] ); if(tmpuser.channels) tmpchan = tmpuser.channels; } @@ -99,15 +100,15 @@ class irc { } tmpuser.channels = tmpchan; - this.server.user.set( msg.params[1].toLowerCase(), tmpuser ); + this.server.user.set( msg.params[1], tmpuser ); break; case "330": // Quarknet tmpuser = {}; - if (this.server.user.has( msg.params[1].toLowerCase() )) - tmpuser = this.server.user.get( msg.params[1].toLowerCase() ); + if (this.server.user.hasi( msg.params[1] )) + tmpuser = this.server.user.geti( msg.params[1] ); tmpuser.account = msg.params[2]; tmpuser.registered = true; - this.server.user.set( msg.params[1].toLowerCase(), tmpuser ); + this.server.user.set( msg.params[1], tmpuser ); break; // WHOIS END case "001": // welcome @@ -163,6 +164,12 @@ class irc { case "NOTICE": this.emit("data", ["notice", msg.params[1]]); break; + case "NICK": // nickchange + prefix = parsePrefix(msg.prefix); + if(this.server.user.hasi(prefix.nick)) + this.server.user.deli(prefix.nick); + this.whois(msg.params[0], true); // force + break; default: console.log(msg); break; @@ -243,9 +250,9 @@ class irc { } whois(user, force = false) { user = user.toLowerCase(); - if(this.server.user.has(user) && !force) { - if(this.server.user.get(user).cached >= ~~(Date.now() / 1000) - this._recachetime) { - console.log(this.server.user.get(user).cached, ~~(Date.now() / 1000) - this._recachetime); + 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"); return; } @@ -266,4 +273,24 @@ function parsePrefix(prefix) { username: hosttmp[0], hostname: hosttmp[1] }; -} \ No newline at end of file +} + +Map.prototype.hasi = function(val) { + for (let [key] of this) + if(key.toLowerCase() === val.toLowerCase()) + return true; + return false; +}; + +Map.prototype.geti = function(val) { + for (let [key, value] of this) + if(key.toLowerCase() === val.toLowerCase()) + return value; + return false; +}; + +Map.prototype.deli = function(val) { + for (let [key] of this) + if(key.toLowerCase() === val.toLowerCase()) + this.delete(key); +}; \ No newline at end of file