From 7e2b717d0a5fbfc543d7e4fdeb7e39b8d235d01b Mon Sep 17 00:00:00 2001 From: reality Date: Thu, 27 Jun 2013 18:26:54 +0000 Subject: [PATCH] poll uses event.rUser [#511] --- modules/dns/dns.js | 1 + modules/kick/commands.js | 3 - modules/poll/commands.js | 176 +++++++++++++++++++-------------------- 3 files changed, 85 insertions(+), 95 deletions(-) diff --git a/modules/dns/dns.js b/modules/dns/dns.js index e061d83..fbc38cb 100644 --- a/modules/dns/dns.js +++ b/modules/dns/dns.js @@ -16,6 +16,7 @@ var dns = function(dbot) { } }); }, + '~rdns': function(event) { ip = event.params[1]; dnsmod.reverse(ip, function (error, domain) { diff --git a/modules/kick/commands.js b/modules/kick/commands.js index c64aa46..e04c5a2 100644 --- a/modules/kick/commands.js +++ b/modules/kick/commands.js @@ -55,9 +55,6 @@ var commands = function(dbot) { if(this.config.network_name[event.server]) { network = this.config.network_name[event.server]; } - console.log(timeout); - console.log(banee); - console.log(reason); dbot.api.nickserv.getUserHost(event.server, banee, function(host) { // Add host record entry diff --git a/modules/poll/commands.js b/modules/poll/commands.js index fafb62f..455656f 100644 --- a/modules/poll/commands.js +++ b/modules/poll/commands.js @@ -13,63 +13,59 @@ var commands = function(dbot) { _.each(options, function(item, index, list) { list[index] = [ item, 0 ]; }) votes = _.object(options); - dbot.api.users.resolveUser(event.server, event.user, function(user) { - this.db.create('poll', name, { - 'name': name, - 'description': description, - 'owner': user.id, - 'votes': votes, - 'votees': {} - }, function(err, value) { - if(!err) { - event.reply(dbot.t('poll_created', { - 'name': name, - 'description': description, - 'url': dbot.api.web.getUrl('poll/' + name) - })); - } else if(err instanceof AlreadyExistsError) { - event.reply(dbot.t('poll_exists', { 'name': name })); - } - }); - }.bind(this)); + this.db.create('poll', name, { + 'name': name, + 'description': description, + 'owner': event.rUser.id, + 'votes': votes, + 'votees': {} + }, function(err, value) { + if(!err) { + event.reply(dbot.t('poll_created', { + 'name': name, + 'description': description, + 'url': dbot.api.web.getUrl('poll/' + name) + })); + } else if(err instanceof AlreadyExistsError) { + event.reply(dbot.t('poll_exists', { 'name': name })); + } + }); }, '~addoption': function(event) { var name = event.input[1].toLowerCase(), option = event.input[2].toLowerCase(); - 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)) { - poll.votes[option] = 0; - this.db.save('poll', name, poll, function(err) { - event.reply(dbot.t('option_added', { - 'user': event.user, - 'name': name, - 'option': option - })); - }); - } else { - event.reply(dbot.t('option_exists', { - 'option': option, + this.db.read('poll', name, function(err, poll) { + if(!err) { + if(poll.owner === event.rUser.id) { + if(!_.has(poll.votes, option)) { + poll.votes[option] = 0; + this.db.save('poll', name, poll, function(err) { + event.reply(dbot.t('option_added', { + 'user': event.user, 'name': name, - 'user': event.user + 'option': option })); - } + }); } else { - event.reply(dbot.t('not_poll_owner', { - 'user': event.user, - 'name': name + event.reply(dbot.t('option_exists', { + 'option': option, + 'name': name, + 'user': event.user })); } } else { - if(err instanceof NoSuchThingError) { - event.reply(dbot.t('poll_unexistent', { 'name': name })); - } + event.reply(dbot.t('not_poll_owner', { + 'user': event.user, + 'name': name + })); } - }.bind(this)); + } else { + if(err instanceof NoSuchThingError) { + event.reply(dbot.t('poll_unexistent', { 'name': name })); + } + } }.bind(this)); }, @@ -77,32 +73,30 @@ var commands = function(dbot) { var name = event.input[1].toLowerCase(), option = event.input[2].toLowerCase(); - 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.read('poll', name, function(err, poll) { + if(!err) { + if(poll.owner === event.rUser.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 })); - } + 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('not_poll_owner', { 'name': name })); + event.reply(dbot.t('invalid_vote', { 'vote': option })); } } else { - if(err instanceof NoSuchThingError) { - event.reply(dbot.t('poll_unexistent', { 'name': name })); - } + event.reply(dbot.t('not_poll_owner', { 'name': name })); } - }.bind(this)); + } else { + if(err instanceof NoSuchThingError) { + event.reply(dbot.t('poll_unexistent', { 'name': name })); + } + } }.bind(this)); }, @@ -110,37 +104,35 @@ var commands = function(dbot) { var name = event.input[1].toLowerCase(), vote = event.input[2].toLowerCase(); - dbot.api.users.resolveUser(event.server, event.user, function(user) { - this.db.read('poll', name, function(err, poll) { - if(!err) { - if(_.has(poll.votes, vote)) { - if(_.has(poll.votees, user.id)) { - var oldVote = poll.votees[user.id]; - poll.votes[oldVote]--; - poll.votes[vote]++; - poll.votees[user.id] = vote; - } else { - poll.votes[vote]++; - poll.votees[user.id] = vote; - } - - this.db.save('poll', name, poll, function(err) { - event.reply(dbot.t('voted', { - 'vote': vote, - 'poll': name, - 'count': poll.votes[vote], - 'user': event.user - })); - }.bind(this)); + this.db.read('poll', name, function(err, poll) { + if(!err) { + if(_.has(poll.votes, vote)) { + if(_.has(poll.votees, event.rUser.id)) { + var oldVote = poll.votees[event.rUser.id]; + poll.votes[oldVote]--; + poll.votes[vote]++; + poll.votees[event.rUser.id] = vote; } else { - event.reply(dbot.t('invalid_vote', { 'vote': vote })); + poll.votes[vote]++; + poll.votees[event.rUser.id] = vote; } + + this.db.save('poll', name, poll, function(err) { + event.reply(dbot.t('voted', { + 'vote': vote, + 'poll': name, + 'count': poll.votes[vote], + 'user': event.user + })); + }.bind(this)); } else { - if(err instanceof NoSuchThingError) { - event.reply(dbot.t('poll_unexistent', { 'name': name })); - } + event.reply(dbot.t('invalid_vote', { 'vote': vote })); } - }.bind(this)); + } else { + if(err instanceof NoSuchThingError) { + event.reply(dbot.t('poll_unexistent', { 'name': name })); + } + } }.bind(this)); },