Skip to content

Commit

Permalink
Merge pull request #1009 from thelounge/yamanickill/1008-banlist
Browse files Browse the repository at this point in the history
Add support for banlist messages
  • Loading branch information
xPaw committed Apr 22, 2017
2 parents 934400f + 1e504f4 commit 78221fc
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 8 deletions.
12 changes: 9 additions & 3 deletions client/css/style.css
Expand Up @@ -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;
Expand All @@ -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;
}

Expand Down
9 changes: 9 additions & 0 deletions client/index.html
Expand Up @@ -554,6 +554,15 @@ <h2>Commands</h2>
</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>
Expand Down
4 changes: 3 additions & 1 deletion client/js/lounge.js
Expand Up @@ -20,6 +20,7 @@ $(function() {
var commands = [
"/away",
"/back",
"/banlist",
"/close",
"/connect",
"/deop",
Expand Down Expand Up @@ -247,6 +248,7 @@ $(function() {
"whois",
"ctcp",
"channel_list",
"ban_list",
].indexOf(type) !== -1) {
template = "msg_action";
} else if (type === "unhandled") {
Expand Down Expand Up @@ -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();
}

Expand Down
18 changes: 18 additions & 0 deletions client/views/actions/ban_list.tpl
@@ -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>
1 change: 1 addition & 0 deletions client/views/index.js
Expand Up @@ -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"),
Expand Down
1 change: 1 addition & 0 deletions src/client.js
Expand Up @@ -17,6 +17,7 @@ var id = 0;
var events = [
"connection",
"unhandled",
"banlist",
"ctcp",
"error",
"invite",
Expand Down
3 changes: 2 additions & 1 deletion src/models/msg.js
Expand Up @@ -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;
Expand Down
13 changes: 10 additions & 3 deletions src/plugins/inputs/mode.js
@@ -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",
Expand All @@ -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) {
Expand All @@ -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]`
Expand All @@ -36,6 +39,7 @@ exports.input = function(network, chan, cmd, args) {
}

const mode = {
banlist: "+b",
op: "+o",
hop: "+h",
voice: "+v",
Expand All @@ -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);
});
Expand Down
48 changes: 48 additions & 0 deletions src/plugins/irc-events/banlist.js
@@ -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
);
});
};

0 comments on commit 78221fc

Please sign in to comment.