From 5b0f4d3ae83b81da5c9fd074a75f233ef3fd5b69 Mon Sep 17 00:00:00 2001 From: reality Date: Mon, 6 May 2013 20:00:31 +0000 Subject: [PATCH] finish off poll using new users api [#434] --- modules/poll/commands.js | 47 ++++++++++++++++++++-------------------- 1 file changed, 24 insertions(+), 23 deletions(-) diff --git a/modules/poll/commands.js b/modules/poll/commands.js index b643ebb..fafb62f 100644 --- a/modules/poll/commands.js +++ b/modules/poll/commands.js @@ -70,38 +70,39 @@ var commands = function(dbot) { } } }.bind(this)); - }); + }.bind(this)); }, '~rmoption': function(event) { var name = event.input[1].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]; + option = event.input[2].toLowerCase(); - this.db.save('poll', name, poll, function(err) { - event.reply(dbot.t('option_removed', { - 'user': event.user, - 'name': name, - 'option': option - })); - }.bind(this)); + dbot.api.users.resolveUser(event.server, event.user, function(user) { + this.db.read('poll', name, function(err, poll) { + if(!err) { + if(poll.owner === user.id) { + if(_.has(poll.votes, option)) { + delete poll.votes[option]; + + 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 { - event.reply(dbot.t('invalid_vote', { 'vote': option })); + event.reply(dbot.t('not_poll_owner', { 'name': name })); } } else { - event.reply(dbot.t('not_poll_owner', { 'name': name })); + if(err instanceof NoSuchThingError) { + event.reply(dbot.t('poll_unexistent', { 'name': name })); + } } - } else { - if(err instanceof NoSuchThingError) { - event.reply(dbot.t('poll_unexistent', { 'name': name })); - } - } + }.bind(this)); }.bind(this)); },