Add support for banlist messages

This commit is contained in:
Alistair McKinlay 2017-04-22 13:51:21 +01:00
parent 761dfbb33c
commit 1e504f4383
9 changed files with 101 additions and 8 deletions

View file

@ -1005,13 +1005,16 @@ kbd {
padding-left: 20px;
}
#chat table.channel-list {
#chat table.channel-list,
#chat table.ban-list {
margin: 5px 10px;
width: calc(100% - 30px);
}
#chat table.channel-list th,
#chat table.channel-list td {
#chat table.ban-list th,
#chat table.channel-list td,
#chat table.ban-list td {
padding: 5px;
vertical-align: top;
border-bottom: #eee 1px solid;
@ -1022,7 +1025,10 @@ kbd {
}
#chat table.channel-list .channel,
#chat table.channel-list .topic {
#chat table.channel-list .topic,
#chat table.ban-list .hostmask,
#chat table.ban-list .banned_by,
#chat table.ban-list .banned_at {
text-align: left;
}

View file

@ -554,6 +554,15 @@
</div>
</div>
<div class="help-item">
<div class="subject">
<code>/banlist</code>
</div>
<div class="description">
<p>Load the banlist for the current channel.</p>
</div>
</div>
<div class="help-item">
<div class="subject">
<code>/clear</code>

View file

@ -20,6 +20,7 @@ $(function() {
var commands = [
"/away",
"/back",
"/banlist",
"/close",
"/connect",
"/deop",
@ -247,6 +248,7 @@ $(function() {
"whois",
"ctcp",
"channel_list",
"ban_list",
].indexOf(type) !== -1) {
template = "msg_action";
} else if (type === "unhandled") {
@ -379,7 +381,7 @@ $(function() {
var target = "#chan-" + data.chan;
var container = chat.find(target + " .messages");
if (data.msg.type === "channel_list") {
if (data.msg.type === "channel_list" || data.msg.type === "ban_list") {
$(container).empty();
}

View file

@ -0,0 +1,18 @@
<table class="ban-list">
<thead>
<tr>
<th class="hostmask">Banned</th>
<th class="banned_by">Banned By</th>
<th class="banned_at">Banned At</th>
</tr>
</thead>
<tbody>
{{#each bans}}
<tr>
<td class="hostmask">{{hostmask}}</td>
<td class="banned_by">{{{parse banned_by}}}</td>
<td class="banned_at">{{{localetime banned_at}}}</td>
</tr>
{{/each}}
</tbody>
</table>

View file

@ -3,6 +3,7 @@
module.exports = {
actions: {
action: require("./actions/action.tpl"),
ban_list: require("./actions/ban_list.tpl"),
channel_list: require("./actions/channel_list.tpl"),
ctcp: require("./actions/ctcp.tpl"),
invite: require("./actions/invite.tpl"),

View file

@ -17,6 +17,7 @@ var id = 0;
var events = [
"connection",
"unhandled",
"banlist",
"ctcp",
"error",
"invite",

View file

@ -20,7 +20,8 @@ Msg.Type = {
CTCP: "ctcp",
TOPIC: "topic",
TOPIC_SET_BY: "topic_set_by",
WHOIS: "whois"
WHOIS: "whois",
BANLIST: "ban_list"
};
module.exports = Msg;

View file

@ -1,11 +1,10 @@
"use strict";
exports.commands = ["mode", "op", "voice", "deop", "devoice"];
var Chan = require("../../models/chan");
var Msg = require("../../models/msg");
exports.commands = [
"banlist",
"mode",
"op",
"deop",
@ -15,6 +14,10 @@ exports.commands = [
"devoice",
];
const chanCommands = [
"banlist"
];
exports.input = function(network, chan, cmd, args) {
if (cmd !== "mode") {
if (chan.type !== Chan.Type.CHANNEL) {
@ -26,7 +29,7 @@ exports.input = function(network, chan, cmd, args) {
return;
}
if (args.length === 0) {
if (args.length === 0 && chanCommands.indexOf(cmd) === -1) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
text: `Usage: /${cmd} <nick> [...nick]`
@ -36,6 +39,7 @@ exports.input = function(network, chan, cmd, args) {
}
const mode = {
banlist: "+b",
op: "+o",
hop: "+h",
voice: "+v",
@ -44,6 +48,9 @@ exports.input = function(network, chan, cmd, args) {
devoice: "-v"
}[cmd];
if (chanCommands.indexOf(cmd) > -1 && args.length === 0) {
network.irc.raw("MODE", chan.name, mode);
}
args.forEach(function(target) {
network.irc.raw("MODE", chan.name, mode, target);
});

View file

@ -0,0 +1,48 @@
"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;
if (!bans) {
const msg = new Msg({
time: Date.now(),
type: Msg.Type.ERROR,
text: "Banlist empty"
});
network.getChannel(channel).pushMessage(client, msg, true);
return;
}
const chanName = `Banlist for ${channel}`;
let chan = network.getChannel(chanName);
if (typeof chan === "undefined") {
chan = new Chan({
type: Chan.Type.SPECIAL,
name: chanName
});
network.channels.push(chan);
client.emit("join", {
network: network.id,
chan: chan
});
}
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
}))
}),
true
);
});
};