ignore uses event.rUser [#511][#514]

This commit is contained in:
reality 2013-06-27 15:33:18 +00:00
parent 3021601c52
commit 68b0977bae
4 changed files with 107 additions and 95 deletions

View File

@ -21,8 +21,8 @@ var command = function(dbot) {
} }
this.api.hasAccess(event.server, event.user, commandName, function(hasAccess) { this.api.hasAccess(event.server, event.user, commandName, function(hasAccess) {
dbot.api.ignore.isUserIgnoring(event.server, event.user, commandName, function(isIgnoring) { dbot.api.ignore.isUserIgnoring(event.rUser, commandName, function(isIgnoring) {
dbot.api.ignore.isUserBanned(event.server, event.user, commandName, function(isBanned) { dbot.api.ignore.isUserBanned(event.rUser, commandName, function(isBanned) {
if(isBanned) { if(isBanned) {
if(this.config.banOutput && commandName != '~') { if(this.config.banOutput && commandName != '~') {
event.reply(dbot.t('command_ban', {'user': event.user})); event.reply(dbot.t('command_ban', {'user': event.user}));

View File

@ -3,18 +3,18 @@ var _ = require('underscore')._;
var api = function(dbot) { var api = function(dbot) {
return { return {
// Is user ignoring command/module? // Is user ignoring command/module?
'isUserIgnoring': function(server, user, item, callback) { 'isUserIgnoring': function(user, item, callback) {
this.internalAPI.isUserImpeded(server, user, item, 'ignores', callback); this.internalAPI.isUserImpeded(user, item, 'ignores', callback);
}, },
// Is user banned from command/module? // Is user banned from command/module?
'isUserBanned': function(server, user, item, callback) { 'isUserBanned': function(user, item, callback) {
this.internalAPI.isUserImpeded(server, user, item, 'bans', callback); this.internalAPI.isUserImpeded(user, item, 'bans', callback);
}, },
// Is channel ignoring module? // Is channel ignoring module?
// TODO: Command support // TODO: Command support
'isChannelIgnoring': function(server, channelName, item, callback) { 'isChannelIgnoring': function(channelName, item, callback) {
var isIgnoring = false, var isIgnoring = false,
channel = false; channel = false;
@ -32,16 +32,14 @@ var api = function(dbot) {
}, },
// Resolve a nick and return their user and ignores object // Resolve a nick and return their user and ignores object
'getUserIgnores': function(server, user, callback) { 'getUserIgnores': function(user, callback) {
dbot.api.users.resolveUser(server, user, function(user) {
if(user) {
this.db.read('ignores', user.id, function(err, ignores) { this.db.read('ignores', user.id, function(err, ignores) {
callback(false, user, ignores); if(!err && ignores) {
}); callback(false, ignores);
} else { } else {
callback(true, null, null); callback(true, null);
} }
}.bind(this)); });
} }
}; };
} }

View File

@ -12,8 +12,8 @@ var _ = require('underscore')._,
var ignore = function(dbot) { var ignore = function(dbot) {
this.internalAPI = { this.internalAPI = {
'isUserImpeded': function(server, user, item, by, callback) { 'isUserImpeded': function(user, item, by, callback) {
this.api.getUserIgnores(server, user, function(err, user, ignores) { this.api.getUserIgnores(user, function(err, ignores) {
var isImpeded = false; var isImpeded = false;
if(!err && ignores) { if(!err && ignores) {
if(_.has(dbot.commands, item)) { if(_.has(dbot.commands, item)) {
@ -33,7 +33,7 @@ var ignore = function(dbot) {
var module = event.params[1]; var module = event.params[1];
var ignorableModules = _.chain(dbot.modules) var ignorableModules = _.chain(dbot.modules)
.filter(function(module, name) { .filter(function(module, name) {
return dbot.config[module].ignorable === true; return dbot.config.modules[module].ignorable === true;
}) })
.pluck('name') .pluck('name')
.value(); .value();
@ -45,11 +45,10 @@ var ignore = function(dbot) {
})); }));
} else { } else {
if(module == '*' || _.include(ignorableModules, module)) { if(module == '*' || _.include(ignorableModules, module)) {
this.api.getUserIgnores(event.server, event.user, function(err, user, ignores) { this.api.getUserIgnores(event.rUser, function(err, ignores) {
if(!err) {
if(!ignores) { if(!ignores) {
ignores = { ignores = {
'id': user.id, 'id': event.rUser.id,
'ignores': [], 'ignores': [],
'bans': [] 'bans': []
}; };
@ -57,7 +56,7 @@ var ignore = function(dbot) {
if(!_.include(ignores.ignores, module)) { if(!_.include(ignores.ignores, module)) {
ignores.ignores.push(module); ignores.ignores.push(module);
this.db.save('ignores', user.id, ignores, function(err) { this.db.save('ignores', event.rUser.id, ignores, function(err) {
if(!err) { if(!err) {
dbot.instance.ignoreTag(event.user, module); dbot.instance.ignoreTag(event.user, module);
event.reply(dbot.t('ignored', { event.reply(dbot.t('ignored', {
@ -69,9 +68,6 @@ var ignore = function(dbot) {
} else { } else {
event.reply(dbot.t('already_ignoring', { 'user': event.user })); event.reply(dbot.t('already_ignoring', { 'user': event.user }));
} }
} else {
// User doesn't exist
}
}.bind(this)); }.bind(this));
} else { } else {
event.reply(dbot.t('invalid_ignore', { 'user': event.user })); event.reply(dbot.t('invalid_ignore', { 'user': event.user }));
@ -82,16 +78,22 @@ var ignore = function(dbot) {
'~unignore': function(event) { '~unignore': function(event) {
var module = event.params[1]; 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)) { if(err || !ignores || _.isUndefined(module)) {
if(ignores) {
event.reply(dbot.t('unignore_usage', { event.reply(dbot.t('unignore_usage', {
'user': event.user, 'user': event.user,
'modules': ignores.ignores.join(', ') 'modules': ignores.ignores.join(', ')
})); }));
} else {
event.reply(dbot.t('empty_unignore_usage', {
'user': event.user
}));
}
} else { } else {
if(_.include(ignores.ignores, module)) { if(_.include(ignores.ignores, module)) {
ignores.ignores = _.without(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) { if(!err) {
dbot.instance.removeIgnore(event.user, module) dbot.instance.removeIgnore(event.user, module)
event.reply(dbot.t('unignored', { event.reply(dbot.t('unignored', {
@ -112,7 +114,8 @@ var ignore = function(dbot) {
item = event.input[2]; item = event.input[2];
if(module == '*' || _.include(dbot.config.moduleNames, item) || _.include(dbot.commands, item)) { if(module == '*' || _.include(dbot.config.moduleNames, item) || _.include(dbot.commands, item)) {
this.api.getUserIgnores(event.server, nick, function(err, user, ignores) { dbot.api.users.resolveUser(event.server, nick, function(user) {
this.api.getUserIgnores(user, function(err, ignores) {
if(!err) { if(!err) {
if(!ignores) { if(!ignores) {
ignores = { ignores = {
@ -141,6 +144,7 @@ var ignore = function(dbot) {
} }
} }
}.bind(this)); }.bind(this));
});
} else { } else {
event.reply(dbot.t('invalid_ban', { 'user': event.user })); event.reply(dbot.t('invalid_ban', { 'user': event.user }));
} }
@ -150,7 +154,8 @@ var ignore = function(dbot) {
var nick = event.input[1], var nick = event.input[1],
item = event.input[2]; item = event.input[2];
this.api.getUserIgnores(event.server, nick, function(err, user, ignores) { dbot.api.users.resolveUser(event.server, nick, function(user) {
this.api.getUserIgnores(user, function(err, ignores) {
if(err || !ignores) { if(err || !ignores) {
event.reply(dbot.t('invalid_unban', { event.reply(dbot.t('invalid_unban', {
'user': event.user, 'user': event.user,
@ -174,6 +179,7 @@ var ignore = function(dbot) {
} }
} }
}.bind(this)); }.bind(this));
}.bind(this));
}, },
'~ignorechannel': function(event) { '~ignorechannel': function(event) {

View File

@ -39,6 +39,14 @@
"nl": "{user}: Gebruik: ~unignore [module]. Modules die momenteel worden genegeerd: {modules}.", "nl": "{user}: Gebruik: ~unignore [module]. Modules die momenteel worden genegeerd: {modules}.",
"de": "{user}: Benutzung: ~unignore [module]. Module, die im Moment ignoriert werden: {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": { "invalid_unignore": {
"en": "{user}: You're not ignoring that module or it doesn't exist.", "en": "{user}: You're not ignoring that module or it doesn't exist.",
"es": "{user}: No ignoras este módulo o no existe.", "es": "{user}: No ignoras este módulo o no existe.",
@ -57,7 +65,7 @@
}, },
"ban_usage": { "ban_usage": {
"en": "{user}: Usage: ~ban [user] [module/command]. Use * for all modules and commands.", "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.", "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." "de": "{user}: Benutzung ~ban [Benutzer] [module/Befehl]. Benutze * für alle Module und Befehle."
}, },