Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function vote(sender, voteText) {
- var optionIndex;
- if (!poll.pollRunning) {
- return;
- }
- if (hasKey(poll.voters, sender.toLowerCase())) {
- $.say($.whisperPrefix(sender) + $.lang.get('pollsystem.vote.already'));
- return;
- }
- voteOptions = voteText.split(',');
- if (voteOptions.length > 3) {
- $.say($.whisperPrefix(sender) + 'You can only vote on up to three items.');
- return;
- }
- // First validate that the user voted properly.
- for (voteOption in voteOptions) {
- optionIndex = parseInt(voteOptions[voteOption]);
- if (isNaN(optionIndex) || optionIndex < 1 || optionIndex > poll.options.length) {
- $.say($.whisperPrefix(sender) + $.lang.get('pollsystem.vote.invalid', voteText));
- return;
- }
- }
- // Now, apply the votes. Assume first vote gets 3 points, second 2, last 1.
- votePoints = 3;
- poll.voters.push(sender);
- for (voteOption in voteOptions) {
- optionIndex = parseInt(voteOptions[voteOption]);
- optionIndex--;
- for (var i = 0; i < votePoints; i++) {
- poll.votes.push(optionIndex);
- $.inidb.incr('pollVotes', poll.options[optionIndex].replace(/\s/, '%space_option%'), 1);
- }
- votePoints--;
- }
- };
- /* This could use more error checking, but for now it works: */
- poll open "color" "red, blue, green"
- [11-15-2018 @ 17:50:30.803 MST] [MUTED] The Bot IllusionaryBot started a poll (minimum votes: 1): color! Use "!vote [option]" to vote. Options: 1) red 2) blue 3) green
- [11-15-2018 @ 17:50:30.805 MST] [MUTED] @IllusionaryBot, Poll started! Use "!poll close" to end the poll manually
- vote 2,1,3
- poll close
- [11-15-2018 @ 17:50:42.671 MST] [MUTED] The poll on "color" has ended! The winner is "blue"!
- poll open "color" "red, blue, green"
- [11-15-2018 @ 17:50:50.609 MST] [MUTED] The Bot IllusionaryBot started a poll (minimum votes: 1): color! Use "!vote [option]" to vote. Options: 1) red 2) blue 3) green
- [11-15-2018 @ 17:50:50.612 MST] [MUTED] @IllusionaryBot, Poll started! Use "!poll close" to end the poll manually
- vote 1,2,3
- poll close
- [11-15-2018 @ 17:50:57.834 MST] [MUTED] The poll on "color" has ended! The winner is "red"!
- As you can see the item that I first voted for wins. It has the most points.
Advertisement
Add Comment
Please, Sign In to add comment