finish off poll using new users api [#434]

This commit is contained in:
reality 2013-05-06 20:00:31 +00:00
parent 75a909df64
commit 5b0f4d3ae8

View File

@ -70,38 +70,39 @@ var commands = function(dbot) {
} }
} }
}.bind(this)); }.bind(this));
}); }.bind(this));
}, },
'~rmoption': function(event) { '~rmoption': function(event) {
var name = event.input[1].toLowerCase(), var name = event.input[1].toLowerCase(),
option = event.input[2].toLowerCase(), option = event.input[2].toLowerCase();
user = dbot.api.users.resolveUser(event.server, event.user);
this.db.read('poll', name, function(err, poll) {
if(!err) {
if(poll.owner === user) {
if(_.has(poll.votes, option)) {
delete poll.votes[option];
this.db.save('poll', name, poll, function(err) { dbot.api.users.resolveUser(event.server, event.user, function(user) {
event.reply(dbot.t('option_removed', { this.db.read('poll', name, function(err, poll) {
'user': event.user, if(!err) {
'name': name, if(poll.owner === user.id) {
'option': option if(_.has(poll.votes, option)) {
})); delete poll.votes[option];
}.bind(this));
this.db.save('poll', name, poll, function(err) {
event.reply(dbot.t('option_removed', {
'user': event.user,
'name': name,
'option': option
}));
}.bind(this));
} else {
event.reply(dbot.t('invalid_vote', { 'vote': option }));
}
} else { } else {
event.reply(dbot.t('invalid_vote', { 'vote': option })); event.reply(dbot.t('not_poll_owner', { 'name': name }));
} }
} else { } else {
event.reply(dbot.t('not_poll_owner', { 'name': name })); if(err instanceof NoSuchThingError) {
event.reply(dbot.t('poll_unexistent', { 'name': name }));
}
} }
} else { }.bind(this));
if(err instanceof NoSuchThingError) {
event.reply(dbot.t('poll_unexistent', { 'name': name }));
}
}
}.bind(this)); }.bind(this));
}, },