2022-06-19 00:25:21 +00:00
|
|
|
import {IrcEventHandler} from "../../client";
|
|
|
|
import {ChanType} from "../../models/chan";
|
2016-10-09 19:14:02 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
import Msg, {MessageType} from "../../models/msg";
|
2014-09-13 21:29:45 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
export default <IrcEventHandler>function (irc, network) {
|
2017-11-10 20:44:14 +00:00
|
|
|
const client = this;
|
2018-06-20 18:01:45 +00:00
|
|
|
|
|
|
|
irc.on("whois", handleWhois);
|
|
|
|
|
|
|
|
irc.on("whowas", (data) => {
|
|
|
|
data.whowas = true;
|
|
|
|
|
|
|
|
handleWhois(data);
|
|
|
|
});
|
|
|
|
|
|
|
|
function handleWhois(data) {
|
2017-11-10 20:44:14 +00:00
|
|
|
let chan = network.getChannel(data.nick);
|
|
|
|
|
2014-09-13 21:29:45 +00:00
|
|
|
if (typeof chan === "undefined") {
|
2018-06-20 18:01:45 +00:00
|
|
|
// Do not create new windows for errors as they may contain illegal characters
|
|
|
|
if (data.error) {
|
2023-02-27 17:30:33 +00:00
|
|
|
chan = network.getLobby();
|
2018-06-20 18:01:45 +00:00
|
|
|
} else {
|
|
|
|
chan = client.createChannel({
|
2022-06-19 00:25:21 +00:00
|
|
|
type: ChanType.QUERY,
|
2018-06-20 18:01:45 +00:00
|
|
|
name: data.nick,
|
|
|
|
});
|
2018-03-12 12:42:59 +00:00
|
|
|
|
2018-06-20 18:01:45 +00:00
|
|
|
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
|
|
|
|
2017-11-10 20:44:14 +00:00
|
|
|
let msg;
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2016-03-09 08:27:01 +00:00
|
|
|
if (data.error) {
|
|
|
|
msg = new Msg({
|
2022-06-19 00:25:21 +00:00
|
|
|
type: MessageType.ERROR,
|
|
|
|
// eslint-disable-next-line @typescript-eslint/restrict-plus-operands
|
2017-11-15 06:35:15 +00:00
|
|
|
text: "No such nick: " + data.nick,
|
2016-03-09 08:27:01 +00:00
|
|
|
});
|
|
|
|
} else {
|
2016-10-27 03:46:14 +00:00
|
|
|
// 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({
|
2022-06-19 00:25:21 +00:00
|
|
|
type: MessageType.WHOIS,
|
2017-11-15 06:35:15 +00:00
|
|
|
whois: data,
|
2016-03-09 08:27:01 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2016-04-19 10:20:18 +00:00
|
|
|
chan.pushMessage(client, msg);
|
2018-06-20 18:01:45 +00:00
|
|
|
}
|
2014-09-13 21:29:45 +00:00
|
|
|
};
|