Bots Home
|
Create an App
Power to the PeoPoll
Author:
metal4ever_
Description
Source Code
Launch Bot
Current Users
Created by:
Metal4ever_
// modified from kinkycouple4you's "Viewers Choice Goal" for Mila_ var total_voted = 0; voters = []; cb.settings_choices = [ {name:'bc_peopoll_only', type:'choice', choice1:'Yes', choice2:'No', defaultValue:'Yes', label: "Broadcaster can call !peopoll exclusively?"}, {name:'polltitle', type:'str', defaultValue:'What do you prefer?', label: "PeoPoll Title", maxLength: 200}, {name:'choice1', type:'str', defaultValue:'Bananas!', label: "Choice 1", maxLength: 200}, {name:'choice2', type:'str', defaultValue:'Apples!', 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'] == '!peopoll') { msg['X-Spam'] = true; if (msg['user'] == cb.room_slug) { vote_tracker.send_stats(); } else { if(cb.settings.bc_peopoll_only == "No") { vote_tracker.send_stats(msg['user']); } else { cb.chatNotice('Only the broadcaster can show the results!', msg['user'], "#FF0000", "#FFFFFF", "bold"); } } } 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']}); cb.chatNotice('Thanks, your vote has been cast!', msg['user'], "#008800", "#FFFFFF", "bold"); total_voted ++ } } } return msg; }); 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]); } }, 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 = ""; 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)"; } if (total_voted) { msg += "\n=== " + total_voted + " votes have been cast in total! ==="; } else { msg += "\n=== No votes have been cast yet! ==="; } cb.chatNotice(cb.settings.polltitle, user, "#FF9900", "#FFFFFF", "bold"); cb.chatNotice(msg, user); if (vote_tracker.bestchoice) { nbchoice = vote_tracker.bestchoice.nb_voted; bestchoice_display = vote_tracker.bestchoice.choice+ ' (' + nbchoice + ')'; cb.chatNotice('Leading option: ' + bestchoice_display, user, "#0000C4", "#FFFFFF", "bold"); } } }; vote_tracker.init(); function testvoter(user) { for(var i=0; i < voters.length; i++){ if(voters[i].user==user){ cb.chatNotice('You can only vote once!', user, "#FF0000", "#FFFFFF", "bold"); return 0; } } return 1; }
© Copyright Chaturbate 2011- 2024. All Rights Reserved.