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

38 lines
793 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";
2014-09-13 23:29:45 +02:00
export default <IrcEventHandler>function (irc, network) {
const client = this;
irc.on("part", function (data) {
if (!data.channel) {
return;
}
const chan = network.getChannel(data.channel);
2014-09-13 23:29:45 +02:00
if (typeof chan === "undefined") {
return;
}
const user = chan.getUser(data.nick);
const msg = new Msg({
type: MessageType.PART,
time: data.time,
text: data.message || "",
hostmask: data.ident + "@" + data.hostname,
from: user,
self: data.nick === irc.user.nick,
});
chan.pushMessage(client, msg);
if (data.nick === irc.user.nick) {
client.part(network, chan);
2014-09-13 23:29:45 +02:00
} else {
2017-11-16 21:32:03 +01:00
chan.removeUser(user);
2014-09-13 23:29:45 +02:00
}
});
};