From 3994b4244429398b20ee01077d3da498665fd1e8 Mon Sep 17 00:00:00 2001 From: Calvin Montgomery Date: Thu, 22 May 2014 19:34:46 -0700 Subject: [PATCH] Add /kickanons; fix handling of kickban commands with no arguments --- lib/channel/kickban.js | 40 ++++++++++++++++++++++++++++++++++++++-- 1 file changed, 38 insertions(+), 2 deletions(-) diff --git a/lib/channel/kickban.js b/lib/channel/kickban.js index 51047126..5771ed2b 100644 --- a/lib/channel/kickban.js +++ b/lib/channel/kickban.js @@ -15,6 +15,7 @@ function KickBanModule(channel) { if (this.channel.modules.chat) { this.channel.modules.chat.registerCommand("/kick", this.handleCmdKick.bind(this)); + this.channel.modules.chat.registerCommand("/kickanons", this.handleCmdKickAnons.bind(this)); this.channel.modules.chat.registerCommand("/ban", this.handleCmdBan.bind(this)); this.channel.modules.chat.registerCommand("/ipban", this.handleCmdIPBan.bind(this)); this.channel.modules.chat.registerCommand("/banip", this.handleCmdIPBan.bind(this)); @@ -141,6 +142,12 @@ KickBanModule.prototype.handleCmdKick = function (user, msg, meta) { var args = msg.split(" "); args.shift(); /* shift off /kick */ + if (args.length === 0) { + return user.socket.emit("errorMsg", { + msg: "No kick target specified. If you're trying to kick " + + "anonymous users, use /kickanons" + }); + } var name = args.shift().toLowerCase(); var reason = args.join(" "); var target = null; @@ -171,11 +178,35 @@ KickBanModule.prototype.handleCmdKick = function (user, msg, meta) { } }; +KickBanModule.prototype.handleCmdKickAnons = function (user, msg, meta) { + if (!this.channel.modules.permissions.canKick(user)) { + return; + } + + var users = Array.prototype.slice.call(this.channel.users); + users.forEach(function (u) { + if (!u.is(Flags.U_LOGGED_IN)) { + u.kick("anonymous user"); + } + }); + + this.channel.logger.log("[mod] " + user.getName() + " kicked anonymous users."); + if (this.channel.modules.chat) { + this.channel.modules.chat.sendModMessage(user.getName() + " kicked anonymous " + + "users"); + } +}; + /* /ban - name bans */ KickBanModule.prototype.handleCmdBan = function (user, msg, meta) { var args = msg.split(" "); args.shift(); /* shift off /ban */ - var name = args.shift(); + if (args.length === 0) { + return user.socket.emit("errorMsg", { + msg: "No ban target specified." + }); + } + var name = args.shift().toLowerCase(); var reason = args.join(" "); var chan = this.channel; @@ -189,7 +220,12 @@ KickBanModule.prototype.handleCmdBan = function (user, msg, meta) { KickBanModule.prototype.handleCmdIPBan = function (user, msg, meta) { var args = msg.split(" "); args.shift(); /* shift off /ipban */ - var name = args.shift(); + if (args.length === 0) { + return user.socket.emit("errorMsg", { + msg: "No ban target specified." + }); + } + var name = args.shift().toLowerCase(); var range = false; if (args[0] === "range") { range = "range";