This commit is contained in:
reality 2013-03-21 14:45:34 +00:00
commit c26d0acfc0
4 changed files with 92 additions and 6 deletions

View File

@ -4,8 +4,10 @@ var api = function(dbot) {
return { return {
'isBanned': function(user, command) { 'isBanned': function(user, command) {
var banned = false; var banned = false;
if(_.has(dbot.db.bans, command)) { if(_.has(dbot.db.bans, user)) {
if(_.include(dbot.db.bans[command], user) || _.include(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; banned = true;
} }
} }
@ -39,7 +41,8 @@ var api = function(dbot) {
'isIgnoring': function(item, command) { 'isIgnoring': function(item, command) {
var module = dbot.commands[command].module; var module = dbot.commands[command].module;
return (_.has(dbot.db.ignores, item) && return (_.has(dbot.db.ignores, item) &&
_.include(dbot.db.ignores[item], module)); (_.include(dbot.db.ignores[item], module) ||
_.include(dbot.db.ignores[item], '*')));
}, },
/** /**

View File

@ -1,5 +1,5 @@
{ {
"ignorable": false, "ignorable": false,
"help": "http://github.com/reality/depressionbot/blob/master/modules/command/README.md", "help": "http://github.com/reality/depressionbot/blob/master/modules/command/README.md",
"dbKeys": [ "ignores" ] "dbKeys": [ "ignores", "bans" ]
} }

View File

@ -24,7 +24,7 @@ var ignore = function(dbot) {
'modules': ignorableModules.join(', ') 'modules': ignorableModules.join(', ')
})); }));
} else { } else {
if(_.include(ignorableModules, module)) { if(module == '*' || _.include(ignorableModules, module)) {
if(_.has(dbot.db.ignores, event.user) && _.include(dbot.db.ignores[event.user], module)) { if(_.has(dbot.db.ignores, event.user) && _.include(dbot.db.ignores[event.user], module)) {
event.reply(dbot.t('already_ignoring', { 'user': event.user })); event.reply(dbot.t('already_ignoring', { 'user': event.user }));
} else { } else {
@ -72,12 +72,72 @@ 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) { '~ignorechannel': function(event) {
var channel = ((event.params[1] == '@') ? event.channel.name : event.params[1]); var channel = ((event.params[1] == '@') ? event.channel.name : event.params[1]);
var module = event.params[2]; var module = event.params[2];
// Ignoring the value of 'ignorable' at the moment // 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(!_.has(dbot.db.ignores, channel)) dbot.db.ignores[channel] = [];
if(!_.include(dbot.db.ignores[channel], module)) { if(!_.include(dbot.db.ignores[channel], module)) {
dbot.db.ignores[channel].push(module); dbot.db.ignores[channel].push(module);
@ -118,6 +178,8 @@ var ignore = function(dbot) {
} }
}; };
commands['~ban'].access = 'moderator';
commands['~unban'].access = 'moderator';
commands['~ignorechannel'].access = 'moderator'; commands['~ignorechannel'].access = 'moderator';
commands['~unignorechannel'].access = 'moderator'; commands['~unignorechannel'].access = 'moderator';

View File

@ -41,6 +41,27 @@
"na'vi": "{user}: Nga terìng mikyun {module}ne set", "na'vi": "{user}: Nga terìng mikyun {module}ne set",
"cy": "{user}: Ddim yn anwybyddu {module} bellach" "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": { "ignoring_channel": {
"en": "Now ignoring {module} in {channel}", "en": "Now ignoring {module} in {channel}",
"na'vi": "Oe ke stayawm {module}ur mì {channel}" "na'vi": "Oe ke stayawm {module}ur mì {channel}"