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

60 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);
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,
name: chanName,
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
});
}
chan.pushMessage(client,
new Msg({
type: Msg.Type.BANLIST,
bans: bans.map((data) => ({
hostmask: data.banned,
banned_by: data.banned_by,
banned_at: data.banned_at * 1000,
})),
2017-04-22 12:51:21 +00:00
}),
true
);
});
};