2016-10-09 21:14:02 +02:00
|
|
|
"use strict";
|
|
|
|
|
2017-11-10 21:44:14 +01:00
|
|
|
const _ = require("lodash");
|
|
|
|
const Msg = require("../../models/msg");
|
2014-09-13 23:29:45 +02:00
|
|
|
|
2020-03-21 21:55:36 +01:00
|
|
|
module.exports = function (irc, network) {
|
2017-11-10 21:44:14 +01:00
|
|
|
const client = this;
|
|
|
|
|
2020-03-21 21:55:36 +01:00
|
|
|
irc.on("part", function (data) {
|
2017-11-10 21:44:14 +01:00
|
|
|
const chan = network.getChannel(data.channel);
|
|
|
|
|
2014-09-13 23:29:45 +02:00
|
|
|
if (typeof chan === "undefined") {
|
|
|
|
return;
|
|
|
|
}
|
2017-11-10 21:44:14 +01:00
|
|
|
|
2019-01-21 17:07:00 +01:00
|
|
|
const user = chan.getUser(data.nick);
|
|
|
|
const msg = new Msg({
|
|
|
|
type: Msg.Type.PART,
|
|
|
|
time: data.time,
|
|
|
|
text: data.message || "",
|
|
|
|
hostmask: data.ident + "@" + data.hostname,
|
|
|
|
from: user,
|
|
|
|
self: data.nick === irc.user.nick,
|
|
|
|
});
|
|
|
|
chan.pushMessage(client, msg);
|
|
|
|
|
2017-11-10 21:44:14 +01:00
|
|
|
if (data.nick === irc.user.nick) {
|
2014-09-13 23:29:45 +02:00
|
|
|
network.channels = _.without(network.channels, chan);
|
2017-08-11 14:02:58 +02:00
|
|
|
chan.destroy();
|
2014-10-12 01:59:01 +02:00
|
|
|
client.save();
|
2014-09-13 23:29:45 +02:00
|
|
|
client.emit("part", {
|
2017-11-15 07:35:15 +01:00
|
|
|
chan: chan.id,
|
2014-09-13 23:29:45 +02:00
|
|
|
});
|
|
|
|
} else {
|
2017-11-16 21:32:03 +01:00
|
|
|
chan.removeUser(user);
|
2017-11-10 21:44:14 +01:00
|
|
|
client.emit("users", {
|
|
|
|
chan: chan.id,
|
|
|
|
});
|
2014-09-13 23:29:45 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|