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

62 lines
1.3 KiB
JavaScript
Raw Normal View History

2017-04-22 12:51:21 +00:00
"use strict";
const Chan = require("../../models/chan");
const Msg = require("../../models/msg");
module.exports = function(irc, network) {
const client = this;
irc.on("banlist", function(banlist) {
const channel = banlist.channel;
const bans = banlist.bans;
2017-04-24 10:40:53 +00:00
if (!bans || bans.length === 0) {
2017-04-22 12:51:21 +00:00
const msg = new Msg({
time: Date.now(),
type: Msg.Type.ERROR,
text: "Banlist empty",
2017-04-22 12:51:21 +00:00
});
let chan = network.getChannel(channel);
// Send error to lobby if we receive banlist for a channel we're not in
if (typeof chan === "undefined") {
msg.showInActive = true;
chan = network.channels[0];
}
chan.pushMessage(client, msg, true);
2017-04-22 12:51:21 +00:00
return;
}
const chanName = `Banlist for ${channel}`;
let chan = network.getChannel(chanName);
2018-07-10 09:40:55 +00:00
const data = bans.map((ban) => ({
hostmask: ban.banned,
banned_by: ban.banned_by,
banned_at: ban.banned_at * 1000,
2018-07-10 09:16:24 +00:00
}));
2017-04-22 12:51:21 +00:00
if (typeof chan === "undefined") {
chan = client.createChannel({
2017-04-22 12:51:21 +00:00
type: Chan.Type.SPECIAL,
2018-07-10 09:16:24 +00:00
special: Chan.SpecialType.BANLIST,
name: chanName,
2018-07-10 09:16:24 +00:00
data: data,
2017-04-22 12:51:21 +00:00
});
client.emit("join", {
network: network.uuid,
chan: chan.getFilteredClone(true),
index: network.addChannel(chan),
2017-04-22 12:51:21 +00:00
});
2018-07-10 09:16:24 +00:00
} else {
chan.data = data;
2017-04-22 12:51:21 +00:00
2018-07-10 09:16:24 +00:00
client.emit("msg:special", {
chan: chan.id,
data: data,
});
}
2017-04-22 12:51:21 +00:00
});
};