Apps Home
|
Create an App
tiptimer
Author:
test01
Description
Source Code
Launch App
Current Users
Created by:
Test01
var timeLeft = 0; var timerState = 'stopped'; var timerID; cb.settings_choices = [ {name:'action_title', type:'str', maxLength: 1000, label: 'Action Title'}, {name:'min_tip_amount', type:'int', minValue:1, maxValue:99999, default:1, label: 'Minimum tip amount for timer'}, {name:'seconds_per_tip_amount', type:'int', minValue:1, maxValue:99999, default:10, label: 'Seconds Added Per Tip Minimum'}, {name:'tip_bonus_min', type:'int', minValue:0, maxValue:9999, default:0, required:false, label: 'Minimum tip for a bonus'}, {name:'bonus_seconds', type:'int', minValue:0, maxValue:9999, default:0, required:false, label: 'Extra seconds per bonus'}, {name:'periodic_message', type:'str', maxLength:1000, required:false, label: 'Periodic Message'}, {name:'message_frequency', type:'int', minValue:1, maxValue:10, required:false, label: 'Message Frequency (minutes)'}, ]; function periodicMessage(){ var msg = cb.settings.periodic_message + ' For every ' + cb.settings.min_tip_amount + ' tips, ' + cb.settings.seconds_per_tip_amount + ' seconds will be added to the timer.'; if(cb.settings.tip_bonus_min > 0){ msg += '\n A bonus ' + cb.settings.bonus_seconds + ' seconds will be added for every ' + cb.settings.tip_bonus_min + ' tips.' } if(timeLeft > 0){ var time1 = Math.floor(timeLeft / 60); var time2 = timeLeft - (time1 * 60); var disp1; var disp2; if(time1 < 10){ disp1 = '0' + time1.toString(); } else{ disp1 = time1.toString(); } if(time2 < 10){ disp2 = '0' + time2.toString(); } else{ disp2 = time2.toString(); } msg += ' Only ' + disp1 + ':' + disp2 + ' left on the clock!'; } cb.sendNotice(msg, "", '#9966ff', '#ffffff'); cb.setTimeout(periodicMessage, (cb.settings.message_frequency * 60000)); } if(cb.settings.periodic_message != 0){ periodicMessage(); } cb.onEnter(function(user) { if(cb.settings.periodic_message != 0){ var msg = 'Welcome ' + user['user'] + '! Keep the timer going! \n Every ' + cb.settings.min_tip_amount + ' tips will add ' + cb.settings.seconds_per_tip_amount; if(cb.settings.tip_bonus_min > 0){ msg += ', \n and for every ' + cb.settings.tip_bonus_min + ' tips, a bonus ' + cb.settings.bonus_seconds + ' will be added to the timer!'; } else{ msg += '!'; } cb.sendNotice(msg, user['user'], '#9966ff', '#ffffff'); } }); cb.onTip(function(tip) { if(tip['amount'] >= cb.settings.min_tip_amount){ var timeToAdd = 0; if(tip['amount'] > cb.settings.min_tip_amount){ timeToAdd += (Math.floor(tip['amount'] / cb.settings.min_tip_amount) * cb.settings.seconds_per_tip_amount); if(tip['amount'] >= cb.settings.tip_bonus_min){ if(tip['amount'] > cb.settings.tip_bonus_min){ timeToAdd += (Math.floor(tip['amount'] / cb.settings.tip_bonus_min) * cb.settings.bonus_seconds); } else{ timeToAdd += cb.settings.bonus_seconds; } } } else{ timeToAdd += cb.settings.seconds_per_tip_amount; } if(timeToAdd > 0){ if(timeLeft <= 0){ timeLeft += timeToAdd; } else{ timeLeft += timeToAdd; } } } cb.drawPanel(); }); function updateTime(){ timeLeft = timeLeft - 1; if(timeLeft > 0){ if(timerState == 'started'){ timerID = cb.setTimeout(updateTime, 1000); } } else{ timeLeft = 0; timerState = 'stopped'; } cb.drawPanel(); } cb.onDrawPanel(function (user) { var time1 = Math.floor(timeLeft / 60); var time2 = timeLeft - (time1 * 60); var disp1; var disp2; if(time1 < 10){ disp1 = '0' + time1.toString(); } else{ disp1 = time1.toString(); } if(time2 < 10){ disp2 = '0' + time2.toString(); } else{ disp2 = time2.toString(); } var label1 = disp1 + ':' + disp2; if(timerState == 'stopped'){ label1 += ' (paused)'; } var msg1 = 'For every ' + cb.settings.min_tip_amount + ' tips, ' + cb.settings.seconds_per_tip_amount + ' seconds will be added to the timer.'; var msg2; if(cb.settings.tip_bonus_min > 0){ msg2 = ' A bonus ' + cb.settings.bonus_seconds + ' seconds will be added for every ' + cb.settings.tip_bonus_min + ' tips.' } return { 'template':'3_rows_12_21_31', 'row1_label':'Time Remaining:', 'row1_value': label1, 'row2_value': msg1, 'row3_value': msg2 }; }); cb.onMessage(function (msg) { if (msg['user'] == cb.room_slug) { if (msg['m'] == '/start') { msg['X-Spam'] = true; if(timerState == 'started'){ if(timerID != null){ cb.cancelTimeout(timerID); } } timerState = 'started'; updateTime(); } else if(msg['m'] == '/pause' || msg['m'] == '/stop'){ msg['X-Spam'] = true; if(timerState == 'started'){ timerState = 'stopped'; } if(timerID != null){ cb.cancelTimeout(timerID); } } else{ if(msg['m'].length > 3){ if(msg['m'].substring(0, 4) == '/add'){ msg['X-Spam'] = true; var val = parseInt(msg['m'].substring(5)); if(val > 0){ timeLeft += val; } } } } } cb.drawPanel(); });
© Copyright Chaturbate 2011- 2024. All Rights Reserved.