hardlounge/src/plugins/irc-events/kick.js
2016-04-07 16:04:28 -04:00

40 lines
804 B
JavaScript

var _ = require("lodash");
var Msg = require("../../models/msg");
module.exports = function(irc, network) {
var client = this;
irc.on("kick", function(data) {
var from = data.nick;
var chan = _.find(network.channels, {name: data.channel});
var mode = chan.getMode(from);
if (typeof chan === "undefined") {
return;
}
if (data.client === irc.user.nick) {
chan.users = [];
} else {
chan.users = _.without(chan.users, _.find(chan.users, {name: data.client}));
}
client.emit("users", {
chan: chan.id
});
var msg = new Msg({
type: Msg.Type.KICK,
mode: mode,
from: from,
target: data.client,
text: data.message || "",
self: data.nick === irc.user.nick
});
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
});
});
};