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

41 lines
944 B
TypeScript
Raw Normal View History

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