forked from GitHub/dbot
Merge branch 'ignoreban' of https://github.com/JohnMaguire2013/depressionbot
This commit is contained in:
commit
c26d0acfc0
@ -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], '*')));
|
||||
},
|
||||
|
||||
/**
|
||||
|
@ -1,5 +1,5 @@
|
||||
{
|
||||
"ignorable": false,
|
||||
"help": "http://github.com/reality/depressionbot/blob/master/modules/command/README.md",
|
||||
"dbKeys": [ "ignores" ]
|
||||
"dbKeys": [ "ignores", "bans" ]
|
||||
}
|
||||
|
@ -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 {
|
||||
@ -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) {
|
||||
var channel = ((event.params[1] == '@') ? event.channel.name : event.params[1]);
|
||||
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);
|
||||
@ -118,6 +178,8 @@ var ignore = function(dbot) {
|
||||
}
|
||||
};
|
||||
|
||||
commands['~ban'].access = 'moderator';
|
||||
commands['~unban'].access = 'moderator';
|
||||
commands['~ignorechannel'].access = 'moderator';
|
||||
commands['~unignorechannel'].access = 'moderator';
|
||||
|
||||
|
@ -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}"
|
||||
|
Loading…
Reference in New Issue
Block a user