~ignore and ~unignore commands working on data storage/modification and listener execution prevention [#331]

This commit is contained in:
reality 2013-04-10 00:32:30 +00:00
parent 228a2611a5
commit 384fe3024a

View File

@ -29,7 +29,7 @@ var ignore = function(dbot) {
if(module == '*' || _.include(ignorableModules, module)) { if(module == '*' || _.include(ignorableModules, module)) {
dbot.api.users.resolveUser(event.server, event.user, function(user) { dbot.api.users.resolveUser(event.server, event.user, function(user) {
this.db.read('ignores', user.id, function(err, ignores) { this.db.read('ignores', user.id, function(err, ignores) {
if(err == NoSuchThingError) { if(ignores == null) {
this.db.create('ignores', user.id, { this.db.create('ignores', user.id, {
'id': user.id, 'id': user.id,
'ignores': [ module ] 'ignores': [ module ]
@ -45,7 +45,7 @@ var ignore = function(dbot) {
} else { } else {
if(!_.include(ignores.ignores, module)) { if(!_.include(ignores.ignores, module)) {
ignores.ignores.push(module); ignores.ignores.push(module);
this.db.save('ignores', user.id, function(err) { this.db.save('ignores', user.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', {
@ -58,8 +58,8 @@ var ignore = function(dbot) {
event.reply(dbot.t('already_ignoring', { 'user': event.user })); event.reply(dbot.t('already_ignoring', { 'user': event.user }));
} }
} }
}); }.bind(this));
}); }.bind(this));
} else { } else {
event.reply(dbot.t('invalid_ignore', { 'user': event.user })); event.reply(dbot.t('invalid_ignore', { 'user': event.user }));
} }
@ -67,41 +67,35 @@ var ignore = function(dbot) {
}, },
'~unignore': function(event) { '~unignore': function(event) {
var ignoredModules = [];
if(_.has(dbot.db.ignores, event.user)) {
ignoredModules = dbot.db.ignores[event.user];
}
var module = event.params[1]; var module = event.params[1];
if(_.isUndefined(module)) { dbot.api.users.resolveUser(event.server, event.user, function(user) {
event.reply(dbot.t('unignore_usage', { this.db.read('ignores', user.id, function(err, ignores) {
'user': event.user, if(!ignores) {
'modules': ignoredModules.join(', ') event.reply(dbot.t('invalid_unignore', { 'user': event.user }));
})); } else if(_.isUndefined(module)) {
} else { event.reply(dbot.t('unignore_usage', {
dbot.api.users.resolveUser(event.server, event.user, function(user) { 'user': event.user,
this.db.read('ignores', user.id, function(err, ignores) { 'modules': ignores.ignores.join(', ')
if(!err) { }));
if(_.include(ignores.ignores, module)) { } else {
ignores.ignores = _.without(ignores.ignores, module); if(_.include(ignores.ignores, module)) {
this.db.save('ignores', user.id, function(err) { ignores.ignores = _.without(ignores.ignores, module);
if(!err) { this.db.save('ignores', user.id, ignores, function(err) {
dbot.instance.removeIgnore(event.user, module) if(!err) {
event.reply(dbot.t('unignored', { dbot.instance.removeIgnore(event.user, module)
'user': event.user, event.reply(dbot.t('unignored', {
'module': module 'user': event.user,
})); 'module': module
} }));
}); }
} else { });
event.reply(dbot.t('invalid_unignore', { 'user': event.user })); } else {
}
} else if(err == NoSuchThingError) {
event.reply(dbot.t('invalid_unignore', { 'user': event.user })); event.reply(dbot.t('invalid_unignore', { 'user': event.user }));
} }
}); }
}); }.bind(this));
} }.bind(this));
}, },
'~ban': function(event) { '~ban': function(event) {