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

35 lines
792 B
TypeScript
Raw Permalink Normal View History

import {IrcEventHandler} from "../../client";
import Msg, {MessageType} from "../../models/msg";
2014-09-13 21:29:45 +00:00
export default <IrcEventHandler>function (irc, network) {
const client = this;
irc.on("quit", function (data) {
network.channels.forEach((chan) => {
2017-07-11 14:30:47 +00:00
const user = chan.findUser(data.nick);
2014-09-13 21:29:45 +00:00
if (typeof user === "undefined") {
return;
}
const msg = new Msg({
2016-03-12 09:36:55 +00:00
time: data.time,
type: MessageType.QUIT,
2016-02-23 16:22:41 +00:00
text: data.message || "",
hostmask: data.ident + "@" + data.hostname,
from: user,
2014-09-13 21:29:45 +00:00
});
chan.pushMessage(client, msg);
2017-11-16 20:32:03 +00:00
chan.removeUser(user);
2014-09-13 21:29:45 +00:00
});
2019-09-15 19:35:18 +00:00
// If user with the nick we are trying to keep has quit, try to get this nick
if (network.keepNick === data.nick) {
irc.changeNick(network.keepNick);
network.keepNick = null;
}
2014-09-13 21:29:45 +00:00
});
};