thelounge/src/plugins/irc-events/quit.js

35 lines
732 B
JavaScript
Raw Normal View History

"use strict";
const Msg = require("../../models/msg");
2014-09-13 23:29:45 +02:00
module.exports = function (irc, network) {
const client = this;
irc.on("quit", function (data) {
network.channels.forEach((chan) => {
2017-07-11 16:30:47 +02:00
const user = chan.findUser(data.nick);
2014-09-13 23:29:45 +02:00
if (typeof user === "undefined") {
return;
}
const msg = new Msg({
2016-03-12 10:36:55 +01:00
time: data.time,
2014-09-13 23:29:45 +02:00
type: Msg.Type.QUIT,
2016-02-23 17:22:41 +01:00
text: data.message || "",
hostmask: data.ident + "@" + data.hostname,
from: user,
2014-09-13 23:29:45 +02:00
});
chan.pushMessage(client, msg);
2017-11-16 21:32:03 +01:00
chan.removeUser(user);
2014-09-13 23:29:45 +02:00
});
2019-09-15 21:35:18 +02: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 23:29:45 +02:00
});
};