diff --git a/src/inc/clients/irc.js b/src/inc/clients/irc.js index 0f3ad36..0d591db 100644 --- a/src/inc/clients/irc.js +++ b/src/inc/clients/irc.js @@ -18,7 +18,7 @@ class irc { this.username = this.options.username || "test"; this.realname = this.options.realname || "test"; this.channels = this.options.channels || []; - this._recachetime = (10 * 1000); // 10 minutes + this._recachetime = 60 * 5; // 10 minutes this.server = { motd: "", me: {}, @@ -121,7 +121,7 @@ class irc { username: msg.params[2], hostname: msg.params[3] }); - this.send(`WHOIS ${msg.params[5]}`); + this.whois(msg.params[5]); break; case "315": // who_end console.log(this.server.channel); @@ -144,10 +144,13 @@ class irc { this.send(`PONG ${msg.params.join``}`); break; case "JOIN": + console.log("join", msg); this.send(`WHO ${msg.params[0]}`); break; case "PART": + console.log("part", msg); delete this.server.user[msg.params[0]]; + //this.whois(msg.params[0], true); // force whois break; case "PRIVMSG": if (msg.params[1] === "\u0001VERSION\u0001") @@ -224,6 +227,7 @@ class irc { // commands join: chan => this.join(chan), part: (chan, msg) => this.part(chan, msg), + whois: user => this.whois(user), write: msg => this.send(msg) }; } @@ -233,6 +237,18 @@ class irc { part(channel, msg=false) { this.send(`PART ${(typeof channel === "object") ? channel.join(',') : channel}${msg ? " " + msg : " part"}`); } + 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); + console.log(user, "already cached"); + return; + } + } + console.log("get whois for", user); + this.send(`WHOIS ${user}`); + } } module.exports = irc;