2016-10-09 21:14:02 +02:00
|
|
|
"use strict";
|
|
|
|
|
2014-09-13 23:29:45 +02:00
|
|
|
var _ = require("lodash");
|
|
|
|
var Msg = require("../../models/msg");
|
|
|
|
|
|
|
|
module.exports = function(irc, network) {
|
|
|
|
var client = this;
|
|
|
|
irc.on("part", function(data) {
|
2016-03-20 15:28:47 +01:00
|
|
|
var chan = network.getChannel(data.channel);
|
2014-09-13 23:29:45 +02:00
|
|
|
if (typeof chan === "undefined") {
|
|
|
|
return;
|
|
|
|
}
|
2014-10-04 14:31:45 +02:00
|
|
|
var from = data.nick;
|
2016-03-07 22:09:42 +01:00
|
|
|
if (from === 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-07-11 16:30:47 +02:00
|
|
|
const user = chan.findUser(from);
|
2014-09-13 23:29:45 +02:00
|
|
|
chan.users = _.without(chan.users, user);
|
|
|
|
client.emit("users", {
|
2017-11-15 07:35:15 +01:00
|
|
|
chan: chan.id,
|
2014-09-13 23:29:45 +02:00
|
|
|
});
|
|
|
|
var msg = new Msg({
|
|
|
|
type: Msg.Type.PART,
|
2016-03-12 10:36:55 +01:00
|
|
|
time: data.time,
|
2016-03-08 14:36:25 +01:00
|
|
|
mode: (user && user.mode) || "",
|
2016-02-23 17:22:41 +01:00
|
|
|
text: data.message || "",
|
2016-03-08 10:26:43 +01:00
|
|
|
hostmask: data.ident + "@" + data.hostname,
|
2017-11-15 07:35:15 +01:00
|
|
|
from: from,
|
2014-09-13 23:29:45 +02:00
|
|
|
});
|
2016-04-19 12:20:18 +02:00
|
|
|
chan.pushMessage(client, msg);
|
2014-09-13 23:29:45 +02:00
|
|
|
}
|
|
|
|
});
|
|
|
|
};
|