2022-06-19 00:25:21 +00:00
|
|
|
import {IrcEventHandler} from "../../client";
|
2017-04-22 12:51:21 +00:00
|
|
|
|
2024-02-15 22:01:22 +00:00
|
|
|
import Msg from "../../models/msg";
|
|
|
|
import {MessageType} from "../../../shared/types/msg";
|
2024-02-24 10:13:11 +00:00
|
|
|
import {SpecialChanType, ChanType} from "../../../shared/types/chan";
|
2017-04-22 12:51:21 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
export default <IrcEventHandler>function (irc, network) {
|
2017-04-22 12:51:21 +00:00
|
|
|
const client = this;
|
|
|
|
|
2019-04-14 11:44:44 +00:00
|
|
|
irc.on("banlist", (list) => {
|
|
|
|
const data = list.bans.map((ban) => ({
|
|
|
|
hostmask: ban.banned,
|
|
|
|
banned_by: ban.banned_by,
|
|
|
|
banned_at: ban.banned_at * 1000,
|
|
|
|
}));
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
handleList(SpecialChanType.BANLIST, "Ban list", list.channel, data);
|
2019-04-14 11:44:44 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
irc.on("inviteList", (list) => {
|
|
|
|
const data = list.invites.map((invite) => ({
|
|
|
|
hostmask: invite.invited,
|
|
|
|
invited_by: invite.invited_by,
|
|
|
|
invited_at: invite.invited_at * 1000,
|
|
|
|
}));
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
handleList(SpecialChanType.INVITELIST, "Invite list", list.channel, data);
|
2019-04-14 11:44:44 +00:00
|
|
|
});
|
|
|
|
|
2022-06-19 00:25:21 +00:00
|
|
|
function handleList(
|
|
|
|
type: SpecialChanType,
|
|
|
|
name: string,
|
|
|
|
channel: string,
|
|
|
|
data: {
|
|
|
|
hostmask: string;
|
|
|
|
invited_by?: string;
|
|
|
|
inivted_at?: number;
|
|
|
|
}[]
|
|
|
|
) {
|
2019-04-14 11:44:44 +00:00
|
|
|
if (data.length === 0) {
|
2017-04-22 12:51:21 +00:00
|
|
|
const msg = new Msg({
|
2022-06-19 00:25:21 +00:00
|
|
|
time: new Date(),
|
|
|
|
type: MessageType.ERROR,
|
2019-04-14 11:44:44 +00:00
|
|
|
text: `${name} is empty`,
|
2017-04-22 12:51:21 +00:00
|
|
|
});
|
2018-02-22 09:01:49 +00:00
|
|
|
let chan = network.getChannel(channel);
|
|
|
|
|
2019-04-14 11:44:44 +00:00
|
|
|
// Send error to lobby if we receive empty list for a channel we're not in
|
2018-02-22 09:01:49 +00:00
|
|
|
if (typeof chan === "undefined") {
|
|
|
|
msg.showInActive = true;
|
2023-02-27 17:30:33 +00:00
|
|
|
chan = network.getLobby();
|
2018-02-22 09:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
chan.pushMessage(client, msg, true);
|
|
|
|
|
2017-04-22 12:51:21 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-04-14 11:44:44 +00:00
|
|
|
const chanName = `${name} for ${channel}`;
|
2017-04-22 12:51:21 +00:00
|
|
|
let chan = network.getChannel(chanName);
|
2018-02-20 07:28:04 +00:00
|
|
|
|
2017-04-22 12:51:21 +00:00
|
|
|
if (typeof chan === "undefined") {
|
2018-04-27 10:16:23 +00:00
|
|
|
chan = client.createChannel({
|
2022-06-19 00:25:21 +00:00
|
|
|
type: ChanType.SPECIAL,
|
2019-04-14 11:44:44 +00:00
|
|
|
special: type,
|
2017-11-15 06:35:15 +00:00
|
|
|
name: chanName,
|
2018-07-10 09:16:24 +00:00
|
|
|
data: data,
|
2017-04-22 12:51:21 +00:00
|
|
|
});
|
|
|
|
client.emit("join", {
|
2018-04-26 09:06:01 +00:00
|
|
|
network: network.uuid,
|
2017-12-03 14:29:50 +00:00
|
|
|
chan: chan.getFilteredClone(true),
|
2024-03-03 10:33:40 +00:00
|
|
|
shouldOpen: false,
|
2018-03-12 12:42:59 +00:00
|
|
|
index: network.addChannel(chan),
|
2017-04-22 12:51:21 +00:00
|
|
|
});
|
2018-07-10 09:16:24 +00:00
|
|
|
} else {
|
|
|
|
chan.data = data;
|
2017-04-22 12:51:21 +00:00
|
|
|
|
2018-07-10 09:16:24 +00:00
|
|
|
client.emit("msg:special", {
|
|
|
|
chan: chan.id,
|
|
|
|
data: data,
|
|
|
|
});
|
|
|
|
}
|
2019-04-14 11:44:44 +00:00
|
|
|
}
|
2017-04-22 12:51:21 +00:00
|
|
|
};
|