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

31 lines
663 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("quit", function(data) {
network.channels.forEach(function(chan) {
2014-10-04 12:31:45 +00:00
var from = data.nick;
var user = _.findWhere(chan.users, {name: from});
2014-09-13 21:29:45 +00:00
if (typeof user === "undefined") {
return;
}
chan.users = _.without(chan.users, user);
client.emit("users", {
chan: chan.id,
users: chan.users
});
var msg = new Msg({
type: Msg.Type.QUIT,
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
});
});
});
};