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

42 lines
838 B
JavaScript
Raw Normal View History

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