diff --git a/modules/command/command.js b/modules/command/command.js index a5f2b33..fd0f494 100644 --- a/modules/command/command.js +++ b/modules/command/command.js @@ -21,8 +21,8 @@ var command = function(dbot) { } this.api.hasAccess(event.server, event.user, commandName, function(hasAccess) { - dbot.api.ignore.isUserIgnoring(event.server, event.user, commandName, function(isIgnoring) { - dbot.api.ignore.isUserBanned(event.server, event.user, commandName, function(isBanned) { + dbot.api.ignore.isUserIgnoring(event.rUser, commandName, function(isIgnoring) { + dbot.api.ignore.isUserBanned(event.rUser, commandName, function(isBanned) { if(isBanned) { if(this.config.banOutput && commandName != '~') { event.reply(dbot.t('command_ban', {'user': event.user})); diff --git a/modules/ignore/api.js b/modules/ignore/api.js index 79b1102..43fa89f 100644 --- a/modules/ignore/api.js +++ b/modules/ignore/api.js @@ -3,18 +3,18 @@ var _ = require('underscore')._; var api = function(dbot) { return { // Is user ignoring command/module? - 'isUserIgnoring': function(server, user, item, callback) { - this.internalAPI.isUserImpeded(server, user, item, 'ignores', callback); + 'isUserIgnoring': function(user, item, callback) { + this.internalAPI.isUserImpeded(user, item, 'ignores', callback); }, // Is user banned from command/module? - 'isUserBanned': function(server, user, item, callback) { - this.internalAPI.isUserImpeded(server, user, item, 'bans', callback); + 'isUserBanned': function(user, item, callback) { + this.internalAPI.isUserImpeded(user, item, 'bans', callback); }, // Is channel ignoring module? // TODO: Command support - 'isChannelIgnoring': function(server, channelName, item, callback) { + 'isChannelIgnoring': function(channelName, item, callback) { var isIgnoring = false, channel = false; @@ -32,16 +32,14 @@ var api = function(dbot) { }, // Resolve a nick and return their user and ignores object - 'getUserIgnores': function(server, user, callback) { - dbot.api.users.resolveUser(server, user, function(user) { - if(user) { - this.db.read('ignores', user.id, function(err, ignores) { - callback(false, user, ignores); - }); + 'getUserIgnores': function(user, callback) { + this.db.read('ignores', user.id, function(err, ignores) { + if(!err && ignores) { + callback(false, ignores); } else { - callback(true, null, null); + callback(true, null); } - }.bind(this)); + }); } }; } diff --git a/modules/ignore/ignore.js b/modules/ignore/ignore.js index 8edd5e8..7f52078 100644 --- a/modules/ignore/ignore.js +++ b/modules/ignore/ignore.js @@ -12,8 +12,8 @@ var _ = require('underscore')._, var ignore = function(dbot) { this.internalAPI = { - 'isUserImpeded': function(server, user, item, by, callback) { - this.api.getUserIgnores(server, user, function(err, user, ignores) { + 'isUserImpeded': function(user, item, by, callback) { + this.api.getUserIgnores(user, function(err, ignores) { var isImpeded = false; if(!err && ignores) { if(_.has(dbot.commands, item)) { @@ -33,7 +33,7 @@ var ignore = function(dbot) { var module = event.params[1]; var ignorableModules = _.chain(dbot.modules) .filter(function(module, name) { - return dbot.config[module].ignorable === true; + return dbot.config.modules[module].ignorable === true; }) .pluck('name') .value(); @@ -45,32 +45,28 @@ var ignore = function(dbot) { })); } else { if(module == '*' || _.include(ignorableModules, module)) { - this.api.getUserIgnores(event.server, event.user, function(err, user, ignores) { - if(!err) { - if(!ignores) { - ignores = { - 'id': user.id, - 'ignores': [], - 'bans': [] - }; - } + this.api.getUserIgnores(event.rUser, function(err, ignores) { + if(!ignores) { + ignores = { + 'id': event.rUser.id, + 'ignores': [], + 'bans': [] + }; + } - if(!_.include(ignores.ignores, module)) { - ignores.ignores.push(module); - this.db.save('ignores', user.id, ignores, function(err) { - if(!err) { - dbot.instance.ignoreTag(event.user, module); - event.reply(dbot.t('ignored', { - 'user': event.user, - 'module': module - })); - } - }); - } else { - event.reply(dbot.t('already_ignoring', { 'user': event.user })); - } + if(!_.include(ignores.ignores, module)) { + ignores.ignores.push(module); + this.db.save('ignores', event.rUser.id, ignores, function(err) { + if(!err) { + dbot.instance.ignoreTag(event.user, module); + event.reply(dbot.t('ignored', { + 'user': event.user, + 'module': module + })); + } + }); } else { - // User doesn't exist + event.reply(dbot.t('already_ignoring', { 'user': event.user })); } }.bind(this)); } else { @@ -82,16 +78,22 @@ var ignore = function(dbot) { '~unignore': function(event) { var module = event.params[1]; - this.api.getUserIgnores(event.server, event.user, function(err, user, ignores) { + this.api.getUserIgnores(event.rUser, function(err, ignores) { if(err || !ignores || _.isUndefined(module)) { - event.reply(dbot.t('unignore_usage', { - 'user': event.user, - 'modules': ignores.ignores.join(', ') - })); + if(ignores) { + event.reply(dbot.t('unignore_usage', { + 'user': event.user, + 'modules': ignores.ignores.join(', ') + })); + } else { + event.reply(dbot.t('empty_unignore_usage', { + 'user': event.user + })); + } } else { if(_.include(ignores.ignores, module)) { ignores.ignores = _.without(ignores.ignores, module); - this.db.save('ignores', user.id, ignores, function(err) { + this.db.save('ignores', event.rUser.id, ignores, function(err) { if(!err) { dbot.instance.removeIgnore(event.user, module) event.reply(dbot.t('unignored', { @@ -112,35 +114,37 @@ var ignore = function(dbot) { item = event.input[2]; if(module == '*' || _.include(dbot.config.moduleNames, item) || _.include(dbot.commands, item)) { - this.api.getUserIgnores(event.server, nick, function(err, user, ignores) { - if(!err) { - if(!ignores) { - ignores = { - 'id': user.id, - 'ignores': [], - 'bans': [] - }; - } + dbot.api.users.resolveUser(event.server, nick, function(user) { + this.api.getUserIgnores(user, function(err, ignores) { + if(!err) { + if(!ignores) { + ignores = { + 'id': user.id, + 'ignores': [], + 'bans': [] + }; + } - if(!_.include(ignores.bans, item)) { - ignores.bans.push(item); - this.db.save('ignores', user.id, ignores, function(err) { - if(!err) { - event.reply(dbot.t('banned_success', { - 'user': event.user, - 'banned': nick, - 'module': item - })); - } - }); - } else { - event.reply(dbot.t('already_banned', { - 'user': event.user, - 'banned': nick - })); + if(!_.include(ignores.bans, item)) { + ignores.bans.push(item); + this.db.save('ignores', user.id, ignores, function(err) { + if(!err) { + event.reply(dbot.t('banned_success', { + 'user': event.user, + 'banned': nick, + 'module': item + })); + } + }); + } else { + event.reply(dbot.t('already_banned', { + 'user': event.user, + 'banned': nick + })); + } } - } - }.bind(this)); + }.bind(this)); + }); } else { event.reply(dbot.t('invalid_ban', { 'user': event.user })); } @@ -150,29 +154,31 @@ var ignore = function(dbot) { var nick = event.input[1], item = event.input[2]; - this.api.getUserIgnores(event.server, nick, function(err, user, ignores) { - if(err || !ignores) { - event.reply(dbot.t('invalid_unban', { - 'user': event.user, - 'banned': nick - })); - } else { - if(_.include(ignores.bans, item)) { - ignores.bans = _.without(ignores.bans, item); - this.db.save('ignores', user.id, ignores, function(err) { - event.reply(dbot.t('unbanned_success', { - 'user': event.user, - 'banned': nick, - 'module': item - })); - }); - } else { + dbot.api.users.resolveUser(event.server, nick, function(user) { + this.api.getUserIgnores(user, function(err, ignores) { + if(err || !ignores) { event.reply(dbot.t('invalid_unban', { 'user': event.user, - 'banned': nick + 'banned': nick })); + } else { + if(_.include(ignores.bans, item)) { + ignores.bans = _.without(ignores.bans, item); + this.db.save('ignores', user.id, ignores, function(err) { + event.reply(dbot.t('unbanned_success', { + 'user': event.user, + 'banned': nick, + 'module': item + })); + }); + } else { + event.reply(dbot.t('invalid_unban', { + 'user': event.user, + 'banned': nick + })); + } } - } + }.bind(this)); }.bind(this)); }, diff --git a/modules/ignore/strings.json b/modules/ignore/strings.json index abcdd07..a5763e6 100644 --- a/modules/ignore/strings.json +++ b/modules/ignore/strings.json @@ -39,6 +39,14 @@ "nl": "{user}: Gebruik: ~unignore [module]. Modules die momenteel worden genegeerd: {modules}.", "de": "{user}: Benutzung: ~unignore [module]. Module, die im Moment ignoriert werden: {modules}." }, + "empty_unignore_usage": { + "en": "{user}: Usage: ~unignore [module].", + "es": "{user}: Modo de empleo: ~unignore [módulo].", + "na'vi": "{user}: Sar: ~unignore ['u].", + "cy": "{user}: Defnydd: ~unignore [modiwl].", + "nl": "{user}: Gebruik: ~unignore [module].", + "de": "{user}: Benutzung: ~unignore [module]." + }, "invalid_unignore": { "en": "{user}: You're not ignoring that module or it doesn't exist.", "es": "{user}: No ignoras este módulo o no existe.", @@ -57,7 +65,7 @@ }, "ban_usage": { "en": "{user}: Usage: ~ban [user] [module/command]. Use * for all modules and commands.", - "cy": "{user}: Defnydd: ~ban [defnyddiwr] [modiwl/gorchymyn]. Defnyddio * am pob modiwlau a gorchmynion." + "cy": "{user}: Defnydd: ~ban [defnyddiwr] [modiwl/gorchymyn]. Defnyddio * am pob modiwlau a gorchmynion.", "nl": "{user}: Gebruik: ~ban [gebruiker] [module/commando]. Gebruik * voor alle modules en alle commandos.", "de": "{user}: Benutzung ~ban [Benutzer] [module/Befehl]. Benutze * für alle Module und Befehle." },