Bots Home
|
Create an App
bash
Author:
bash74
Description
Source Code
Launch Bot
Current Users
Created by:
Bash74
cb.settings_choices = [ {name: 'Timer g', type: 'str', defaultValue: 'General Timer'}, {name: 'Timer m', type: 'str', defaultValue: 'Mystery Timer'}, {name: 'Timer s', type: 'str', defaultValue: 'Silence Timer'}, {name: 'Timer l', type: 'str', defaultValue: 'Log Off'}, ]; // Timer... function appTimeout(a,b) { cb.setTimeout(a, b<1000 ? 1000 : b); } var setTimeout=function a(b,c) { function d() { _aa.cancelled || b(); } if (!(this instanceof a))return new a(b,c); var _aa=this; appTimeout(d,c); }; var clearTimeout=function(b) { null!=b && (b.cancelled=!0); }; function notify(a,b,c,d,e) { null==c && (c=cb_light); null==d && (d=cb_dark); null==e && (e='bold'); cb.sendNotice(a,(null==b)?'':b,c,d,e) } function notifyBold(a,b,c,d) { null==c && (c=theme_light), null==d && (d=theme_dark), notify(a,b,c,d,'bold'); } function notifyHelpPlain(a,b,d) { var c=white; null==d && (d=cb_dark); notify(a,b,c,d); } function notifyHelpBold(a,b,c,d) { null==c && (c=cb_dark), null==d && (d=white), notify(a,b,c,d,'bold'); } function notifyError(a,usr) { notify(a,usr,error_light,error_dark); } function notifyInvalidOption(cmd, o, usr) { if (null!=o) notifyError('\''+o+'\' is not a valid option for /'+cmd+'.\nType \"/help '+cmd+'\" to see how to use /'+cmd+'.', usr) else notifyError('You did not enter a valid option for /'+cmd+'.\nType \"/help '+cmd+'\" to see how to use /'+cmd+'.', usr); } var timerName= { 'g': cb.settings['Timer g'], 's': cb.settings['Timer s'], 'l': cb.settings['Timer l'], 'm': cb.settings['Timer m'], }; function setTimerName(o,usr,pusr) { var x,g='g'; var a=(null!=o && (x=o.indexOf(' '),0<x)) ? (g=o.substr(0,x),o.substr(x+1).trim()):o; if (pusr!=null) g+=" "+pusr; if (a!=null) { timerName[g]=a; notifyBold(a+' has named Timer '+g+': '+name(g),pusr); } else { notifyInvalidOption('nt', null, usr) } } function name(g) { return (timerName[g]==null)?"Timer "+g:timerName[g]; } function setTimer(g,ts,pusr) { clearTimeout(warnTimeout[g]); clearTimeout(timerTimeout[g]); if (0==ts) { startTime[g] = 0; } if (ts>300) { warnTimeout[g]=setTimeout(function() { var x=(ts-1-(ts-1)%300)/60; notifyBold(name(g)+' has '+x+' minutes remaining!',pusr); setTimer(g,timeRemaining(g),pusr); },1000*((ts-1)%300+1)); } if (60<ts && ts<=300) { warnTimeout[g]=setTimeout(function() { notifyBold('One minute remaining for '+name(g)+'!',pusr); },1000*(ts-60)); } timerTimeout[g]=setTimeout(function() { notifyBold(bullets+' '+name(g)+'... Time is up!',pusr), startTime[g]=0; },1000*ts); } function startTimer(o,usr,pusr) { var x,g='g'; var a=(null!=o && (x=o.indexOf(' '),0<x)) ? (g=o.substr(0,x),o.substr(x+1).trim()):o; var t=parseInt(a); var ts=60*t; if (pusr!=null) g+=" "+pusr; if (0==startTime[g] || null==startTime[g])if (t>0 && -1==t.toString().indexOf('.')) { timerDuration[g]=ts; startTime[g]=new Date(); setTimer(g,ts,pusr); notifyBold(usr+' has set '+name(g)+' for '+t+' minute'+(1==t?'':'s')+'!',pusr); } else notifyInvalidOption("st", o, usr) else notifyError(name(g)+' is already running.',usr); } function timeRemaining(g) { var now=new Date(); var t= 3600*startTime[g].getHours()-3600*now.getHours() +60*startTime[g].getMinutes()-60*now.getMinutes() +startTime[g].getSeconds()-now.getSeconds() +timerDuration[g]; return t; } function addTime(o,usr,pusr) { var x,g='g'; var a=(null!=o && (x=o.indexOf(' '),0<x)) ? (g=o.substr(0,x),o.substr(x+1).trim()):o; var t=parseInt(a); var ts=60*t; if (pusr!=null) g+=" "+pusr; if (t>0 && -1==t.toString().indexOf('.'))if (0!=startTime[g] && null!=startTime[g]) { timerDuration[g]+=ts; setTimer(g,timeRemaining(g),pusr), notifyBold(usr+' has added '+t+' minute'+(1==t?'':'s')+' to '+name(g)+'!',pusr); } else notifyError(name(g)+' is not running.',usr); else notifyInvalidOption("at", o, usr); } function minusTime(o,usr,pusr) { var x,g='g'; var a=(null!=o && (x=o.indexOf(' '),0<x)) ? (g=o.substr(0,x),o.substr(x+1).trim()):o; var t=parseInt(a); var ts=-60*t; if (pusr!=null) g+=" "+pusr; if (t>0 && -1==t.toString().indexOf('.'))if (0!=startTime[g] && null!=startTime[g]) { timerDuration[g]+=ts; setTimer(g,timeRemaining(g),pusr), notifyBold(usr+' has subtracted '+t+' minute'+(1==t?'':'s')+' from '+name(g)+'!',pusr); } else notifyError(name(g)+' is not running.',usr); else notifyInvalidOption("mt", o, usr); } function stopTimer(o,usr,pusr) { var g=(null!=o)?o:'g'; if (pusr!=null) g+=" "+pusr; if (0!=startTime[g] && null!=startTime[g]) { setTimer(g,0,pusr); notifyBold(usr+' has cancelled '+name(g)+'.',pusr); } else { notifyError(name(g)+' is not running.',usr); } } function doubleDigit(a) { return('0'+a).slice(-2); } function timeLeft(usr) { var f=1, msg=''; for (var g in startTime) { if (g.indexOf(' ')<0 || g.indexOf(" "+usr)>0) if (0!=startTime[g]) { f=0; var r=timeRemaining(g); var hh=doubleDigit(Math.floor(r/3600)); var mm=doubleDigit(Math.floor((r-3600*hh)/60)); var ss=doubleDigit(r-3600*hh-60*mm); msg+='Time Remaining for '+name(g)+': '+hh+':'+mm+':'+ss+'\n'; } } if (f) notifyError('No Timer is running.',usr); else notify(msg,usr); } function showHelp(arg,usr) { var _aa=0; switch(null==arg && (arg=''),arg) { case '': var msg1='',msg2=''; msg1+=bullets+' Timer Help Menu '+bullets+'\n'; msg1+='Type \"/help x\", where x is one of the following choices,'; msg1+=' for more detailed information.\n'; msg1+='Ex: /help st'; msg2+='!nt g name - give the timer a name.\n'; msg2+='!st g x - start a timer with x minutes\n'; msg2+='!at g x - add x minutes to the timer.\n'; msg2+='!mt g x - subtract x minutes from the timer.\n'; msg2+='!et g - cancel the timer.\n'; msg2+='!tl - show remaining time for all running timers.'; notifyHelpBold(msg1,usr); notify(msg2,usr); _aa=1; break; case 'st': var msg1='',msg2=''; msg1+='!st g x - start a timer\n'; msg1+=' - g: Timer identifier, no blanks allowed\n'; msg1+=' - x: Time in minutes for the timer'; msg2+='This command starts a timer, using g as the identifier.'; msg2+=' So you can start as many different timers as you want.'; msg2+=' There will be a warning every multiple of 5 minutes'; msg2+=' and 1 minute left of the timer, and a \"Time is up\" message at the end.'; msg2+=' Use the following commands to modify the timer:\n'; notifyHelpBold(msg1,usr); notify(msg2,usr); _aa=1; break; case 'nt': var msg1='',msg2=''; msg1+='!nt g name - give the timer a name.\n'; msg1+=' - g: Timer identifier, no blanks allowed\n'; msg1+=' - name: Name of the timer. Blanks are allowed here.'; msg2+='The name of a timer is used in the following messages:\n'; msg2+=' - [name] has [x] minutes remaining! ([x]=5,10,15,...)\n'; msg2+=' - One minute remaining for [name]!\n'; msg2+=' - [name]... Time is up!\n'; msg2+=' - [user] has set [x] minutes for [name]!\n'; msg2+=' - [user] has added [x] minutes to [name]!\n'; msg2+=' - [user] has subtracted [x] minutes from [name]!\n'; msg2+=' - [user] has cancelled [name]!\n'; msg2+=' - Time Remaining for [name]: hh:mm:ss!\n'; msg2+='Default-name for timer with identifier x:\n'; msg2+=" - x='g': General Timer\n"; msg2+=" - x='m': Mystery Timer\n"; msg2+=" - x='s': Silence Timer\n"; msg2+=" - x='l': Log Off\n"; msg2+=' - [x]: Timer [x]\n'; notifyHelpBold(msg1,usr); notify(msg2,usr); _aa=1; break; case 'at': notifyHelpPlain('!at g x - add x minutes to the timer.',usr); _aa=1; break; case 'mt': notifyHelpPlain('!mt g x - subtract x minutes from the timer.',usr); _aa=1; break; case 'et': notifyHelpPlain('!et g - cancel the timer.',usr); _aa=1; break; case 'tl': notifyHelpPlain('!tl - show remainig time for all running timers.',usr); _aa=1; break; } if (_aa=0) { notifyError(a+' is not a valid subsection of the help menu. Type \"!help\" to access the main help menu.',usr); } } cb.onMessage(function(x012) { var msg = x012.m.trim(); var usr = x012.user; var isMod = (x012.user==cb.room_slug) || x012.user.is_mod; var idx=msg.indexOf(' '); var cmd = (idx<0) ? msg.toLowerCase() : msg.substr(0,idx).toLowerCase(); var arg = (idx<0) ? null : msg.substring(idx + 1).trim(); if (cmd.charAt(0)=='!') { x012['X-Spam']=!0, x012.background=whis_cmnds_sentbg, x012.c=whis_cmnds_senttext; } if (isMod) switch (cmd) { case '!st': startTimer(arg,usr); break; case '!at': addTime(arg,usr); break; case '!mt': minusTime(arg,usr); break; case '!nt': setTimerName(arg,usr); break; case '!et': stopTimer(arg,usr); break; } switch (cmd) { case '!stp': startTimer(arg,usr,usr); break; case '!atp': addTime(arg,usr,usr); break; case '!mtp': minusTime(arg,usr,usr); break; case '!ntp': setTimerName(arg,usr,usr); break; case '!etp': stopTimer(arg,usr,usr); break; case '!tl': timeLeft(usr); break; case '!help': showHelp(arg,usr); break; } }); var startTime={}, timerDuration={}, timerTimeout={}, warnTimeout={}, purple_dark='#AC00DC', purple_light='#EEE1F1', cb_dark='#000000', cb_light='#EEEEEE', white='#FFFFFF', whis_cmnds_sentbg='#EEEEEE', whis_cmnds_senttext='#000000', error_dark='#000000', error_light='#FFC8C8', theme_dark=purple_dark, theme_light=purple_light, bullets=' * * * ';
© Copyright Chaturbate 2011- 2024. All Rights Reserved.