Bots Home
|
Create an App
HP Vote #3 - Action Vote
Author:
beautyandthebooty
Description
Source Code
Launch Bot
Current Users
Created by:
Beautyandthebooty
/** Name: Ongoing Token Polling Modifier/Author: indshadow Based On: Token Polling by kevanescence and lindseylove **/ var dashLine = "------------------------------------------------------------"; var cmdPrefix = '!'; var MODS = 'red'; var FANS = 'green'; var COLOR = { BRED : '#FF1407', /* Bright red: Timer notice, misc. important messages */ MRED : '#D80A00', /* Medium red */ HIGHLIGHT : '#EEE5FF', /* Pastel purple: Highlight colour for ticket holders */ SUCCESS : '#468847', /* Green: Everything is fine */ ERROR : '#B94A48', /* Red: Everything fails */ INFO : '#144D8C', /* Blue-grey: Help and misc info */ NOTICE : '#6900CC', /* Bluish purple: General chat notice */ DPURPLE : '#663399', /* Dark purple */ LPURPLE : '#8041BF', /* Lighter purple */ BLUE : '#000099', /* Dark blue */ MOD : '#DC0000', /* Moderator red */ FAN : '#009900', /* Fan green */ SYNTAX : '#995B00', /* Brownish: Usage notice colour and messages to broadcaster on mod-action */ HVTEXT : '#D80A00', /* Reddish: Text colour for Hi-Vis notices */ HVBACK : '#FFFFBF', /* Light yellow: Background colour for Hi-Vis notices */ TBMBACK : '#E0EEFF', TBMTEXT : '#12447A', MAG : '#E509E5', /* Magenta */ STOPHL : '#FFE5E5', PINK : '#FF48D2', /* Pink */ BLI : '#DDFFCC', /* Pastel green - Birdy */ BF : '#FFE0EA' /* Pastel pink - Blaze */ }; //Code originally from Token Poll Chaturbate App //Modified by the developers of this app var foreground = '#FFFFFF'; var fg_warn = '#FF0000'; var background = COLOR.PINK; var txt_never = 'When I end it'; var txt_minutes = 'After x minutes'; var txt_votecount= 'After x votes'; var txt_wincount = 'When one option reaches x votes'; var opt_votes = [0, 0, 0, 0, 0, 0, 0, 0]; var opt_labels = [cb.settings.opt1_label, cb.settings.opt2_label, cb.settings.opt3_label, cb.settings.opt4_label, cb.settings.opt5_label, cb.settings.opt6_label, cb.settings.opt7_label, cb.settings.opt8_label]; var opt_tokens = [cb.settings.opt1_tokens, cb.settings.opt2_tokens, cb.settings.opt3_tokens, cb.settings.opt4_tokens, cb.settings.opt5_tokens, cb.settings.opt6_tokens, cb.settings.opt7_tokens, cb.settings.opt8_tokens]; var mins_remain = cb.settings.poll_count; var votes_remain = cb.settings.poll_count; var poll_running = true; /***** App commands *****/ var COMMAND = { // Moderator Commands: CMDS : '!cmds', // List of these commands ADDTIME : '!addtime', // Add time in minutes to the timer. ADDVOTES : '!addvotes', // Add votes to the counter SETVOTES : '!setvotes', // Sets the vote counter ENDPOLL : '!endpoll', // Stop the Poll. POLL : '!poll' // Display the poll board }; // bot options cb.settings_choices = [ {name: 'poll_title', type: 'str', minLength: 1, maxLength: 255, label: 'Poll Title'}, {name: 'board_interval', type: 'int', minValue: 1, default: 3, label: 'Board Display Interval (mins)'}, {name: 'poll_mode', type: 'choice', label: 'Poll ends...', choice1: txt_never, choice2: txt_minutes, choice3: txt_votecount, choice4: txt_wincount, defaultValue: txt_minutes}, {name: 'poll_count', type: 'int', minValue: 1, default: 15, label: '... Where x is ...'}, {name: 'opt1_label', type: 'str', minLength: 1, maxLength: 255, label: 'Option 1'}, {name: 'opt1_tokens', type: 'int', minValue: 1, default: 10, label: 'Option 1 tokens'}, {name: 'opt1_prev', type: 'int', minValue: 0, default: 0, label: 'Option 1 last vote total', required: false}, {name: 'opt2_label', type: 'str', minLength: 1, maxLength: 255, label: 'Option 2'}, {name: 'opt2_tokens', type: 'int', minValue: 1, default: 11, label: 'Option 2 tokens'}, {name: 'opt2_prev', type: 'int', minValue: 0, default: 0, label: 'Option 2 last vote total', required: false}, {name: 'opt3_label', type: 'str', minLength: 1, maxLength: 255, label: 'Option 3', required: false}, {name: 'opt3_tokens', type: 'int', minValue: 0, default: 0, label: 'Option 3 tokens', required: false}, {name: 'opt3_prev', type: 'int', minValue: 0, default: 0, label: 'Option 3 last vote total', required: false}, {name: 'opt4_label', type: 'str', minLength: 1, maxLength: 255, label: 'Option 4', required: false}, {name: 'opt4_tokens', type: 'int', minValue: 0, default: 0, label: 'Option 4 tokens', required: false}, {name: 'opt4_prev', type: 'int', minValue: 0, default: 0, label: 'Option 4 last vote total', required: false}, {name: 'opt5_label', type: 'str', minLength: 1, maxLength: 255, label: 'Option 5', required: false}, {name: 'opt5_tokens', type: 'int', minValue: 0, default: 0, label: 'Option 5 tokens', required: false}, {name: 'opt5_prev', type: 'int', minValue: 0, default: 0, label: 'Option 5 last vote total', required: false}, {name: 'opt6_label', type: 'str', minLength: 1, maxLength: 255, label: 'Option 6', required: false}, {name: 'opt6_tokens', type: 'int', minValue: 0, default: 0, label: 'Option 6 tokens', required: false}, {name: 'opt6_prev', type: 'int', minValue: 0, default: 0, label: 'Option 6 last vote total', required: false}, {name: 'opt7_label', type: 'str', minLength: 1, maxLength: 255, label: 'Option 7', required: false}, {name: 'opt7_tokens', type: 'int', minValue: 0, default: 0, label: 'Option 7 tokens', required: false}, {name: 'opt7_prev', type: 'int', minValue: 0, default: 0, label: 'Option 7 last vote total', required: false}, {name: 'opt8_label', type: 'str', minLength: 1, maxLength: 255, label: 'Option 8', required: false}, {name: 'opt8_tokens', type: 'int', minValue: 0, default: 0, label: 'Option 8 tokens', required: false}, {name: 'opt8_prev', type: 'int', minValue: 0, default: 0, label: 'Option 8 last vote total', required: false} ]; function showBoard(user) { // var response1 = "Here's the Token Poll board:\n"; var response1 = '---------- Token Poll board' + ('' == user ? ' (sent to all)' : '') + ': ----------\n'; var response2 = cb.settings.poll_title; if (!poll_running) { return; } for (i=0; i<opt_tokens.length; i++) { if (0 != opt_tokens[i]) { response2 += "\n - " + opt_labels[i] + " ["+ opt_votes[i] + " votes]: " + opt_tokens[i] + " tokens"; } } var response3 = ''; switch (cb.settings.poll_mode) { case txt_minutes: response3 = mins_remain + ' minute' + (mins_remain > 1 ? 's' : '') + ' remaining to vote\n'; break; case txt_votecount: response3 = votes_remain + ' vote' + (votes_remain > 1 ? 's' : '') + ' remaining before poll closes\n'; break; case txt_wincount: response3 = 'First option to ' + cb.settings.poll_count + ' votes wins!\n'; break; } response3 += 'Simply tip the shown token amounts to register your vote. Type !poll at any time to see poll board.'; if (undefined == user) { // we were triggered by a timeout user = ''; cb.setTimeout(showBoard, cb.settings.board_interval*60*1000); } // cb.sendNotice(response1, user); cb.sendNotice(response1 + response2, user, background, foreground, 'bold'); // if (undefined != response3) { cb.sendNotice(response3, user, background, foreground); // } // cb.sendNotice(response4, user); } function sanitizeBoard() { for (i=0; i<opt_tokens.length; i++) { if ( 0 != opt_tokens[i] ) { if ( cb.settings['opt'+(i+1)+'_prev'] > 0 ) { opt_votes[i] = cb.settings['opt'+(i+1)+'_prev']; votes_remain -= cb.settings['opt'+(i+1)+'_prev']; } } } for (i=1; i<opt_tokens.length; i++) { // start at option 2 if (0 != opt_tokens[i] && '' == opt_labels[i]) { // make sure no option labels are left blank cb.sendNotice("Token Poll Warning: Label for option " + (i+1) + " is blank -- removing from poll board!", cb.soom_slug, background, fg_warn, 'bold'); opt_tokens[i] = 0; continue; } for (j=0; j<i; j++) { // check all options before this one if (0 != opt_tokens[i] && opt_tokens[i] == opt_tokens[j]) { // make sure we don't have two options with the same token amounts cb.sendNotice("Token Poll Warning: Token amount for option " + (i+1) + " is not unique -- removing from poll board!", cb.soom_slug, background, fg_warn, 'bold'); opt_tokens[i] = 0; break; } else if (0 != opt_tokens[i] && opt_labels[i] == opt_labels[j]) { // make sure we don't have two options with the same label cb.sendNotice("Token Poll Warning: Label for option " + (i+1) + " is not unique -- removing from poll board!", cb.soom_slug, background, fg_warn, 'bold'); opt_tokens[i] = 0; break; } } } } function showWinner() { var options = []; for (i=0; i<opt_tokens.length; i++) { options[i] = i; } options.sort(function(a, b){return opt_votes[b]-opt_votes[a]}); var win_count = 1; for (i=1; i<opt_tokens.length; i++) { if (opt_votes[options[i]] != opt_votes[options[0]]) { break; } if (0 != opt_tokens[options[i]]) { win_count++; } } var response1 = '---------- Token Poll has ended! ----------\n'; var response2 = 'Winner' + (win_count > 1 ? 's (' + win_count + '-way tie)' : '') + ':'; for (i=0; i<win_count; i++) { if (opt_tokens[options[i]] != 0) { response2 += "\n - " + opt_labels[options[i]] + ": " + opt_votes[options[i]] + " votes"; } } cb.sendNotice(response1 + response2, '', background, foreground, 'bold'); } function checkPollEnd() { var _poll_running = poll_running; switch (cb.settings.poll_mode) { case txt_never: return; case txt_minutes: if (mins_remain < 1) { poll_running = false; } break; case txt_votecount: if (votes_remain < 1) { poll_running = false; } break; case txt_wincount: for (i=0; i<opt_tokens.length; i++) { if (opt_votes[i] >= cb.settings.poll_count) { poll_running = false; } } break; } if (_poll_running && !poll_running) { showWinner(); } } function tickTimer() { mins_remain--; checkPollEnd(); if (mins_remain > 0) { cb.setTimeout(tickTimer, 60*1000); } } // Check Message Function cb.onMessage(function (msg) { // for convenience var m = msg['m'].split(' '); var u = msg['user']; var isMod = (msg['is_mod'] || msg['user'] == cb.room_slug); var isFan = msg['in_fanclub']; var viewer, toViewer; /********** Start Switchs ***********/ if ( m[0].charAt(0) == '!' ) { // don't print the command to chat msg['X-Spam'] = true; switch (m[0]) { case COMMAND.POLL: { if (isMod) { if (poll_running) { showBoard(''); } else { showWinner(); } } else { if (poll_running) { showBoard(u); } else { showWinner(); } } break; } case COMMAND.ENDPOLL: { if (isMod) { poll_running = false; showWinner(); } break; } case COMMAND.CMDS: cb.sendNotice(getCommandList(isMod),u,'',COLOR.NOTICE,'bold'); break; case COMMAND.ADDTIME: if (isMod) { if (cb.settings.poll_mode != txt_minutes) return cb.sendNotice("* Timer is not running.",u,'',COLOR.NOTICE,'bold'); if(m[1]) { if (!isNan(parseInt(m[1],10)) && (parseInt(mins_remain,10) + parseInt(m[1],10)) < 121) { mins_remain = parseInt(mins_remain,10) + parseInt(m[1],10); cb.sendNotice("* "+m[1]+" minutes added to the timer.",u,'',COLOR.NOTICE,'bold'); cb.sendNotice(dashLine+"\n* Less than " + mins_remain + " minutes until the show starts!\n"+dashLine,'','',COLOR.BRED,'bold'); } else { cb.sendNotice("* Not a valid number.",u,'',COLOR.NOTICE,'bold'); } } else { cb.sendNotice("* Syntax: "+ COMMAND.ADDTIME +" <some number of minutes here>",u,'',COLOR.SYNTAX,'bold'); } } break; case COMMAND.ADDVOTES: if (isMod) { if (cb.settings.poll_mode != txt_votecount && cb.settings.poll_mode != txt_wincount){ return cb.sendNotice("* Vote count currently not running.",u,'',COLOR.NOTICE,'bold') } if(m[1]){ if(!isNan(parseInt(m[1],10))){ switch (cb.settings.poll_mode){ case txt_votecount: votes_remain = parseInt(m[1],10) + parseInt(votes_remain,10); cb.settings.poll_count = parseInt(m[1],10) + parseInt(cb.settings.poll_count,10); break; case txt_wincount: cb.settings.poll_count = parseInt(m[1],10) + parseInt(cb.settings.poll_count,10); break; } } else{ cb.sendNotice("* Not a valid number.",u,'',COLOR.NOTICE,'bold'); } } else{ cb.sendNotice("* Syntax: "+ COMMAND.ADDVOTES +" <some number of votes here>",u,'',COLOR.SYNTAX,'bold'); } } break; case COMMAND.SETVOTES: if (isMod) { if (cb.settings.poll_mode != txt_votecount && cb.settings.poll_mode != txt_wincount){ return cb.sendNotice("* Vote count currently not running.",u,'',COLOR.NOTICE,'bold') } if(m[1]){ if(!isNan(parseInt(m[1],10))){ switch (cb.settings.poll_mode){ case txt_votecount: votes_remain = parseInt(m[1],10); cb.settings.poll_count = parseInt(m[1],10); break; case txt_wincount: cb.settings.poll_count = parseInt(m[1],10); break; } } else{ cb.sendNotice("* Not a valid number.",u,'',COLOR.NOTICE,'bold'); } } else{ cb.sendNotice("* Syntax: "+ COMMAND.ADDVOTES +" <some number of votes here>",u,'',COLOR.SYNTAX,'bold'); } } break; } } }); //End Check Message Function // Get the list of commands function getCommandList(isMod) { var cmdlist = "--------------- COMMAND LIST ---------------"; // Header // Moderator, or Broadcaster only Commands if (isMod) { // Only show these commands to the moderators // Always show to the broadcaster cmdlist += "\n"; cmdlist += "\n" + COMMAND.CMDS + " - Lists commands"; cmdlist += "\n"; cmdlist += "\n" + COMMAND.ADDTIME + " <minutes> - Adds time to the countdown timer. Negative numbers can used to subtract time."; cmdlist += "\n"; cmdlist += "\n" + COMMAND.ADDVOTES + "<votes> - Adds votes to the counter"; cmdlist += "\n"; cmdlist += "\n" + COMMAND.SETVOTES + "<votes> - Sets the number of votes on the counter"; cmdlist += "\n"; cmdlist += "\n" + COMMAND.ENDPOLL + " Stop the poll."; cmdlist += "\n"; cmdlist += "\n" + COMMAND.POLL + " Show the Polling board."; } else { cmdlist += "\n"; cmdlist += "\n" + COMMAND.CMDS + " - Lists commands"; cmdlist += "\n"; cmdlist += "\n" + COMMAND.POLL + " Show the Polling board."; } return cmdlist; } cb.onEnter(function (user) { cb.sendNotice("Hello " + user['user'] + ", the Token Poll app is currently active in this room.\nType !poll to see voting options.", user['user'], background, foreground); }); cb.onTip(function (tip) { var amount = parseInt(tip['amount']); if (!poll_running) { return; } for (i=0; i<opt_tokens.length; i++) { if (amount == opt_tokens[i]) { cb.sendNotice(tip['from_user'] + " has voted for " + opt_labels[i], '', background, foreground); opt_votes[i]++; if (txt_votecount == cb.settings.poll_mode) { votes_remain--; } checkPollEnd(); break; } } }); sanitizeBoard(); showBoard(); if (txt_minutes == cb.settings.poll_mode) { cb.setTimeout(tickTimer, 60*1000); }
© Copyright Chaturbate 2011- 2026. All Rights Reserved.