Bots Home
|
Create an App
FREE VOTE BOT
Author:
everlast_69
Description
Source Code
Launch Bot
Current Users
Created by:
Everlast_69
/* * Title: FREE POLL * Author: Naturist_be * Version: 1.0 (23/07/13) * Summary: FREE Hangman! Everyone can play! * * Description: Options: - Set the number of votes limit - Set at least 2 choices (maximum of 5) - Users can vote only once List of commands: Users only type the number of the choice they want !stat = display choices and stats Have fun! Naturist_be * */ var total_voted = 0, finished = false, voters = [], ADVERT_TIME = 5; cb.settings_choices = [{ name: 'advert_time', type: 'int', minValue: 1, label: "Number of minutes to display choices", maxValue: 99999, default: 3 }, { name: 'max_votes', type: 'int', minValue: 1, label: "Maximum Number of votes", maxValue: 99999, default: 50 }, { name: 'choice1', type: 'str', label: "Choice 1", maxLength: 200 }, { name: 'choice2', type: 'str', label: "Choice 2", maxLength: 200 }, { name: 'choice3', type: 'str', label: "Choice 3", maxLength: 200, required: false }, { name: 'choice4', type: 'str', label: "Choice 4", maxLength: 200, required: false }, { name: 'choice5', type: 'str', label: "Choice 5", maxLength: 200, required: false } ]; cb.onMessage(function(msg) { if (msg['m'] == '!stat') { msg['X-Spam'] = true; vote_tracker.send_stats(msg['user']); } if (msg['m'].length == 1 && testvoter(msg['user']) == 1) { for (var i = 0; i < all_choices().length; i++) { if (all_choices()[i].charAt(0) == msg['m']) { vote_tracker.track_vote(0, all_choices()[i]); voters.push({ user: msg['user'] }); total_voted++; } } drawPanel(); update_subject(); } return msg; }); /* cb.onDrawPanel(function (user) { var bestchoice_display = '\u2605 start voting! \u2605'; var nbchoice = 0; if (vote_tracker.bestchoice) { nbchoice = vote_tracker.bestchoice.nb_voted; bestchoice_display = vote_tracker.bestchoice.choice+ ' (' + nbchoice + ')'; } if (!finished) return { 'template':'3_rows_11_21_31', 'row1_value':'WELCOME TO FREE POLL!', 'row2_value': 'Top choice: ' + bestchoice_display, 'row3_value': 'Votes remaining: ' + total_voted + "/" + cb.settings.max_votes }; else return { 'template':'3_rows_11_21_31', 'row1_value':'FREE POLL - by Naturist_be', 'row2_value': 'Elected: ' + bestchoice_display, 'row3_value':'Thanks all for your vote!!' }; }); */ function drawPanel() { cb.debug('drawpanel'); var nbchoice = 0; var bestchoice_display = ""; if (vote_tracker.bestchoice) { nbchoice = vote_tracker.bestchoice.nb_voted; bestchoice_display = vote_tracker.bestchoice.choice + ' (' + nbchoice + ')'; } if (!finished) { cb.log('!finished'); cb.sendNotice( 'WELCOME TO FREE POLL!\n' + 'Top choice: ' + bestchoice_display + '\n' + 'Votes remaining: ' + total_voted + "/" + cb.settings.max_votes, "" , "#666699", "#FFFFFF", "bold" ); } else { cb.log('else'); cb.sendNotice( 'FREE POLL - by Naturist_be\n' + 'Elected: ' + bestchoice_display + '\n' + 'Thanks all for your vote!!' ); } } var _all_choices_cache = null; function all_choices() { if (_all_choices_cache) { return _all_choices_cache; } var choices = []; for (var i = 0; i < 5; i++) { var name = 'choice' + i; if (cb.settings[name]) { choices.push(i + ' - ' + cb.settings[name]); } } _all_choices_cache = choices; return choices; } var vote_tracker = { _data: [], bestchoice: null, init: function() { for (var i = 0; i < all_choices().length; i++) { vote_tracker.track_vote(0, all_choices()[i]); ADVERT_TIME = cb.settings['advert_time']; } }, track_vote: function(voteamount, choice) { var found = false; for (var i = 0; i < vote_tracker._data.length; i++) { if (vote_tracker._data[i].choice == choice) { vote_tracker._data[i].nb_voted += 1; found = true; } } if (!found) { vote_tracker._data.push({ choice: choice, nb_voted: 0, }); } vote_tracker._update_bestchoice(); }, _update_bestchoice: function() { if (vote_tracker._data.length == 0) { return; } vote_tracker._data.sort(function(a, b) { return b.nb_voted - a.nb_voted }); if (vote_tracker._data[0].nb_voted > 0) { vote_tracker.bestchoice = vote_tracker._data[0]; } }, send_stats: function(user) { var msg = ""; var suser = ''; if (! user == cb.room_slug) { suser = user; } for (var i = 0; i < vote_tracker._data.length; i++) { if (i > 0) { msg += "\n"; } msg += vote_tracker._data[i].choice + " (" + vote_tracker._data[i].nb_voted + " votes)"; } cb.sendNotice(" Poll choices and stats: ", suser, "#666699", "#FFFFFF", "bold"); cb.sendNotice(msg, suser); } }; vote_tracker.init(); function votes_remaining() { var r = cb.settings.max_votes - total_voted; if (r < 1) { finished = true; return 0; } else { finished = false; return r; } } function testvoter(user) { for (var i = 0; i < voters.length; i++) { if (voters[i].user == user) { cb.sendNotice('You can only vote once!', user, "#FF0000", "#FFFFFF", "bold"); return 0; } } return 1; } function advert() { cb.sendNotice("Poll choices & stats:", "" , "#666699", "#FFFFFF", "bold"); var msga = ""; for (var i = 0; i < vote_tracker._data.length; i++) { if (i > 0) { msga += "\n"; } msga += vote_tracker._data[i].choice + " (" + vote_tracker._data[i].nb_voted + " votes)"; } cb.sendNotice(msga); cb.setTimeout(advert, (ADVERT_TIME * 60000)); } var subject_is_set_with_0 = false; function update_subject() { cb.log('update_subject'); var ft = ""; if (votes_remaining() == 0) { if (subject_is_set_with_0) { return; } subject_is_set_with_0 = true; } else { subject_is_set_with_0 = false; } if (vote_tracker.bestchoice) { if (finished == true) { ft = "Elected: " + vote_tracker.bestchoice.choice; } else { ft = "Top choice: " + vote_tracker.bestchoice.choice + " (" + votes_remaining() + " votes remaining) Type !stat to see choices and stats."; } //ft = vote_tracker.bestchoice.choice; } else { ft = "\u2605 start voting! \u2605 Type !stat to see choices and stats."; vote_tracker.send_stats(); cb.setTimeout(advert, (ADVERT_TIME * 60000)); } // var new_subject = ft; cb.sendNotice(ft); // cb.changeRoomSubject(ft); } update_subject();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.