hardlounge/server/plugins/irc-events/whois.ts

63 lines
1.4 KiB
TypeScript
Raw Permalink Normal View History

import {IrcEventHandler} from "../../client";
import {ChanType} from "../../models/chan";
import Msg, {MessageType} from "../../models/msg";
2014-09-13 21:29:45 +00:00
export default <IrcEventHandler>function (irc, network) {
const client = this;
irc.on("whois", handleWhois);
irc.on("whowas", (data) => {
data.whowas = true;
handleWhois(data);
});
function handleWhois(data) {
let chan = network.getChannel(data.nick);
2014-09-13 21:29:45 +00:00
if (typeof chan === "undefined") {
// Do not create new windows for errors as they may contain illegal characters
if (data.error) {
chan = network.getLobby();
} else {
chan = client.createChannel({
type: ChanType.QUERY,
name: data.nick,
});
client.emit("join", {
shouldOpen: true,
network: network.uuid,
chan: chan.getFilteredClone(true),
index: network.addChannel(chan),
});
chan.loadMessages(client, network);
client.save();
}
2014-09-13 21:29:45 +00:00
}
2016-03-09 08:27:01 +00:00
let msg;
2016-03-09 08:27:01 +00:00
if (data.error) {
msg = new Msg({
type: MessageType.ERROR,
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
text: "No such nick: " + data.nick,
2016-03-09 08:27:01 +00:00
});
} else {
// Absolute datetime in milliseconds since nick is idle
data.idleTime = Date.now() - data.idle * 1000;
2017-11-02 11:01:45 +00:00
// Absolute datetime in milliseconds when nick logged on.
data.logonTime = data.logon * 1000;
2016-03-09 08:27:01 +00:00
msg = new Msg({
type: MessageType.WHOIS,
whois: data,
2016-03-09 08:27:01 +00:00
});
}
chan.pushMessage(client, msg);
}
2014-09-13 21:29:45 +00:00
};