thelounge/src/plugins/irc-events/whois.js

46 lines
1,009 B
JavaScript
Raw Normal View History

"use strict";
const Chan = require("../../models/chan");
const Msg = require("../../models/msg");
2014-09-13 23:29:45 +02:00
module.exports = function(irc, network) {
const client = this;
2016-03-09 09:27:01 +01:00
irc.on("whois", function(data) {
let chan = network.getChannel(data.nick);
2014-09-13 23:29:45 +02:00
if (typeof chan === "undefined") {
chan = new Chan({
type: Chan.Type.QUERY,
name: data.nick,
2014-09-13 23:29:45 +02:00
});
network.channels.push(chan);
client.emit("join", {
shouldOpen: true,
2014-09-13 23:29:45 +02:00
network: network.id,
chan: chan.getFilteredClone(true),
2014-09-13 23:29:45 +02:00
});
2017-11-28 18:56:53 +01:00
chan.loadMessages(client, network);
2014-09-13 23:29:45 +02:00
}
2016-03-09 09:27:01 +01:00
let msg;
2016-03-09 09:27:01 +01:00
if (data.error) {
msg = new Msg({
type: Msg.Type.ERROR,
text: "No such nick: " + data.nick,
2016-03-09 09:27:01 +01:00
});
} else {
// Absolute datetime in milliseconds since nick is idle
data.idleTime = Date.now() - data.idle * 1000;
2017-11-02 12:01:45 +01:00
// Absolute datetime in milliseconds when nick logged on.
data.logonTime = data.logon * 1000;
2016-03-09 09:27:01 +01:00
msg = new Msg({
type: Msg.Type.WHOIS,
whois: data,
2016-03-09 09:27:01 +01:00
});
}
chan.pushMessage(client, msg);
2014-09-13 23:29:45 +02:00
});
};