Add /kickanons; fix handling of kickban commands with no arguments

This commit is contained in:
Calvin Montgomery 2014-05-22 19:34:46 -07:00
parent d004c0bcdd
commit 3994b42444

View file

@ -15,6 +15,7 @@ function KickBanModule(channel) {
if (this.channel.modules.chat) { if (this.channel.modules.chat) {
this.channel.modules.chat.registerCommand("/kick", this.handleCmdKick.bind(this)); 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("/ban", this.handleCmdBan.bind(this));
this.channel.modules.chat.registerCommand("/ipban", this.handleCmdIPBan.bind(this)); this.channel.modules.chat.registerCommand("/ipban", this.handleCmdIPBan.bind(this));
this.channel.modules.chat.registerCommand("/banip", 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(" "); var args = msg.split(" ");
args.shift(); /* shift off /kick */ 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 name = args.shift().toLowerCase();
var reason = args.join(" "); var reason = args.join(" ");
var target = null; 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 */ /* /ban - name bans */
KickBanModule.prototype.handleCmdBan = function (user, msg, meta) { KickBanModule.prototype.handleCmdBan = function (user, msg, meta) {
var args = msg.split(" "); var args = msg.split(" ");
args.shift(); /* shift off /ban */ 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 reason = args.join(" ");
var chan = this.channel; var chan = this.channel;
@ -189,7 +220,12 @@ KickBanModule.prototype.handleCmdBan = function (user, msg, meta) {
KickBanModule.prototype.handleCmdIPBan = function (user, msg, meta) { KickBanModule.prototype.handleCmdIPBan = function (user, msg, meta) {
var args = msg.split(" "); var args = msg.split(" ");
args.shift(); /* shift off /ipban */ 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; var range = false;
if (args[0] === "range") { if (args[0] === "range") {
range = "range"; range = "range";