Add ban/unban command

Fixes #1073
This commit is contained in:
Alistair McKinlay 2017-04-24 11:40:53 +01:00
parent ac9101ed61
commit b03d01b6eb
6 changed files with 69 additions and 11 deletions

View File

@ -554,6 +554,16 @@
</div> </div>
</div> </div>
<div class="help-item">
<div class="subject">
<code>/ban nick</code>
</div>
<div class="description">
<p>Ban (<code>+b</code>) a user from the current channel.
This can be a nickname or a hostmask.</p>
</div>
</div>
<div class="help-item"> <div class="help-item">
<div class="subject"> <div class="subject">
<code>/banlist</code> <code>/banlist</code>
@ -799,6 +809,16 @@
</div> </div>
</div> </div>
<div class="help-item">
<div class="subject">
<code>/unban nick</code>
</div>
<div class="description">
<p>Unban (<code>-b</code>) a user from the current channel.</p>
This can be a nickname or a hostmask.</p>
</div>
</div>
<div class="help-item"> <div class="help-item">
<div class="subject"> <div class="subject">
<code>/voice nick [...nick]</code> <code>/voice nick [...nick]</code>

View File

@ -3,6 +3,7 @@
const commands = [ const commands = [
"/away", "/away",
"/back", "/back",
"/ban",
"/banlist", "/banlist",
"/close", "/close",
"/connect", "/connect",
@ -28,6 +29,7 @@ const commands = [
"/server", "/server",
"/slap", "/slap",
"/topic", "/topic",
"/unban",
"/voice", "/voice",
"/whois" "/whois"
]; ];

View File

@ -36,6 +36,7 @@ var events = [
"whois" "whois"
]; ];
var inputs = [ var inputs = [
"ban",
"ctcp", "ctcp",
"msg", "msg",
"part", "part",

44
src/plugins/inputs/ban.js Normal file
View File

@ -0,0 +1,44 @@
"use strict";
var Chan = require("../../models/chan");
var Msg = require("../../models/msg");
exports.commands = [
"ban",
"unban",
"banlist"
];
exports.input = function(network, chan, cmd, args) {
if (chan.type !== Chan.Type.CHANNEL) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
text: `${cmd} command can only be used in channels.`
}));
return;
}
if (cmd !== "banlist" && args.length === 0) {
if (args.length === 0) {
chan.pushMessage(this, new Msg({
type: Msg.Type.ERROR,
text: `Usage: /${cmd} <nick>`
}));
return;
}
}
switch (cmd) {
case "ban":
network.irc.ban(chan.name, args[0]);
break;
case "unban":
network.irc.unban(chan.name, args[0]);
break;
case "banlist":
network.irc.banlist(chan.name);
break;
}
};

View File

@ -4,7 +4,6 @@ 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",
@ -14,10 +13,6 @@ 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) {
@ -29,7 +24,7 @@ exports.input = function(network, chan, cmd, args) {
return; return;
} }
if (args.length === 0 && chanCommands.indexOf(cmd) === -1) { if (args.length === 0) {
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]`
@ -39,7 +34,6 @@ 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",
@ -48,9 +42,6 @@ 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

@ -9,7 +9,7 @@ module.exports = function(irc, network) {
irc.on("banlist", function(banlist) { irc.on("banlist", function(banlist) {
const channel = banlist.channel; const channel = banlist.channel;
const bans = banlist.bans; const bans = banlist.bans;
if (!bans) { if (!bans || bans.length === 0) {
const msg = new Msg({ const msg = new Msg({
time: Date.now(), time: Date.now(),
type: Msg.Type.ERROR, type: Msg.Type.ERROR,