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;
|
2016-02-14 17:09:51 +00:00
|
|
|
var user = _.find(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", {
|
2016-02-17 02:29:44 +00:00
|
|
|
chan: chan.id
|
2014-09-13 21:29:45 +00:00
|
|
|
});
|
|
|
|
var msg = new Msg({
|
|
|
|
type: Msg.Type.QUIT,
|
2014-10-04 12:31:45 +00:00
|
|
|
mode: chan.getMode(from),
|
2016-02-23 16:22:41 +00:00
|
|
|
text: data.message || "",
|
|
|
|
hostmask: data.hostmask.username + "@" + data.hostmask.hostname,
|
2014-10-04 12:31:45 +00:00
|
|
|
from: from
|
2014-09-13 21:29:45 +00:00
|
|
|
});
|
|
|
|
chan.messages.push(msg);
|
|
|
|
client.emit("msg", {
|
|
|
|
chan: chan.id,
|
|
|
|
msg: msg
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|