thelounge/server/plugins/irc-events/kick.ts

42 lines
962 B
TypeScript
Raw Permalink Normal View History

import {IrcEventHandler} from "../../client";
2024-02-15 23:01:22 +01:00
import Msg from "../../models/msg";
import {MessageType} from "../../../shared/types/msg";
2024-02-24 11:13:11 +01:00
import {ChanState} from "../../../shared/types/chan";
2014-09-13 23:29:45 +02:00
export default <IrcEventHandler>function (irc, network) {
const client = this;
irc.on("kick", function (data) {
const chan = network.getChannel(data.channel!);
2014-09-13 23:29:45 +02:00
if (typeof chan === "undefined") {
return;
}
2014-10-04 14:31:45 +02:00
2024-04-15 07:52:58 +02:00
const user = chan.getUser(data.kicked!);
const msg = new Msg({
type: MessageType.KICK,
time: data.time,
from: chan.getUser(data.nick),
2024-04-15 07:52:58 +02:00
target: user,
text: data.message || "",
highlight: data.kicked === irc.user.nick,
self: data.nick === irc.user.nick,
});
chan.pushMessage(client, msg);
2017-07-11 16:30:47 +02:00
2016-03-08 11:16:20 +01:00
if (data.kicked === irc.user.nick) {
2017-11-16 21:32:03 +01:00
chan.users = new Map();
chan.state = ChanState.PARTED;
client.emit("channel:state", {
chan: chan.id,
state: chan.state,
});
2014-09-13 23:29:45 +02:00
} else {
2024-04-15 07:52:58 +02:00
chan.removeUser(user);
2014-09-13 23:29:45 +02:00
}
});
};