From f04621a5e9377f78e79352c9d56f86ad0bd41e61 Mon Sep 17 00:00:00 2001 From: reality Date: Sun, 20 Jan 2013 19:12:34 +0000 Subject: [PATCH] poll uses knownUsers [#158] --- modules/poll/commands.js | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/modules/poll/commands.js b/modules/poll/commands.js index 796b32b..bcd8530 100644 --- a/modules/poll/commands.js +++ b/modules/poll/commands.js @@ -14,7 +14,7 @@ var commands = function(dbot) { polls[name] = { 'name': name, 'description': description, - 'owner': event.user, + 'owner': dbot.api.users.resolveUser(event.server, event.user), 'votes': {}, 'votees': {} }; @@ -35,10 +35,11 @@ var commands = function(dbot) { '~addoption': function(event) { 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); if(_.has(polls, name)) { - if(polls[name].owner === event.user) { + if(polls[name].owner === user) { if(!_.has(polls[name].votes, option)) { polls[name]['votes'][option] = 0; event.reply(dbot.t('option_added', { @@ -66,10 +67,11 @@ var commands = function(dbot) { '~rmoption': function(event) { 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); if(_.has(polls, name)) { - if(polls[name].owner === event.user) { + if(polls[name].owner === user) { if(_.has(polls[name].votes, option)) { delete polls[name]['votes'][option]; event.reply(dbot.t('option_removed', { @@ -90,15 +92,16 @@ var commands = function(dbot) { '~vote': function(event) { var name = event.input[1].toLowerCase(), - vote = event.input[2].toLowerCase(); + vote = event.input[2].toLowerCase(), + user = dbot.api.users.resolveUser(event.server, event.user); if(_.has(polls, name)) { if(_.has(polls[name].votes, vote)) { - if(_.has(polls[name].votees, event.user)) { + if(_.has(polls[name].votees, user)) { var oldVote = polls[name].votees[event.user]; polls[name].votes[oldVote]--; polls[name].votes[vote]++; - polls[name].votees[event.user] = vote; + polls[name].votees[user] = vote; event.reply(dbot.t('changed_vote', { 'vote': vote, @@ -108,7 +111,7 @@ var commands = function(dbot) { })); } else { polls[name].votes[vote]++; - polls[name].votees[event.user] = vote; + polls[name].votees[user] = vote; event.reply(dbot.t('voted', { 'vote': vote, 'poll': name,