3
0
mirror of https://github.com/reality/dbot.git synced 2024-12-28 21:52:38 +01:00

finish off poll using new users api [#434]

This commit is contained in:
reality 2013-05-06 20:00:31 +00:00
parent 75a909df64
commit 5b0f4d3ae8

View File

@ -70,38 +70,39 @@ var commands = function(dbot) {
}
}
}.bind(this));
});
}.bind(this));
},
'~rmoption': function(event) {
var name = event.input[1].toLowerCase(),
option = event.input[2].toLowerCase(),
user = dbot.api.users.resolveUser(event.server, event.user);
this.db.read('poll', name, function(err, poll) {
if(!err) {
if(poll.owner === user) {
if(_.has(poll.votes, option)) {
delete poll.votes[option];
option = event.input[2].toLowerCase();
this.db.save('poll', name, poll, function(err) {
event.reply(dbot.t('option_removed', {
'user': event.user,
'name': name,
'option': option
}));
}.bind(this));
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.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 }));
}
} else {
event.reply(dbot.t('invalid_vote', { 'vote': option }));
event.reply(dbot.t('not_poll_owner', { 'name': name }));
}
} else {
event.reply(dbot.t('not_poll_owner', { 'name': name }));
if(err instanceof NoSuchThingError) {
event.reply(dbot.t('poll_unexistent', { 'name': name }));
}
}
} else {
if(err instanceof NoSuchThingError) {
event.reply(dbot.t('poll_unexistent', { 'name': name }));
}
}
}.bind(this));
}.bind(this));
},