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