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) { dbot.api.users.resolveUser(event.server, event.user, function(user) {
if(!err) { this.db.read('poll', name, function(err, poll) {
if(poll.owner === user) { if(!err) {
if(_.has(poll.votes, option)) { if(poll.owner === user.id) {
delete poll.votes[option]; if(_.has(poll.votes, option)) {
delete poll.votes[option];
this.db.save('poll', name, poll, function(err) { this.db.save('poll', name, poll, function(err) {
event.reply(dbot.t('option_removed', { event.reply(dbot.t('option_removed', {
'user': event.user, 'user': event.user,
'name': name, 'name': name,
'option': option 'option': option
})); }));
}.bind(this)); }.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));
}, },