thelounge/lib/plugins/part.js

35 lines
825 B
JavaScript
Raw Normal View History

2014-06-19 17:28:53 +02:00
var _ = require("lodash");
var Chan = require("../models/chan");
var Msg = require("../models/msg");
2014-06-23 19:28:36 +02:00
module.exports = function(slate, network) {
var client = this;
slate.on("part", function(data) {
2014-06-19 17:28:53 +02:00
var chan = _.findWhere(network.channels, {name: data.channels[0]});
if (typeof chan === "undefined") {
return;
}
2014-06-23 19:28:36 +02:00
if (data.nick == slate.me) {
2014-06-19 17:28:53 +02:00
network.channels = _.without(network.channels, chan);
2014-06-23 19:28:36 +02:00
client.emit("part", {
2014-06-19 17:28:53 +02:00
id: chan.id,
});
} else {
chan.users = _.without(chan.users, _.findWhere(chan.users, {name: data.nick}));
2014-06-23 19:28:36 +02:00
client.emit("users", {
2014-06-19 17:28:53 +02:00
id: chan.id,
users: chan.users,
});
var msg = new Msg({
type: "part",
from: data.nick,
});
chan.addMsg(msg);
2014-06-23 19:28:36 +02:00
client.emit("msg", {
2014-06-19 17:28:53 +02:00
id: chan.id,
msg: msg,
});
}
});
};