From e90572aebf7bc7250fc43fccc23faba7dd306fc2 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Thu, 21 Mar 2013 06:34:33 -0400 Subject: [PATCH 1/3] adding initial support for wildcard ignores/bans --- modules/command/api.js | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/modules/command/api.js b/modules/command/api.js index 51202e9..dd19b9e 100644 --- a/modules/command/api.js +++ b/modules/command/api.js @@ -4,8 +4,10 @@ var api = function(dbot) { return { 'isBanned': function(user, command) { var banned = false; - if(_.has(dbot.db.bans, command)) { - if(_.include(dbot.db.bans[command], user) || _.include(dbot.db.bans['*'], user)) { + if(_.has(dbot.db.bans, user)) { + if(_.include(dbot.db.bans[user], command) || + _.include(dbot.db.bans[user], dbot.commands[command].module) || + _.include(dbot.db.bans[user], '*')) { banned = true; } } @@ -39,7 +41,8 @@ var api = function(dbot) { 'isIgnoring': function(item, command) { var module = dbot.commands[command].module; return (_.has(dbot.db.ignores, item) && - _.include(dbot.db.ignores[item], module)); + (_.include(dbot.db.ignores[item], module) || + _.include(dbot.db.ignores[item], '*'))); }, /** From af3a8bf1f27419be4c9dc8220252ec63266f4ea1 Mon Sep 17 00:00:00 2001 From: John Maguire Date: Thu, 21 Mar 2013 06:39:57 -0400 Subject: [PATCH 2/3] adding support for ban/unban from ignore module, with wildcards --- modules/command/config.json | 2 +- modules/ignore/ignore.js | 62 +++++++++++++++++++++++++++++++++++++ modules/ignore/strings.json | 21 +++++++++++++ 3 files changed, 84 insertions(+), 1 deletion(-) diff --git a/modules/command/config.json b/modules/command/config.json index f7de9b5..bace93b 100644 --- a/modules/command/config.json +++ b/modules/command/config.json @@ -1,5 +1,5 @@ { "ignorable": false, "help": "http://github.com/reality/depressionbot/blob/master/modules/command/README.md", - "dbKeys": [ "ignores" ] + "dbKeys": [ "ignores", "bans" ] } diff --git a/modules/ignore/ignore.js b/modules/ignore/ignore.js index 9fa9eac..6e8590c 100644 --- a/modules/ignore/ignore.js +++ b/modules/ignore/ignore.js @@ -72,6 +72,66 @@ var ignore = function(dbot) { } }, + '~ban': function(event) { + var user = event.params[1]; + var module = event.params[2]; + + if(_.isUndefined(user) || _.isUndefined(module)) { + event.reply(dbot.t('ban_usage', {'user': event.user})); + return; + } + + if(module == '*' || _.include(dbot.config.moduleNames, module) || _.include(dbot.commands, module)) { + if(_.has(dbot.db.bans, user) && _.include(dbot.db.bans[user], module)) { + event.reply(dbot.t('already_banned', { + 'user': event.user, + 'banned': user + })); + return; + } + + if(_.has(dbot.db.bans, event.params[1])) { + dbot.db.bans[event.params[1]].push(module); + } else { + dbot.db.bans[event.params[1]] = [module]; + } + + event.reply(dbot.t('banned_success', { + 'user': event.user, + 'banned': user, + 'module': module + })); + } else { + event.reply(dbot.t('invalid_ban', {'user': event.user})); + } + }, + + '~unban': function(event) { + var bannedModules = []; + + var user = event.params[1]; + var module = event.params[2]; + + if(_.isUndefined(user) || _.isUndefined(module)) { + event.reply(dbot.t('unban_usage', {'user': event.user})); + } else { + if(_.has(dbot.db.bans, user) && _.include(dbot.db.bans[user], module)) { + dbot.db.bans[user].splice(dbot.db.bans[user].indexOf(module), 1); + + event.reply(dbot.t('unbanned_success', { + 'user': event.user, + 'banned': user, + 'module': module + })); + } else { + event.reply(dbot.t('invalid_unban', { + 'user': event.user, + 'banned': user + })); + } + } + }, + '~ignorechannel': function(event) { var channel = ((event.params[1] == '@') ? event.channel.name : event.params[1]); var module = event.params[2]; @@ -118,6 +178,8 @@ var ignore = function(dbot) { } }; + commands['~ban'].access = 'moderator'; + commands['~unban'].access = 'moderator'; commands['~ignorechannel'].access = 'moderator'; commands['~unignorechannel'].access = 'moderator'; diff --git a/modules/ignore/strings.json b/modules/ignore/strings.json index 8202cb0..0badd2a 100644 --- a/modules/ignore/strings.json +++ b/modules/ignore/strings.json @@ -41,6 +41,27 @@ "na'vi": "{user}: Nga terìng mikyun {module}ne set", "cy": "{user}: Ddim yn anwybyddu {module} bellach" }, + "ban_usage": { + "en": "{user}: Usage: ~ban [user] [module/command]. Use * for all modules and commands." + }, + "already_banned": { + "en": "{user}: {banned} is already banned from that module." + }, + "banned_success": { + "en": "{user}: {banned} is now banned from {module}." + }, + "invalid_ban": { + "en": "{user}: That isn't a valid module name." + }, + "unban_usage": { + "en": "{user}: Usage: ~unban [user] [module]." + }, + "invalid_unban": { + "en": "{user}: {banned} is not banned from that module or it doesn't exist." + }, + "unbanned_success": { + "en": "{user}: {banned} is no longer banned from {module}." + }, "ignoring_channel": { "en": "Now ignoring {module} in {channel}", "na'vi": "Oe ke stayawm {module}ur mì {channel}" From 42361e0c0c605a97fcd0e5b4a43e12eab6c1befc Mon Sep 17 00:00:00 2001 From: John Maguire Date: Thu, 21 Mar 2013 06:40:54 -0400 Subject: [PATCH 3/3] adding support for wildcard ~ignore and ~unignore --- modules/ignore/ignore.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/modules/ignore/ignore.js b/modules/ignore/ignore.js index 6e8590c..3e3d974 100644 --- a/modules/ignore/ignore.js +++ b/modules/ignore/ignore.js @@ -24,7 +24,7 @@ var ignore = function(dbot) { 'modules': ignorableModules.join(', ') })); } else { - if(_.include(ignorableModules, module)) { + if(module == '*' || _.include(ignorableModules, module)) { if(_.has(dbot.db.ignores, event.user) && _.include(dbot.db.ignores[event.user], module)) { event.reply(dbot.t('already_ignoring', { 'user': event.user })); } else { @@ -137,7 +137,7 @@ var ignore = function(dbot) { var module = event.params[2]; // Ignoring the value of 'ignorable' at the moment - if(_.include(dbot.config.moduleNames, module)) { + if(module == '*' || _.include(dbot.config.moduleNames, module)) { if(!_.has(dbot.db.ignores, channel)) dbot.db.ignores[channel] = []; if(!_.include(dbot.db.ignores[channel], module)) { dbot.db.ignores[channel].push(module);