Bots Home
|
Create an App
Overtime
Author:
jmmprogrammer
Description
Source Code
Launch Bot
Current Users
Created by:
Jmmprogrammer
/* This BOT will announce that the broadcaster will stop broadcasting 5 minutes after either the broadcaster or a mod kicks it off by simply entering !overtime Tipping within the last 5 minutes will extend the broadcast time. The broadcaster can decide how many tokens per minute going overtime will cost. tested at https://yyanx.github.io/CB-TestBed/ To test and tweak this code yourself, copy and paste all of this code into a locel .js file on your computer. Go to the above URL and follow the impossibly simple instructions. */ // ////////////// GLOBAL VARIABLES //////////////// // cb.settings_choices = [ {name:'__tokensPerMinute', type:'choice', label:'Tokens per minute', choice1:'10', choice2:'20', choice3:'40', choice4:'60', choice5:'80', choice6:'100', defaultValue:'10'}, {name:'__backgroundColor', type:'str', minLength: 7, maxLength: 7, label:"Background Color", defaultValue:'#AA00AA'}, {name:'__foregroundColor', type:'str', minLength: 7, maxLength: 7, label:"Foreground Color", defaultValue:'#FFFF00'} ]; // // // var _durationOfOvertime = 0; var _timerTimeout; var _timeToAddOn = 0; var _countDownDate = new Date().getTime() + _durationOfOvertime; var _speedOfTimer = 1000; // // When should the countdown warning begin. // I have initially set it for 5 minutes from // the scheduled end of the show. // var _finalCountDownStartTrigger = 300000; // 5 minutes // // We don't want to start extending time to the show // until it first dips below the 5 minute mark. // var _finalCountDownStarted = false; // // // $.50 per min. = 120000 // $1 per minute = 60000 // $2 per minute = 30000 // $3 per minute = 20000 // $4 per minute = 15000 // $5 per minute = 12000 // var _costOfOvertimePerMinute = 120000; // var coo = cb.settings.__tokensPerMinute; if( coo == 10 ){ _costOfOvertimePerMinute = 120000; }else if( coo == 20 ){ _costOfOvertimePerMinute = 60000; }else if( coo == 40 ){ _costOfOvertimePerMinute = 30000; }else if( coo == 60 ){ _costOfOvertimePerMinute = 20000; }else if( coo == 80 ){ _costOfOvertimePerMinute = 15000; }else if( coo == 100){ _costOfOvertimePerMinute = 12000; }else{ _costOfOvertimePerMinute = 120000; } // // var _backgroundColor = cb.settings.__backgroundColor; var _foregroundColor = cb.settings.__foregroundColor; var _style = 'bold'; // // // ////////////// END GLOBAL VARIABLES //////////////// // // Once someone tips within the last 5 minutes of the configured planned time, time is added to the show. // function addTokenTime(input){ if( _finalCountDownStarted == true) { // get the user input var newVal = input; _timeToAddOn = (newVal * .05) * _costOfOvertimePerMinute; _countDownDate += _timeToAddOn; //console.log("DEBUG " + _timeToAddOn); var dd = Math.floor(_timeToAddOn / (1000 * 60 * 60 * 24)); var hh = Math.floor((_timeToAddOn % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var mm = Math.floor((_timeToAddOn % (1000 * 60 * 60)) / (1000 * 60)); var ss = Math.floor((_timeToAddOn % (1000 * 60)) / 1000); cb.sendNotice("======= TIME EXTENDED ===========",'', _foregroundColor, _backgroundColor, 'bold'); if( hh > 0 ){ cb.sendNotice("--- Time extended by " + hh + " hour, " + mm + " minutes, and " + ss + " seconds.",'', _foregroundColor, _backgroundColor, ''); } else if( mm > 0 ){ cb.sendNotice("--- Time extended by " + mm + " minutes, and " + ss + " seconds.",'', _foregroundColor, _backgroundColor, ''); } else{ cb.sendNotice("--- Time extended by " + ss + " seconds.",'', _foregroundColor, _backgroundColor, ''); } // Get todays date and time var now = new Date().getTime(); var distance = _countDownDate - now; // Time calculations for days, hours, minutes and seconds var days = Math.floor(distance / (1000 * 60 * 60 * 24)); var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000); if(hours > 0){ cb.sendNotice("--- Will close in " + hours + " hour, " + minutes + " minutes and " + seconds + " seconds.",'', _foregroundColor, _backgroundColor, ''); } else if( hours == 0 && minutes > 0){ cb.sendNotice("--- Will close in " + minutes + " minutes and " + seconds + " seconds.",'', _foregroundColor, _backgroundColor, ''); } else if( hours == 0 && minutes == 0 && seconds > 0){ cb.sendNotice("--- Will close in " + seconds + " seconds.",'', _foregroundColor, _backgroundColor, ''); } else{} cb.sendNotice("======= TIME EXTENDED ===========",'', _foregroundColor, _backgroundColor, 'bold'); } } function overtime(){ // Get todays date and time var now = new Date().getTime(); // Find the distance between now and the count down date var distance = _countDownDate - now; // Final countdown begins if( distance < _finalCountDownStartTrigger ){ _finalCountDownStarted = true; } // calc cost per minute in tokens // _costOfOvertimePerMinute var secondsPerToken = ((1 * .05) * _costOfOvertimePerMinute)/1000; var tokensPerMinute = 60 / secondsPerToken; //cb.chatNotice( tokensPerMinute.toString() ); var outStr = "--- "; // // Time calculations for days, hours, minutes and seconds // var days = Math.floor(distance / (1000 * 60 * 60 * 24)); var hours = Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)); var minutes = Math.floor((distance % (1000 * 60 * 60)) / (1000 * 60)); var seconds = Math.floor((distance % (1000 * 60)) / 1000); if( hours == 0 && minutes == 5 && seconds == 0 ){ outStr += "5 MIN. UNTIL CLOSE --- TIP FOR MORE TIME.\n--- " + tokensPerMinute.toString() + " tokens per min ---"; cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else if( hours == 0 && minutes == 4 && seconds == 0 ){ outStr += "4 MIN. UNTIL CLOSE --- TIP FOR MORE TIME.\n--- " + tokensPerMinute.toString() + " tokens per min ---"; cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else if( hours == 0 && minutes == 3 && seconds == 0 ){ outStr += "3 MIN. UNTIL CLOSE --- TIP FOR MORE TIME.\n--- " + tokensPerMinute.toString() + " tokens per min ---"; cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else if( hours == 0 && minutes == 2 && seconds == 0 ){ outStr += "2 MIN. UNTIL CLOSE --- TIP FOR MORE TIME.\n--- " + tokensPerMinute.toString() + " tokens per min ---"; cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else if( hours == 0 && minutes == 1 && seconds == 0 ){ outStr += "1 MIN. UNTIL CLOSE --- TIP FOR MORE TIME.\n--- " + tokensPerMinute.toString() + " tokens per min ---"; cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else if( hours == 0 && minutes == 0 && seconds == 50 ){ outStr += ("50 SEC. UNTIL CLOSE --- TIP FOR MORE TIME."); cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else if( hours == 0 && minutes == 0 && seconds == 40 ){ outStr += ("40 SEC. UNTIL CLOSE --- TIP FOR MORE TIME."); cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else if( hours == 0 && minutes == 0 && seconds == 30 ){ outStr += ("30 SEC. UNTIL CLOSE --- TIP FOR MORE TIME."); cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else if( hours == 0 && minutes == 0 && seconds == 20 ){ outStr += ("20 SEC. UNTIL CLOSE --- TIP FOR MORE TIME."); cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else if( hours == 0 && minutes == 0 && seconds == 10 ){ outStr += ("10 SEC. UNTIL CLOSE --- TIP FOR MORE TIME."); cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); _speedOfTimer = 1000; } else if( hours == 0 && minutes == 0 && seconds == 9 ){ outStr += ("9 SEC. UNTIL CLOSE.---"); cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else if( hours == 0 && minutes == 0 && seconds == 8 ){ outStr += ("8 SEC. UNTIL CLOSE.---"); cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else if( hours == 0 && minutes == 0 && seconds == 7 ){ outStr += ("7 SEC. UNTIL CLOSE.---"); cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else if( hours == 0 && minutes == 0 && seconds == 6 ){ outStr += ("6 SEC. UNTIL CLOSE.---"); cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else if( hours == 0 && minutes == 0 && seconds == 5 ){ outStr += ("5 SEC. UNTIL CLOSE.---"); cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else if( hours == 0 && minutes == 0 && seconds == 4 ){ outStr += ("4 SEC. UNTIL CLOSE.---"); cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else if( hours == 0 && minutes == 0 && seconds == 3 ){ outStr += ("3 SEC. UNTIL CLOSE.---"); cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else if( hours == 0 && minutes == 0 && seconds == 2 ){ outStr += ("2 SEC. UNTIL CLOSE.---"); cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else if( hours == 0 && minutes == 0 && seconds == 1 ){ outStr += ("1 SEC. UNTIL CLOSE.---"); cb.sendNotice( outStr,'', _backgroundColor, _foregroundColor, _style); } else{} // If the count down is over, write some text if (distance < 0) { // time to stop _finalCountDownStarted = false; cb.chatNotice("==================================="); cb.chatNotice("Thank you for joining me today. I'll see you all next time."); cb.chatNotice("I hope that you will follow me and like my room."); cb.chatNotice("==================================="); cb.cancelTimeout(_timerTimeout); } else{ // keep going cb.setTimeout(overtime, _speedOfTimer); } } cb.onTip(function ( tip ) { var _amountTipped = 0; _amountTipped = parseInt(tip['amount']); addTokenTime( _amountTipped ); }); cb.onMessage(function (msg) { blockBadWords(msg); // // only the broadcaster or a mod can kickoff the countdown // if(( msg['user'] == cb.room_slug )||(msg['is_mod'] == true)){ if ( msg['m'] == '!overtime' ){ // // 5 minutes and 5 seconds = 305000 // msg['X-Spam'] = true; _durationOfOvertime = 305000; _countDownDate = new Date().getTime() + _durationOfOvertime; _timerTimeout = cb.setTimeout(overtime, _speedOfTimer); } } return msg; }); // // Other bots may do this. The requestor asked for this // to be here just to be sure. // function blockBadWords(msg){ var str = msg['m']; str = str.toLowerCase(); // // only the broadcaster or a mod can say whatever they want // if(( msg['user'] != cb.room_slug )&&(msg['is_mod'] == false)) { if ( str.includes("whore") ){ cb.sendNotice( msg['user'] +" said: \"" + msg['m'] + "\"\nThe message was blocked.", cb.room_slug, '#FF0000', '#FFFFFF', _style); msg['X-Spam'] = true; } if ( str.includes("slut") ){ cb.sendNotice( msg['user'] +" said: \"" + msg['m'] + "\"\nThe message was blocked.", cb.room_slug, '#FF0000', '#FFFFFF', _style); msg['X-Spam'] = true; } } return msg; }
© Copyright Chaturbate 2011- 2024. All Rights Reserved.