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

38 lines
844 B
JavaScript
Raw Normal View History

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) {
var chan = _.findWhere(network.channels, {name: data.channels[0]});
if (typeof chan === "undefined") {
return;
}
2014-10-04 12:31:45 +00:00
var from = data.nick;
2015-09-30 22:39:57 +00:00
if (from === irc.me) {
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 {
2014-10-04 12:31:45 +00:00
var user = _.findWhere(chan.users, {name: from});
2014-09-13 21:29:45 +00:00
chan.users = _.without(chan.users, user);
client.emit("users", {
chan: chan.id,
users: chan.users
});
var msg = new Msg({
type: Msg.Type.PART,
2014-10-04 12:31:45 +00:00
mode: chan.getMode(from),
from: from
2014-09-13 21:29:45 +00:00
});
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
});
}
});
};