This commit is contained in:
Flummi 2017-11-17 18:38:00 +01:00
parent e04294816e
commit eca4671b0b

View File

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