From 6b8b617e71af4c07a9084d28136d000181ebbc58 Mon Sep 17 00:00:00 2001 From: reality Date: Sat, 12 Jan 2013 23:31:53 +0000 Subject: [PATCH] Underscorise poll. Unfortunately some stuff went missing in the switch-over. Whoops. Oh I also fixed it. [#81] --- modules/poll/config.json | 3 +- modules/poll/poll.js | 287 ++++++++++++++++++--------------------- 2 files changed, 132 insertions(+), 158 deletions(-) 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