~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,24 +67,21 @@ 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)) {
event.reply(dbot.t('unignore_usage', {
'user': event.user,
'modules': ignoredModules.join(', ')
}));
} else {
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) { if(!ignores) {
event.reply(dbot.t('invalid_unignore', { 'user': event.user }));
} else if(_.isUndefined(module)) {
event.reply(dbot.t('unignore_usage', {
'user': event.user,
'modules': ignores.ignores.join(', ')
}));
} 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, function(err) { this.db.save('ignores', user.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', {
@ -96,12 +93,9 @@ var ignore = function(dbot) {
} else { } else {
event.reply(dbot.t('invalid_unignore', { 'user': event.user })); event.reply(dbot.t('invalid_unignore', { 'user': event.user }));
} }
} else if(err == NoSuchThingError) {
event.reply(dbot.t('invalid_unignore', { 'user': event.user }));
}
});
});
} }
}.bind(this));
}.bind(this));
}, },
'~ban': function(event) { '~ban': function(event) {