diff --git a/modules/poll/config.json b/modules/poll/config.json index d3d8ca6..10db064 100644 --- a/modules/poll/config.json +++ b/modules/poll/config.json @@ -1,3 +1,4 @@ { - "help": "http://github.com/reality/depressionbot/blob/master/modules/poll/README.md" + "help": "http://github.com/reality/depressionbot/blob/master/modules/poll/README.md", + "dbKeys": [ "polls" ] } diff --git a/modules/poll/poll.js b/modules/poll/poll.js index 988664f..0ab8cda 100644 --- a/modules/poll/poll.js +++ b/modules/poll/poll.js @@ -1,68 +1,63 @@ +var _ = require('underscore')._; + var poll = function(dbot) { var polls = dbot.db.polls; var commands = { '~newpoll': function(event) { - var av = event.input[1] != undefined; - var name = event.input[2]; - var options = event.input[3].split(','); - var description = event.input[4]; + var name = event.input[1], + options = event.input[2].split(','), + description = event.input[3]; - if(name === undefined || name === 'help') { - event.reply(dbot.t('newpoll_usage')); + if(_.has(polls, name)) { + event.reply(dbot.t('poll_exists', { 'name': name })); } else { - if(polls.hasOwnProperty(name)) { - event.reply(dbot.t('poll_exists', {'name': name})); - } else { - if(av) { - polls[name] = { - 'av': av, - 'name': name, - 'description': description, - 'owner': event.user, - 'votes': {}, - 'options': [] - }; - for(var i=0;i