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; padding-left: 20px;
} }
#chat table.channel-list { #chat table.channel-list,
#chat table.ban-list {
margin: 5px 10px; margin: 5px 10px;
width: calc(100% - 30px); width: calc(100% - 30px);
} }
#chat table.channel-list th, #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; padding: 5px;
vertical-align: top; vertical-align: top;
border-bottom: #eee 1px solid; border-bottom: #eee 1px solid;
@ -1022,7 +1025,10 @@ kbd {
} }
#chat table.channel-list .channel, #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; text-align: left;
} }

View File

@ -554,6 +554,15 @@
</div> </div>
</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="help-item">
<div class="subject"> <div class="subject">
<code>/clear</code> <code>/clear</code>

View File

@ -20,6 +20,7 @@ $(function() {
var commands = [ var commands = [
"/away", "/away",
"/back", "/back",
"/banlist",
"/close", "/close",
"/connect", "/connect",
"/deop", "/deop",
@ -247,6 +248,7 @@ $(function() {
"whois", "whois",
"ctcp", "ctcp",
"channel_list", "channel_list",
"ban_list",
].indexOf(type) !== -1) { ].indexOf(type) !== -1) {
template = "msg_action"; template = "msg_action";
} else if (type === "unhandled") { } else if (type === "unhandled") {
@ -379,7 +381,7 @@ $(function() {
var target = "#chan-" + data.chan; var target = "#chan-" + data.chan;
var container = chat.find(target + " .messages"); 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(); $(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 = { module.exports = {
actions: { actions: {
action: require("./actions/action.tpl"), action: require("./actions/action.tpl"),
ban_list: require("./actions/ban_list.tpl"),
channel_list: require("./actions/channel_list.tpl"), channel_list: require("./actions/channel_list.tpl"),
ctcp: require("./actions/ctcp.tpl"), ctcp: require("./actions/ctcp.tpl"),
invite: require("./actions/invite.tpl"), invite: require("./actions/invite.tpl"),

View File

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

View File

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

View File

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