thelounge/src/plugins/irc-events/part.js
2017-11-19 02:46:45 -05:00

42 lines
838 B
JavaScript

"use strict";
const _ = require("lodash");
const Msg = require("../../models/msg");
module.exports = function(irc, network) {
const client = this;
irc.on("part", function(data) {
const chan = network.getChannel(data.channel);
if (typeof chan === "undefined") {
return;
}
if (data.nick === irc.user.nick) {
network.channels = _.without(network.channels, chan);
chan.destroy();
client.save();
client.emit("part", {
chan: chan.id,
});
} else {
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,
});
chan.pushMessage(client, msg);
chan.users = _.without(chan.users, user);
client.emit("users", {
chan: chan.id,
});
}
});
};