From 52d8136e9df9e3a3882da10c08d3837f4fa1048c Mon Sep 17 00:00:00 2001 From: Joe MacMahon Date: Mon, 18 Jun 2012 20:11:54 +0100 Subject: [PATCH] Added voting on AV polls. No counting yet. --- modules/poll.js | 83 +++++++++++++++++++++++++++++++++++-------------- strings.json | 4 +++ 2 files changed, 63 insertions(+), 24 deletions(-) diff --git a/modules/poll.js b/modules/poll.js index cebb735..79ed33d 100644 --- a/modules/poll.js +++ b/modules/poll.js @@ -6,9 +6,10 @@ var poll = function(dbot) { var polls = dbot.db.polls; var commands = { '~newpoll': function(event) { - var name = event.input[1]; - var options = event.input[2].split(','); - var description = event.input[3]; + var av = event.input[1] != undefined; + var name = event.input[2]; + var options = event.input[3].split(','); + var description = event.input[4]; if(name === undefined || name === 'help') { event.reply(dbot.t('newpoll_usage')); @@ -16,13 +17,24 @@ var poll = function(dbot) { if(polls.hasOwnProperty(name)) { event.reply(dbot.t('poll_exists', {'name': name})); } else { - polls[name] = { - 'name': name, - 'description': description, - 'owner': event.user, - 'votes': {}, - 'votees': {} - }; + if(av) { + polls[name] = { + 'av': av, + 'name': name, + 'description': description, + 'owner': event.user, + 'votes': {}, + }; + } else { + polls[name] = { + 'av': av, + 'name': name, + 'description': description, + 'owner': event.user, + 'votes': {}, + 'votees': {} + }; + } for(var i=0;i