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