Bots Home
|
Create an App
Stopwatch
Author:
gargoyle1
Description
Source Code
Launch Bot
Current Users
Created by:
Gargoyle1
/** * Bot: Stopwatch * Version: 1.1 * Author: gargoyle1 * Date: 11.11.15 * Last update: 15.04.15 */ var timeleft = 0; var color; var mincount = 60; var minutes; var hour; var min; var sec; var white = '#ffffff'; colname = new Array('black','grey','blue','green','red','orange','purple','pink'); colcode = new Array('#000000','#494949','#000099','#029903','#dd0000','#db5300','#824bab','#fd58d1'); cb.settings_choices = [ {name: 'time', type:'int', label:'Set Time (minutes)', minValue:1, maxValue:9999, defaultValue:5}, {name:'color', type:'choice', label:'Note Color', choice1:'black', choice2:'grey', choice3:'blue', choice4:'green', choice5:'red', choice6:'orange', choice7:'purple', choice8:'pink', defaultValue:'grey', required:false}, ]; cb.onEnter(function(user) { cb.sendNotice('Stopwatch by gargoyle1!', user['user'], '', color, 'bold'); }); cb.onMessage(function (msg) { if ((msg['user'] == (cb.room_slug || msg['is_mod'])) && msg['m'].indexOf("!") == 0) { var message = msg['m'].split(' '); if (msg['m'] == '!c') { msg['X-Spam'] = true; cb.sendNotice('!start = start the stopwatch', msg['user'], '', '', ''); cb.sendNotice('!stop = stop the stopwatch', msg['user'], '', '', ''); cb.sendNotice('!clock = shows the actual remaining time', msg['user'], '', '', ''); cb.sendNotice('!time x = set time to x minutes', msg['user'], '', '', ''); cb.sendNotice('!color x = set color to x (name or code e.g. #FF6699)', msg['user'], '', '', ''); } if (msg['m'] == '!clock') { msg['X-Spam'] = true; printclock(); } if (msg['m'] == '!stop') { msg['X-Spam'] = true; timeleft = 0; cb.sendNotice('Stopwatch stopped!', '', '', color, 'bold'); } if (msg['m'] == '!start') { msg['X-Spam'] = true; timeleft = cb.settings.time*60; mincount = 60; cb.sendNotice('Stopwatch started!', '', '', color, 'bold'); cb.setTimeout(timecount, 1000); } if (message[0] == '!time') { msg['X-Spam'] = true; cb.settings.time = message[1]; timeleft = cb.settings.time*60; mincount = 60; cb.sendNotice('Time set to ' + message[1] + ' minutes!', '', '', color, 'bold'); } if (message[0] == '!color') { msg['X-Spam'] = true; cb.settings.color = message[1]; var codetest = message[1].split(''); if (codetest[0] == '#' && codetest.length == 7) { color = message[1]; cb.sendNotice('Color set to code ' + color + '!', '', '', color, 'bold'); } else { setcolor(); } } } return msg; }); function setcolor() { for(var i=0;i<=7;i++) { if (cb.settings.color == colname[i]) { color = colcode[i]; cb.sendNotice('Color set to ' + cb.settings.color + '!', '', '', color, 'bold'); } } } function timecount() { if (timeleft > 0) { cb.setTimeout(timecount, 1000); if (timeleft == 1 || timeleft == 2 || timeleft == 3 || timeleft == 4 || timeleft == 5 || timeleft == 6 || timeleft == 7 || timeleft == 8 || timeleft == 9) { cb.sendNotice(timeleft + ' ...', '', color, white, 'bold'); } else if (timeleft == 10 || timeleft == 20 || timeleft == 30) { cb.sendNotice(timeleft + ' seconds ...', '', color, white, 'bold'); } else if (timeleft == 60) { cb.sendNotice('Only 1 minute left ...', '', color, white, 'bold'); } else if (mincount == 60) { minutes = timeleft/60; cb.sendNotice(minutes + ' minutes left ...', '', color, white, 'bold'); mincount = 0; } timeleft = timeleft - 1; mincount = mincount + 1; } else { cb.sendNotice('\u2605 TIME IS UP! \u2605', '', color, white, 'bold'); } } function printclock() { converttime(); if (hour < 10) { h = 0; } else { h = ''; } if (min < 10) { m = 0; } else { m = ''; } if (sec < 10) { s = 0; } else { s = ''; } cb.sendNotice('\u2605 ' + h + hour + ':' + m + min + ':' + s + sec + ' \u2605', '', color, white, 'bold'); } function converttime() { hour = Math.floor(timeleft/3600); min = Math.floor((timeleft - (hour * 3600))/60); sec = timeleft - (min * 60) - (hour * 3600); } function ping() { } function init() { setcolor(); cb.sendNotice('Type !c for setting commands, ' + cb.room_slug + '!', cb.room_slug, '', '', 'bold'); cb.setTimeout(ping, 1000); } init();
© Copyright Chaturbate 2011- 2026. All Rights Reserved.