Bots Home
|
Create an App
Poll n Vote
Author:
cachotest
Description
Source Code
Launch Bot
Current Users
Created by:
Cachotest
// startof CBSv2 module - not for re-compilation (function(a,k){function h(a){this.message=a}h.prototype=Error();h.prototype.name="InvalidCharacterError";a.btoa||(a.btoa=function(a){a=String(a);for(var g,b,p=0,c=k,r="";a.charAt(p|0)||(c="=",p%1);r+=c.charAt(63&g>>8-p%1*8)){b=a.charCodeAt(p+=.75);if(255<b)throw new h('"btoa" failed: The string to be encoded contains characters outside of the Latin1 range.');g=g<<8|b}return r});a.atob||(a.atob=function(a){a=String(a).replace(/=+$/,"");if(1==a.length%4)throw new h('"atob" failed: The string to be decoded is not correctly encoded.'); for(var g=0,b,p,c=0,r="";p=a.charAt(c++);~p&&(b=g%4?64*b+p:p,g++%4)?r+=String.fromCharCode(255&b>>(-2*g&6)):0)p=k.indexOf(p);return r})})("undefined"===typeof exports?this:exports,"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="); (function(a){var k=cb.onMessage,h=null,r=null,g,b="#"+(cb.settings.hasOwnProperty("slot")?cb.settings.slot:"")+"CBSv2",p=/^\/#[0-3]CBSv2\//;cb.log("CBS::v2::CB app/bot data Save/restore::20170118.008::Release");cb.onMessage=function(c){if("function"!==typeof c)throw new TypeError(c+" is not a function");k(function(k){var d=k.m.replace(/\s*/g,"").split("/"),n,t;3<d.length&&""===d[0]&&d[1]===b?(h&&r&&k.user===cb.room_slug&&(n=d[2],4===d.length?(d[3]="?",k.m=d.join("/")):6===d.length?((g||{}).hasOwnProperty(n)|| (t=h(),g={},g[n]=a.btoa(a.unescape(a.encodeURIComponent(t))),t||cb.log("onSave returned no data.")),g.hasOwnProperty(n)&&(t=parseInt(d[3],10),n=g[n].slice(t,t+512),d[4]=n,d[5]=n.length,k.m=d.join("/"))):7===d.length&&("0"===d[3]&&(g={},g[n]=""),g.hasOwnProperty(n)&&(d[3]=g[n].length,d[6]=d[4].length,k.m=d.join("/"),d[4]?g[n]+=d[4]:(t=a.decodeURIComponent(a.escape(a.atob(g[n]))),r(t),cb.chatNotice("Previously Saved Data Restored.",cb.room_slug))))),k["X-Spam"]=!0):p.test(k.m)&&(k["X-Spam"]=!0);return c(k)}); return c};cb.onRestore=function(a){if("function"!==typeof a)throw new TypeError(a+" is not a function");return r=a};cb.onSave=function(a){if("function"!==typeof a)throw new TypeError(a+" is not a function");return h=a};cb.onMessage(function(a){return a})})("undefined"===typeof exports?this:exports); // endof CBSv2 module - not for re-compilation /***********************************\ Poll n Vote (c)2017 (10/10/17) Author: cacho_gordo Version: v1.1 (10/10/2017) <- Tips Vote Author: undefined --- fixed and modified --- -> Add POLL FREE OPINION \***********************************/ "use strict";const version=["Poll n Vote (c)2017 (10/10/17)","Version: v1.1 (10/10/2017)","Author: cacho_gordo (cachotest)"];var foreground="#FFFFFF",fg_warn="#FF0000",background="#0164EE",navy="#000080",yellow="#FFFF00",forenice="#0164EE",micolor="#2991f8";var nbsp="\xa0",stars=" \u2605 \u2605 \u2605 ",bullet="\u2022",diamond="\u2666";function spaces(c){var b=nbsp;if(c>1){for(var a=1;a<c;a++){b+=nbsp}}return b}var txt_never="When I end it",txt_votecount="After x votes",txt_wincount="One gets x votes";var opt_votes=[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];var opt_tokens=[cb.settings.opt1_tokens,cb.settings.opt2_tokens,cb.settings.opt3_tokens,cb.settings.opt4_tokens,cb.settings.opt5_tokens];var aPollKeys=[];var aUsrsVote=[];var txtPoll="";var votes_remain=cb.settings.vote_count;var votes_winner=votes_remain;var vote_mode=cb.settings.vote_mode;var vote_running=true;var actMode=cb.settings.action_mode;var modeBot="Token Votes";if(actMode=="POLL"){modeBot="Poll FREE";opt_tokens=[];opt_labels=[];vote_running=false}cb.onSave(function(){var a={opt_votes:opt_votes,opt_labels:opt_labels,opt_tokens:opt_tokens,aPollKeys:aPollKeys,aUsrsVote:aUsrsVote,txtPoll:txtPoll,votes_remain:votes_remain,votes_winner:votes_winner,vote_mode:vote_mode,vote_running:vote_running,actMode:actMode};return JSON.stringify(a)});cb.onRestore(function(b){var a=JSON.parse(b);Object.keys(a).forEach(function(c){if(this.hasOwnProperty(c)){this[c]=a[c]}})});cb.settings_choices=[{name:"action_mode",type:"choice",label:"Mode of Action",choice1:"POLL",choice2:"VOTE",defaultValue:"VOTE"},{name:"poll_title",type:"str",defaultValue:"Poll FREE your opinion in messages with quotes",minLength:10,maxLength:200,label:"For board MAIN TITLE MODE POLL"},{name:"vote_title",type:"str",defaultValue:"Vote by tips for my GOAL",minLength:10,maxLength:200,label:"For board TITLE MODE VOTE"},{name:"board_interval",type:"int",minValue:1,maxValue:15,defaultValue:3,label:"Board Display Interval (mins)"},{name:"vote_mode",type:"choice",label:"Voting ends...",choice1:txt_never,choice2:txt_votecount,choice3:txt_wincount,defaultValue:txt_wincount},{name:"vote_count",type:"int",minValue:10,defaultValue:15,label:"...where x is"},{name:"opt1_label",type:"str",defaultValue:"ANAL dildo",minLength:2,maxLength:200,label:"TOKEN Votes... Option 1"},{name:"opt1_tokens",type:"int",minValue:10,defaultValue:11,label:"Tokens op.1"},{name:"opt2_label",type:"str",defaultValue:"Finguering",minLength:2,maxLength:200,label:"Option 2"},{name:"opt2_tokens",type:"int",minValue:10,defaultValue:12,label:"Tokens op.2"},{name:"opt3_label",type:"str",defaultValue:"Cream a lot",maxLength:200,label:"Option 3",required:false},{name:"opt3_tokens",type:"int",minValue:0,defaultValue:13,label:"Tokens op.3",required:false},{name:"opt4_label",type:"str",defaultValue:"DP",maxLength:200,label:"Option 4",required:false},{name:"opt4_tokens",type:"int",minValue:0,defaultValue:14,label:"Tokens op.4",required:false},{name:"opt5_label",type:"str",defaultValue:"Cum SQUIRT",maxLength:200,label:"Option 5",required:false},{name:"opt5_tokens",type:"int",minValue:0,defaultValue:16,label:"Tokens op.5",required:false}];function showBoard(a){if(actMode=="VOTE"||txtPoll!==""){var e=spaces(3)+stars+"\xA0 Votes Board \xA0"+stars+spaces(12)+"\n";var d="";if(actMode=="POLL"){d="\xA0"+diamond+" "+cb.settings.poll_title+" "+diamond+"\xA0\n";d+=spaces(3)+bullet+" "+txtPoll+" "+bullet+spaces(8)}else{d=spaces(3)+bullet+" "+cb.settings.vote_title+" "+bullet+spaces(8)}var c="";if(vote_running){for(var b=0;b<opt_tokens.length;b++){if(0!=opt_tokens[b]){if(actMode=="VOTE"){d+="\n \xA0 - "+opt_labels[b]+" ["+opt_votes[b]+" vote"+(opt_votes[b]!==1?"s":"")+"] \xA0 Tip "+opt_tokens[b]+" tkns. \xA0"}else{d+="\n \xA0 - "+opt_labels[b]+" ["+opt_votes[b]+' votes] \xA0 Type "'+aPollKeys[b]+'" \xA0'}}}if(vote_mode==txt_votecount){c=votes_remain+" vote"+(votes_remain>1?"s":"")+" remaining before votes closes. \xA0\n"}else{if(vote_mode==txt_wincount){c="First option to "+cb.settings.vote_count+" votes wins! \xA0\n"}}if(actMode=="POLL"){c+="Type shown words in message to register your vote. \xA0\nType !votes at any time to see votes board. \xA0"}else{c+="Tip shown tokens to register your vote. \xA0\nType !votes at any time to see votes board. \xA0"}}var f=a;if(!a){f=""}cb.sendNotice(e+d,f,background,foreground,"bold");if(vote_running){cb.sendNotice(c,f,background,foreground)}else{showWinner()}}else{cb.sendNotice("Poll n Vote Warning: Not running yet!",(a?a:cb.room_slug),"",fg_warn,"bold")}if(!a){checkVoteEnd();cb.setTimeout(showBoard,cb.settings.board_interval*60*1000)}}function lenOpts(){var b=0;for(var a=0;a<opt_tokens.length;a++){if(opt_tokens[a]!=0){++b}}return b}function validaDatos(){for(var b=1;b<opt_tokens.length;b++){if(0!=opt_tokens[b]&&(""==opt_labels[b])){cb.sendNotice("Poll n Vote Warning: Label for option "+(b+1)+" is blank -- removing from vote board!",cb.room_slug,"",fg_warn,"bold");opt_tokens[b]=0;continue}for(var a=0;a<b;a++){if(0!=opt_tokens[b]&&opt_tokens[b]==opt_tokens[a]){cb.sendNotice("Poll n Vote Warning: Token amount for option "+(b+1)+" is not unique -- removing from votes board!",cb.room_slug,"",fg_warn,"bold");opt_tokens[b]=0;break}else{if(0!=opt_tokens[b]&&opt_labels[b].toLowerCase()==opt_labels[a].toLowerCase()){cb.sendNotice("Poll n Vote Warning: Label for option "+(b+1)+" is not unique -- removing from votes board!",cb.room_slug,"",fg_warn,"bold");opt_tokens[b]=0;break}}}}if(lenOpts()<2){cb.sendNotice("Poll n Vote Warning: No running with less of 2 options!",cb.room_slug,"",fg_warn,"bold");vote_running=false;return false}return true}function showWinner(){if(!opt_tokens.length){cb.sendNotice("Poll n Vote Warning: Action Mode "+modeBot+". NO options yet!",cb.room_slug,"",fg_warn,"bold");return}var b=[];for(var c=0;c<opt_tokens.length;c++){b[c]=c}b.sort(function(g,f){return opt_votes[f]-opt_votes[g]});if(opt_votes[b[0]]==0){cb.sendNotice("Poll n Vote Warning: Action Mode "+modeBot+". NO votes yet!",cb.room_slug,"",fg_warn,"bold");return}var a=1;for(var c=1;c<opt_tokens.length;c++){if(opt_votes[b[c]]!=opt_votes[b[0]]){break}if(0!=opt_tokens[b[c]]){a++}}var e="--- "+modeBot+" has ended! --- "+spaces(8)+"\n";var d="Winner"+(a>1?"s ("+a+"-way tie)":"")+": \xA0";for(var c=0;c<a;c++){if(opt_tokens[b[c]]!=0){d+="\n - "+opt_labels[b[c]]+": "+opt_votes[b[c]]+" votes \xA0"}}if(a==1||actMode=="POLL"){vote_running=false}else{d+="\nContinues voting for a few minutes, tie-break!";cb.sendNotice("Poll n Vote NOTE: Continues voting until when you end it with !endvotes command. \xA0",cb.room_slug,"",fg_warn,"bold");vote_mode=txt_never;vote_running=true}cb.sendNotice(e+d,"",background,foreground,"bold")}function checkVoteEnd(){switch(vote_mode){case txt_never:return;case txt_votecount:if(votes_remain>0){return}vote_running=false;break;case txt_wincount:for(var a=0;a<opt_tokens.length;a++){if(opt_votes[a]>=votes_winner){vote_running=false;break}}if(vote_running){return}break}showWinner()}function parsePollParams(b){resetData();b=b.replace(/\\/g,"");var g="";var e=[],d=[],f=[];var h,a=b.indexOf('"');if(a>-1){h=b.indexOf('"',a+7);if(h>-1){g=b.substring(a+1,h).trim()}}if(g==""){return false}b=b.substr(h+1);e=b.split(";");for(var c=0;c<e.length;c++){if(!e[c]||e[c]==""){continue}d=e[c].trim().split("=");if(d.length!=2||d[0]==""){continue}f.push([d[0].trim(),d[1].trim()])}for(var c=0;c<f.length&&c<5;c++){aPollKeys[c]=f[c][0];opt_labels[c]=f[c][1];opt_tokens[c]=c+1}if(validaDatos()){txtPoll=g;aUsrsVote=[];opt_votes=[0,0,0,0,0];vote_running=true;return true}resetData();return false}function isModSlug(a){return(cb.room_slug==a.user||a.is_mod)}function resetData(){txtPoll="";aUsrsVote=[];vote_running=false;aPollKeys=[];opt_labels=[];opt_tokens=[];opt_votes=[0,0,0,0,0];votes_remain=cb.settings.vote_count;vote_mode=cb.settings.vote_mode}function reinit(){aUsrsVote=[];vote_running=true;opt_votes=[0,0,0,0,0];vote_mode=cb.settings.vote_mode;votes_remain=cb.settings.vote_count}cb.onMessage(function(a){if(!a.has_tokens){return a}var c=a.m.trim().split(/\s+/g);var e=isModSlug(a);if(c[0].charAt(0)=="!"){a["X-Spam"]=true;switch(c[0]){case"!help":if(c.length<2){cb.sendNotice(helpNotice(e),a.user,"",micolor)}else{cb.sendNotice(helpNotice(e,c[1]),a.user,"",micolor)}break;case"!votes":if(e){if(vote_running){showBoard("")}else{showWinner()}}else{if(vote_running){showBoard(a.user)}else{showWinner()}}break;case"!endvotes":if(cb.room_slug!=a.user&&"cacho_gordo"!==a.user){break}showWinner();break;case"!revotes":if(cb.room_slug!=a.user&&"cacho_gordo"!==a.user){break}if(actMode=="POLL"&&txtPoll==""){cb.sendNotice("Poll n Vote Warning: Action Mode "+modeBot+". NO options yet!!",cb.room_slug,"",fg_warn,"bold");break}if(!vote_running){reinit();showBoard("")}else{cb.sendNotice("Poll n Vote Warning: Action Mode "+modeBot+" is running!",cb.room_slug,"",fg_warn,"bold")}break;case"!poll":if(cb.room_slug!=a.user&&"cacho_gordo"!==a.user){break}if(actMode=="VOTE"){cb.sendNotice("Poll n Vote Warning: Action Mode "+modeBot+". NO POLL available!",cb.room_slug,"",fg_warn,"bold");break}if(vote_running){cb.sendNotice("Poll n Vote Warning: Action Mode "+modeBot+" is running!",cb.room_slug,"",fg_warn,"bold");break}c.splice(0,1);if(parsePollParams(c.join(" "))){vote_running=true;showBoard()}else{a.m+=" => Error parse params!"}break;case"!ver":if(a.user==cb.room_slug||a.user=="cacho_gordo"){cb.sendNotice(version.join("\n"),a.user,"",micolor)}break}}else{if(!vote_running){return a}var d=/"([^"]+)"/.exec(a.m);if(!d||d.length==0){d=/'([^']+)'/.exec(a.m);if(!d||d.length==0){return a}}if(aUsrsVote.indexOf(a.user)>=0){cb.sendNotice("Poll n Vote Warning: You already voted before, only allowed once!",a.user,"",fg_warn,"bold");a["X-Spam"]=true;return a}d=d[1].toLowerCase().trim();for(var b=0;b<aPollKeys.length;b++){if(d==aPollKeys[b].toLowerCase()){cb.sendNotice(a.user+" has voted for "+opt_labels[b],"",yellow,forenice,"bold");opt_votes[b]++;if(txt_votecount==vote_mode){votes_remain--}checkVoteEnd();break}}if(b==aPollKeys.length){cb.sendNotice("Poll n Vote Warning: Your option voted not exist!",a.user,"",fg_warn,"bold");return a}aUsrsVote.push(a.user)}return a});cb.onEnter(function(a){if(isModSlug(a)||!a.has_tokens){return}cb.sendNotice("Welcome "+a.user+', the Poll n Vote bot run in my room. \xA0\nIn Action Mode "'+modeBot+'" for voting options. \xA0\nType !votes to see voting options. '+(actMode=="VOTE"?"Tip tokens":"Type words")+" \xA0",a.user,background,foreground)});cb.onTip(function(c){if(!vote_running||txtPoll!==""){return}var b=parseInt(c.amount);for(var a=0;a<opt_tokens.length;a++){if(b==opt_tokens[a]){cb.sendNotice(c.from_user+" has voted for "+opt_labels[a],"",yellow,forenice,"bold");opt_votes[a]++;if(txt_votecount==vote_mode){votes_remain--}checkVoteEnd();break}}});function init(){cb.sendNotice();cb.sendNotice("********************************","","",navy,"bolder");cb.sendNotice(nbsp+" "+version[0],"","",navy,"bolder");cb.sendNotice(nbsp+" "+version[1],"","",navy,"bolder");cb.sendNotice(nbsp+" "+version[2],"","",navy,"bolder");cb.sendNotice("********************************","","",navy,"bolder");cb.sendNotice("Action Mode: "+modeBot,"","",micolor,"bold");cb.sendNotice("Commands:","","",navy);cb.sendNotice(" !votes - to see status of voting","","",navy);cb.sendNotice(" !help - see all commands.","","",navy);cb.sendNotice();if(actMode=="VOTE"){validaDatos();showBoard()}}var ahelp0=["\xA0 * * * * \xA0Poll n Vote \xA0 H E L P \xA0* * * *","\xA0\xA0 * * * created by cacho_gordo * * *","Votes for GOAL with tips or Poll FREE in messages."," Commands you can use:"];var ahelp1=["!votes - show state of voting - private, public if broadcaster.","!help [command] - this commands list [info of one of them] - private",""];var ahelp2=["!endvotes - end voting and publishes winning result - broadcaster only","!revotes - reinit voting if TOKEN Vote is ended - broadcaster only",'!poll "text" <options> - set params for Poll free voting - broadcaster only',"!ver - current version - private - use broadcaster and developer ( if mod ).",""];function helpNotice(a,b){var c="";if(!b||b==""){c=ahelp0.join("\n")+"\n";if(a){c+=ahelp2.join("\n")+"\n"}c+=ahelp1.join("\n")}else{switch(b){case"votes":return[" * Help votes command *","!votes - show state of voting.","Show private Notice of the voting or end result.","Show public if broadcaster."].join("\n");break;case"endvotes":if(a){return[" * Help endvotes command *","!endvotes - end voting, if running.","Public show winning result.","Only use of the broadcaster."].join("\n")}break;case"revotes":if(a){return[" * Help revotes command *","!revotes - reinit voting if is TOKEN Vote ended. ","Only use of the broadcaster."].join("\n")}break;case"poll":if(a){return[" * Help poll command *",'!poll "text question" <options>',"Set params for Start Poll FREE voting,","<options=>> op1=desc1;op2=desc2 [;op3=desc3[;op4=desc4[;op5=desc5]]]","Maximum 5 options, min. 2",'Eg: !poll "What do we play?" pussy=PUSSY;anal=ANAL;dp=DP',"Only use of the broadcaster."].join("\n")}break;case"ver":if(a){return[" * Help ver command *","!ver - Show software current version for developer info.","Only use of the broadcaster and developer (if mod) - private."].join("\n")}break;default:}}return c}init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.