mirror of
https://github.com/reality/dbot.git
synced 2025-01-11 20:42:37 +01:00
Added running-orders, not just winners
This commit is contained in:
parent
d192a17d19
commit
e6ac8558ac
@ -150,18 +150,18 @@ var poll = function(dbot) {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
'~winner': function(event) {
|
'~count': function(event) {
|
||||||
var name = event.input[1];
|
var name = event.input[1];
|
||||||
|
|
||||||
if(polls.hasOwnProperty(name)) {
|
if(polls.hasOwnProperty(name)) {
|
||||||
var winner;
|
var order;
|
||||||
if(polls[name].av) {
|
if(polls[name].av) {
|
||||||
var finished = false;
|
var finished = false;
|
||||||
var rounds = [];
|
var rounds = [];
|
||||||
var eliminated = [];
|
var eliminated = [];
|
||||||
var voted;
|
var voted;
|
||||||
|
|
||||||
for(var roundn = 0; !finished; roundn++) {
|
for(var roundn = 0; roundn < polls[name].options.length; roundn++) {
|
||||||
var roundLoser;
|
var roundLoser;
|
||||||
|
|
||||||
// Populate candidates for this round
|
// Populate candidates for this round
|
||||||
@ -182,38 +182,30 @@ var poll = function(dbot) {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Check for 50%
|
// Find the loser
|
||||||
var max = 0;
|
var min = polls[name].votes.length() + 1;
|
||||||
var min = polls[name].votes.length()
|
|
||||||
rounds[roundn].each(function (option, count) {
|
rounds[roundn].each(function (option, count) {
|
||||||
if(count > max) {
|
|
||||||
winner = option;
|
|
||||||
max = count;
|
|
||||||
}
|
|
||||||
|
|
||||||
if(count < min) {
|
if(count < min) {
|
||||||
roundLoser = option;
|
roundLoser = option;
|
||||||
min = count;
|
min = count;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
if((2*max) > polls[name].votes.length()) {
|
|
||||||
finished = true;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Eliminate loser
|
// Eliminate loser
|
||||||
eliminated.push(roundLoser);
|
eliminated.push(roundLoser);
|
||||||
}
|
}
|
||||||
|
order = eliminated.reverse().join(', ')
|
||||||
} else {
|
} else {
|
||||||
var max = 0;
|
var votesArr = [];
|
||||||
polls[name].votes.each(function (name, count) {
|
polls[name].votes.each(function(option, count) {
|
||||||
if(count > max) {
|
votesArr.push([option, count]);
|
||||||
winner = name;
|
|
||||||
max = count;
|
|
||||||
}
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
votesArr = votesArr.sort(function(a, b) { return b[1] - a[1]; });
|
||||||
|
|
||||||
|
order = votesArr.map(function(vote) { return vote[0]; });
|
||||||
}
|
}
|
||||||
event.reply(dbot.t('winner', {'poll': name, 'description': polls[name].description, 'winner': winner}));
|
event.reply(dbot.t('count', {'poll': name, 'description': polls[name].description, 'places': order}));
|
||||||
} else {
|
} else {
|
||||||
event.reply(dbot.t('poll_unexistent', {'name': name}));
|
event.reply(dbot.t('poll_unexistent', {'name': name}));
|
||||||
}
|
}
|
||||||
@ -224,7 +216,7 @@ var poll = function(dbot) {
|
|||||||
commands['~rmoption'].regex = [/~rmoption ([^ ]+) ([^ ]+)/, 3];
|
commands['~rmoption'].regex = [/~rmoption ([^ ]+) ([^ ]+)/, 3];
|
||||||
commands['~vote'].regex = [/~vote ([^ ]+) ([^ ]+)/, 3];
|
commands['~vote'].regex = [/~vote ([^ ]+) ([^ ]+)/, 3];
|
||||||
commands['~pdesc'].regex = [/~pdesc ([^ ]+)/, 2];
|
commands['~pdesc'].regex = [/~pdesc ([^ ]+)/, 2];
|
||||||
commands['~winner'].regex = [/~winner ([^ ]+)/, 2];
|
commands['~count'].regex = [/~count ([^ ]+)/, 2];
|
||||||
|
|
||||||
return {
|
return {
|
||||||
'name': 'poll',
|
'name': 'poll',
|
||||||
|
@ -254,8 +254,8 @@
|
|||||||
"english": "{user} changed their vote in {poll} to '{vote}'.",
|
"english": "{user} changed their vote in {poll} to '{vote}'.",
|
||||||
"spanish" : "{user} cambió su voto en {poll} a '{vote}'."
|
"spanish" : "{user} cambió su voto en {poll} a '{vote}'."
|
||||||
},
|
},
|
||||||
"winner": {
|
"count": {
|
||||||
"english": "The winner of poll '{poll}' ({description}) is: '{winner}'.",
|
"english": "The running-order of poll '{poll}' ({description}) is: {places}.",
|
||||||
"spanish": "La ganera de la votación '{poll}' ({description}) es: '{winner}'."
|
"spanish": ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user