hasi geti deli :⁾

This commit is contained in:
Flummi 2017-11-18 23:41:21 +01:00
parent c365236921
commit 93407fba43
2 changed files with 57 additions and 29 deletions

View File

@ -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",

View File

@ -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;
}
@ -267,3 +274,23 @@ function parsePrefix(prefix) {
hostname: hosttmp[1]
};
}
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);
};