Apps Home
|
Create an App
Tip Goal Plus
Author:
smoker919
Description
Source Code
Launch App
Current Users
Created by:
Smoker919
//////////////////////////////////////////////////////////////////////////////// // T I P G O A L P L U S // by Smoker919 // // The original Tip Goal but a little better. Also available as a V2 app. //////////////////////////////////////////////////////////////////////////////// // "smoker919" (case insensitive) shall be identified as the author of this app and any forked or cloned versions of it. // Developers who fork or clone this app, either directly or from another forked or cloned version, may refer to themselves as the maintainers of their versions. // Constants /////////////////////////////////////////////////////////////////// // Do not change this!!! Change the next one instead. const APP_AUTHOR = 'smoker919'; // Change this to give yourself credit for any changes made in your forked version. const APP_MAINTAINER = 'smoker919'; // Change this to your app name in your forked version. const APP_NAME = 'Tip Goal Plus'; /** * Version log: * 1.0.0: Initial port from V2 version (August 27, 2023) */ const APP_VERSION = '1.0.0'; // fonts const BOLD = 'bold'; // misc const ANONYMOUS_USER = 'anonymous user'; const USERNAME_LETTERS = 'abcdefghijklmnopqrstuvwxyz'; // Settings //////////////////////////////////////////////////////////////////// cb.settings_choices = [ { name: 'goal_description', type: 'str', label: 'Goal description' }, { name: 'tokens', type: 'int', label: 'Tokens', minValue: 1 }, { name: 'greeting', type: 'str', label: 'Greeting', required: false }, { name: 'hashtags', type: 'str', label: 'Hashtags', required: false }, { name: 'goal_completed_gif', type: 'str', label: 'Goal completed GIF', defaultValue: ':goalreached666', required: false } ]; // Variables /////////////////////////////////////////////////////////////////// let totalTipped = 0; let lastTip = null; let highestTip = null; // Functions /////////////////////////////////////////////////////////////////// // capitalize the leading letters of all parts of a username, e.g., dakota_ossa -> Dakota_Ossa function capitalizeUsername(username) { return username.split('_') .map(part => { switch (part.length) { case 0: return ''; case 1: return part[0].toUpperCase(); default: return part[0].toUpperCase() + part.substring(1); } }) .join('_'); } function getAttributions() { if (APP_AUTHOR === APP_MAINTAINER) { return capitalizeUsername(APP_AUTHOR); } else { return capitalizeUsername(APP_AUTHOR) + ' (author) and ' + capitalizeUsername(APP_MAINTAINER) + ' (maintainer)'; } } function announceAppStarted() { cb.sendNotice(APP_NAME + ' (v' + APP_VERSION + ') by ' + getAttributions() + ' has started.'); } function announceGoalStarted() { cb.sendNotice('* Goal started: ' + cb.settings.goal_description, '', '', '', BOLD); } function announceGoalCompleted() { let message = '* Goal completed: ' + cb.settings.goal_description; if (cb.settings.goal_completed_gif) { message += '\n' + cb.settings.goal_completed_gif + ' '; } cb.sendNotice(message, '', '', '', BOLD); } function handleTip(username, isAnon, tokens) { if (addTokens(tokens)) { updateSubject(); } updateTipStats(username, isAnon, tokens); cb.drawPanel(); } function addTokens(tokens) { if (totalTipped < cb.settings.tokens) { totalTipped = Math.min(totalTipped + tokens, cb.settings.tokens); if (totalTipped === cb.settings.tokens) { announceGoalCompleted(); } return true; } return false; } function updateTipStats(username, isAnon, tokens) { username = formatUsername(username, isAnon); lastTip = { username: username, amount: tokens }; if (!highestTip || tokens > highestTip.amount) { highestTip = { username: username, amount: tokens }; } } function updateSubject() { let tipsRemaining = Math.max(cb.settings.tokens - totalTipped, 0); let newSubject = cb.settings.goal_description + ' [' + tipsRemaining + (tipsRemaining === 1 ? ' token' : ' tokens') + ' remaining]'; if (cb.settings.greeting) { newSubject = cb.settings.greeting + ' // Goal: ' + newSubject; } if (cb.settings.hashtags) { newSubject += ' ' + cb.settings.hashtags; } console.log('Changing subject to: ' + newSubject); cb.changeRoomSubject(newSubject); } function formatUsername(username, isAnon) { return isAnon ? ANONYMOUS_USER : username.substring(0, 17); } function formatTip(tip) { return tip ? tip.username + ' (' + tip.amount + ')' : '--' } // Handlers //////////////////////////////////////////////////////////////////// function onStartHandler(user) { announceAppStarted(); announceGoalStarted(); updateSubject(); cb.drawPanel(); } function onTipHandler(tip) { handleTip(tip.from_user, tip.is_anon_tip, tip.amount); } function onDrawPanelHandler(user) { return { template: '3_rows_of_labels', row1_label: 'Received / Goal:', row1_value: totalTipped + ' / ' + cb.settings.tokens, row2_label: 'Last Tip:', row2_value: formatTip(lastTip), row3_label: 'Highest Tip:', row3_value: formatTip(highestTip) }; } // Callbacks /////////////////////////////////////////////////////////////////// cb.onStart(onStartHandler); cb.onTip(onTipHandler); cb.onDrawPanel(onDrawPanelHandler)
© Copyright Freesexcam 2011- 2024. All Rights Reserved.