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