Apps Home
|
Create an App
Task Manager Timer
Author:
zashirt
Description
Source Code
Launch App
Current Users
Created by:
Zashirt
/** * App: Timed Action with Extendable Timer * Version: 1.04 * Author: Custom * Date: 14.09.24 */ var actionName = ''; var initialDuration = 0; var extendPricePerMin = 0; var remainingTime = 0; var timer = null; // Start a new action timer function startTimer() { // Clear any existing timer if (timer !== null) { cb.cancelTimeout(timer); } remainingTime = initialDuration; cb.sendNotice('Model starting a timer action "' + actionName + '" for ' + initialDuration + ' seconds.'); // Start the timer function runTimer(); } // Recursive timer function using cb.setTimeout function runTimer() { if (remainingTime > 0) { remainingTime--; // 20 seconds warning if (remainingTime === 20) { cb.sendNotice('Action is about to end in 20 seconds.'); } // 10 seconds warning if (remainingTime === 10) { cb.sendNotice('Action is about to end in 10 seconds.'); } // Set a timeout for the next second timer = cb.setTimeout(runTimer, 1000); } else { cb.sendNotice('Action "' + actionName + '" has ended.'); cb.cancelTimeout(timer); // Clear the timer once the action ends timer = null; // Reset the timer variable } } // Handle tips and extend the timer cb.onTip(function(tip) { var extendSeconds = Math.floor((tip['amount'] / extendPricePerMin) * 60); remainingTime += extendSeconds; cb.sendNotice('Action was extended by ' + extendSeconds + ' seconds. Time left: ' + remainingTime + ' seconds.'); }); // Handle the /actimer command from the model cb.onMessage(function(msg) { if (msg['m'].match(/\/actimer/i)) { // Only the model can run this command if (msg['user'] === cb.room_slug) { var params = msg['m'].split(' '); // Parse command arguments actionName = params[1]; initialDuration = parseInt(params[2]); extendPricePerMin = parseInt(params[3]); // Start the timer startTimer(); msg['X-Spam'] = true; // Prevent command message from showing in chat } else { cb.sendNotice('Only the model can start the timer action.', msg['user'], '#FF0000', '', 'bold'); } } // Handle the /timeleft command else if (msg['m'].match(/\/timeleft/i)) { // Anyone can run this command to check time left cb.sendNotice('Time left for action "' + actionName + '": ' + remainingTime + ' seconds.'); msg['X-Spam'] = true; // Prevent command message from showing in chat } return msg; }); // Initial notice after app loads cb.setTimeout(function() { cb.sendNotice("Type /actimer action-name duration extend-price-per-min to start a timer action! Type /timeleft to check time remaining."); }, 3000);
© Copyright Freesexcam 2011- 2024. All Rights Reserved.