hardlounge/src/plugins/irc-events/part.js

39 lines
797 B
JavaScript
Raw Normal View History

"use strict";
const _ = require("lodash");
const Msg = require("../../models/msg");
2014-09-13 21:29:45 +00:00
module.exports = function (irc, network) {
const client = this;
irc.on("part", function (data) {
const chan = network.getChannel(data.channel);
2014-09-13 21:29:45 +00:00
if (typeof chan === "undefined") {
return;
}
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);
if (data.nick === irc.user.nick) {
2014-09-13 21:29:45 +00:00
network.channels = _.without(network.channels, chan);
chan.destroy();
2014-10-11 23:59:01 +00:00
client.save();
2014-09-13 21:29:45 +00:00
client.emit("part", {
chan: chan.id,
2014-09-13 21:29:45 +00:00
});
} else {
2017-11-16 20:32:03 +00:00
chan.removeUser(user);
2014-09-13 21:29:45 +00:00
}
});
};