thelounge/src/plugins/irc-events/kick.js

48 lines
971 B
JavaScript
Raw Normal View History

2014-09-13 23:29:45 +02:00
var _ = require("lodash");
var Msg = require("../../models/msg");
module.exports = function(irc, network) {
var client = this;
irc.on("kick", function(data) {
2014-10-04 14:31:45 +02:00
var from = data.nick;
2016-02-14 18:09:51 +01:00
var chan = _.find(network.channels, {name: data.channel});
2014-10-04 14:31:45 +02:00
var mode = chan.getMode(from);
2014-09-13 23:29:45 +02:00
if (typeof chan === "undefined") {
return;
}
2014-10-04 14:31:45 +02:00
2015-10-01 00:39:57 +02:00
if (data.client === irc.me) {
2014-09-13 23:29:45 +02:00
chan.users = [];
} else {
2016-02-14 18:09:51 +01:00
chan.users = _.without(chan.users, _.find(chan.users, {name: data.client}));
2014-09-13 23:29:45 +02:00
}
2014-10-04 14:31:45 +02:00
2014-09-13 23:29:45 +02:00
client.emit("users", {
chan: chan.id,
users: chan.users
});
2014-10-04 14:31:45 +02:00
2014-09-14 20:49:42 +02:00
var self = false;
2015-10-01 00:39:57 +02:00
if (data.nick.toLowerCase() === irc.me.toLowerCase()) {
2014-09-14 20:49:42 +02:00
self = true;
}
2016-01-23 15:39:54 +01:00
var reason = data.message || "";
if (reason.length > 0) {
reason = " (" + reason + ")";
}
2014-09-13 23:29:45 +02:00
var msg = new Msg({
type: Msg.Type.KICK,
2014-10-04 14:31:45 +02:00
mode: mode,
from: from,
2016-01-23 15:39:54 +01:00
text: data.client + reason,
2014-09-14 20:49:42 +02:00
self: self
2014-09-13 23:29:45 +02:00
});
chan.messages.push(msg);
client.emit("msg", {
chan: chan.id,
msg: msg
});
});
};