Apps Home
|
Create an App
Autumn's Progress Multi-Goal
Author:
autumnsapps
Description
Source Code
Launch App
Current Users
Created by:
Autumnsapps
// ================= Unity Goal Tracker ==================== // Author: Alipaeillee // Room: https://chaturbate.com/alipaeillee/ // Version: 1.01 // Summary: Goal management // Updated: 8/10/2015 // Description: /*This goal tracker is built to be very simple. It has only a few settings that are set through chat commands. Type /goal to see all the available commands. Features: * Adding tokens to the tip counter, e.g. if your goal is moving too slowly and you want to help it move along. * Slightly animated panel, to hopefully make the goal tracking more interesting. * Adding a new goal quickly and at any time. * Displays bonus pool tokens; tokens that are tipped after the goal has been hit The goal should be a simple statement of what you're going to do and shouldn't include the token goal. (The way the goal is formatted in the code is: "{Goal description} @ {Token goal} tkns")*/ // ================================================================ var goal = "" var goal_tokens = 0; var tips = 0; var progress = 0; // Percent of goal completed var goalInProgress = true; var silent = false; var broadcaster = cb.room_slug; var animation = { enabled: true, state: 0, next: function() { this.state = this.state ? 0 : 1; } }; var en = { help: 'Available options:\n' + '/goal set <tokens> <description>\n' + '/goal stealth - Toggle on to disable notifying the room when you move the tip count up\n' + '/goal animation - Toggle off to disable the progress bar animation\n' + '/goal add <tokens>', missing: { set: 'Goal description missing', tokens: 'Token parameter missing' }, invalid: { tokens: 'Token parameter was not a number!' }, notice: { tip: 'Thanks {0}!\n We\'re now {1} tokens from hitting our goal!', newGoal: '{0} has set a new goal: {1} @ {2} tkns', goalHit: '------------------------ GOAL REACHED ------------------------\n' + 'Thank you {0}!', bonusTip: 'Thank you {0} for adding {1} tokens to the bonus pool!', silenceOn: 'The room will not be notified on /goal add commands', silenceOff: 'The room will be notified on /goal add commands', broadcasterTipChange: '{0} moved the token count {1} tokens closer to our goal!', broadcasterHitGoal: '{0} completed the goal!', animationOn: 'Progress bar animation enabled', animationOff: 'Progress bar animation disabled' } }; cb.onDrawPanel(function(user) { if (goal == "") { return { 'template': '3_rows_11_21_31', 'row1_value': '\u00a0', 'row2_value': 'Waiting for goal', 'row3_value': '\u00a0' } } else if(tips < goal_tokens) { if (animation.state) { return { 'template': '3_rows_11_21_31', 'row1_value': '{0} @ {1} tkns'.format(goal, numberWithCommas(goal_tokens)), 'row2_value': '\u00a0', 'row3_value': '{0} {1}%'.format(ProgressBarString(progress), progress) } } else { return { 'template': '3_rows_11_21_31', 'row1_value': '{0} @ {1} tkns'.format(goal, numberWithCommas(goal_tokens)), 'row2_value': '\u00a0', 'row3_value': '{0} {1}%'.format(ProgressBarString(progress), progress) } } } else { return { 'template': '3_rows_11_21_31', 'row1_value': 'Goal Achieved:', 'row2_value': goal, 'row3_value': '{0} {1}%'.format(ProgressBarString(progress), progress) } } }); cb.onTip(function (tip) { var from = tip['from_user']; tips += tip['amount']; progress = parseInt((tips/goal_tokens)*100); cb.drawPanel(); if (goalInProgress) { // Send a message when we hit our goal if ((goal_tokens - tips) <= 0) { cb.sendNotice(en.notice.goalHit.format(from), '', '', '#30a13d', 'bolder'); goalInProgress = false; } else { // Otherwise just a normal tip message! cb.sendNotice(en.notice.tip.format(from, numberWithCommas(goal_tokens - tips)), '', '', '#1487F5', 'bold'); } } else { cb.sendNotice(en.notice.bonusTip.format(from, numberWithCommas(tip['amount'])), '', '', '#30a13d', 'bolder'); } }); cb.onMessage(function (msg) { if (msg['user'] == broadcaster && Has(msg['m'], '/goal')) { var cmds = msg['m'].split(' '); msg['X-Spam'] = true; switch(cmds[1]) { case undefined: Notify(en.help); break; case 'set': if (cmds[2] == undefined) { Notify(en.missing.tokens, 'red'); break; } if (isNaN(cmds[2])) { Notify(en.invalid.tokens, 'red'); break; } if (cmds[3] == undefined) { Notify(en.missing.set, 'red'); break; } goal_tokens = cmds[2]; goal = cmds.splice(3).join(' '); tips = 0; progress = 0; goalInProgress = true; cb.drawPanel(); cb.sendNotice(en.notice.newGoal.format(broadcaster, goal, goal_tokens), '', '', '#368218', 'bold'); break; case 'add': if (!goalInProgress) break; if (cmds[2] == undefined) { Notify(en.missing.tokens, 'red'); break; } if (isNaN(cmds[2])) { Notify(en.invalid.tokens, 'red'); break; } tips += parseInt(cmds[2]); progress = parseInt((tips/goal_tokens)*100); cb.drawPanel(); // Check that we're allowed to notify the room if (!silent) cb.sendNotice(en.notice.broadcasterTipChange.format(broadcaster, cmds[2]), '', '', '#368218', 'bold'); // Notify the room if the host has added enough tokens to hit their goal if ((goal_tokens - tips) <= 0) { cb.sendNotice(en.notice.broadcasterHitGoal.format(broadcaster), '', '', '#30a13d', 'bolder'); goalInProgress = false; } break; case 'stealth': silent = silent ? false : true; silent ? Notify(en.notice.silenceOn, 'red') : Notify(en.notice.silenceOff, 'green'); break; case 'animation': animation.enabled = animation.enabled ? false : true; animation.enabled ? Notify(en.notice.animationOn, 'green') : Notify(en.notice.animationOff, 'red'); if (animation.enabled) { cb.setTimeout(TemplateTimer, 5000); } else { animation.state = 0; cb.drawPanel(); } break; } } return msg; }); function ProgressBarString(percentInt) { var fillSymbol = '\u2588'; var voidSymbol = '\u2592'; var fillCount = parseInt(10 * (percentInt/100)); var voidCount = 10 - (fillCount); var outputString = ''; for (var i = 0; i < fillCount; i++) { outputString += fillSymbol; } for (var i = 0; i < voidCount; i++) { outputString += voidSymbol; } return outputString; } function TemplateTimer() { if (animation.enabled) { animation.next(); cb.drawPanel(); cb.setTimeout(TemplateTimer, 5000); } } cb.setTimeout(TemplateTimer, 5000); // Helper functions String.prototype.format = String.prototype.f = function() { var s = this, i = arguments.length; while (i--) { s = s.replace(new RegExp('\\{' + i + '\\}', 'gm'), arguments[i]); } return s; }; function Has(text, search) { return text.search(search) != -1 ? true : false; } function Notify(text, color) { var style; var styleWeight; switch(color) { case 'red': style = '#FF0000'; styleWeight = 'bolder'; break; case 'green': style = '#368218'; styleWeight = 'bolder'; break; default: style = ''; styleWeight = ''; } cb.sendNotice(text, cb.room_slug, '', style, styleWeight); } // Thank you Kerry & Elias Zamaria // http://stackoverflow.com/a/2901298 function numberWithCommas(x) { return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }
© Copyright Chaturbate 2011- 2025. All Rights Reserved.