Apps Home
|
Create an App
test tip goal king plus app
Author:
ceromus
Description
Source Code
Launch App
Current Users
Created by:
Ceromus
/* * Title: Tip Goal King + * Author: Reneestatic & NinjaPervs * Version: 1.1.2 6/30/2018 * Description: Dynamic tip goal app with "Tip King" and "Dynamic Goal Changing" */ var totalTips = 0; var kingList = []; //Whether or not the goal is currently enabled var enabled = true; var tipsTowardsCurrentGoal = 0; var subject_is_set_with_0 = false; cb.settings_choices = [ { name: 'tokens', type: 'int', minValue: 1, default: 100, label: 'Amount of Tokens for Goal' }, { name: 'goal_description', type: 'str', minLength: 1, maxLength: 255, label: 'Goal Description' }, { name: 'hashtags', type: 'str', minLength: 2, maxLength: 255, label: 'Hashtags' }, { name: 'tipper_prefix', type: 'str', minLength: 1, maxLength: 35, defaultValue: 'King', label: 'What should we call your king?' }, { name: 'tipper_crown', type: 'choice', label: 'King Crown', choice1: 'reneecrown4', choice2: 'pinkpoopcrown', defaultValue: 'reneecrown4' }, { name: 'timer', type: 'choice', choice1: 1, choice2: 2, choice3: 3, choice4: 4, choice5: 5, choice6: 6, choice7: 8, choice8: 10, choice9: 12, choice10: 15, choice11: 20, choice12: 30, choice13: 'Never', defaultValue: 6, label: 'King Display frequency (mins)' }, ]; // handlers cb.onTip(function(tip) { onTip(tip['amount'], tip['from_user']); }); cb.onDrawPanel(function(user) { var currentKing = null; var currentKingTips = 0; if (getKing() != undefined) { currentKing = getKing().name; currentKingTips = getKing().tokens; } var goal = tipsTowardsCurrentGoal + ' / ' + cb.settings.tokens; if (tipsRemaining() == 0) { goal = "Goal Reached"; } if (!enabled) { goal = "No Current Goal..." } return { 'template': '3_rows_of_labels', 'row1_label': 'Tips Received / Goal :', 'row1_value': goal, 'row2_label': cb.room_slug +'\'s ' + cb.settings.tipper_prefix + ':', 'row2_value': formatUsername(currentKing) + ' (' + currentKingTips + ')', 'row3_label': 'Tips Received This Show:', 'row3_value': totalTips }; }); cb.onMessage(function (msg) { if (msg['user'] == cb.room_slug && msg['m'].charAt(0) == '!' && msg['m'].length != 1) { var split = msg['m'].split(" "); var command = split[0].substring(1); split.shift(); onCommand(command, split); msg['X-Spam'] = true; } if (getKing() != undefined && msg['user'] == getKing().name) { msg['background'] = '#3deae8'; msg['m'] = ':' + cb.settings.tipper_crown + ' ' + msg['m']; } return msg; }); cb.onEnter(function (user) { for (var i = 0; i < kingList.length; i++) { if (kingList[i].name == user['user']) { kingList[i].online = true; break; } } cb.drawPanel(); }); cb.onLeave(function (user) { for (var i = 0; i < kingList.length; i++) { if (kingList[i].name == user['user']) { kingList[i].online = false; break; } } cb.drawPanel(); }); //On Command function onCommand(command, args) { switch(command.toLowerCase()) { case 'sendtesttip': if (args.length == 0 || args.length > 2) { cb.sendNotice("Invalid arguments...", cb.room_slug, '#ffffff', 'bold'); break; } if (args.length == 1) { onTip(parseInt(args[0]), cb.room_slug); cb.sendNotice("Sent " + args[0] + " test tips", cb.room_slug, '#ffffff', 'bold'); } if (args.length == 2) { onTip(parseInt(args[0]), args[1]); cb.sendNotice("Sent " + args[0] + " test tips in the name of " + args[1], cb.room_slug, '#ffffff', 'bold'); } break; case 'changegoal': if (args.length < 2) { cb.sendNotice("Invalid arguments...", cb.room_slug, '#ffffff', 'bold'); break; } cb.settings.tokens = args[0]; args.shift(); cb.settings.goal_description = args.join(" "); tipsTowardsCurrentGoal = 0; updateSubject(); cb.drawPanel(); cb.sendNotice("New Goal Set", cb.room_slug, '#ffffff', 'bold'); break; case 'enable': enabled = true; cb.sendNotice("Tip Goal Paused", cb.room_slug, '#ffffff', 'bold'); updateSubject(); cb.drawPanel(); break; case 'disable': enabled = false; cb.sendNotice("Tip Goal disabled", cb.room_slug, '#ffffff', 'bold'); updateSubject(); cb.drawPanel(); break; case 'sethashtags': args.shift(); if (args.length == 0) { cb.settings.hashtags = ""; updateSubject(); cb.drawPanel(); break; } cb.settings.hashtags = args.join(" "); updateSubject(); cb.drawPanel(); cb.sendNotice("New Hashtags Set", cb.room_slug, '#ffffff', 'bold'); break; default: cb.sendNotice("Unknown Command", cb.room_slug, '#ffffff', 'bold'); break; } } //On Tip Function function onTip(amount, user) { var currentKing = null; if (getKing() != undefined) { currentKing = getKing().name; } // Add towards goal if (enabled) { tipsTowardsCurrentGoal += amount if (tipsTowardsCurrentGoal > cb.settings.tokens) { tipsTowardsCurrentGoal = cb.settings.tokens; } } totalTips += amount //Add to total tips updateSubject(); if (user == cb.room_slug) { cb.drawPanel(); return; } var found = false; // Update tipper for (var i = 0; i < kingList.length; i++) { if (kingList[i].name == user) { kingList[i].tokens += amount; found = true; break; } } // Add a new one if (!found) kingList.push({ name: user, tokens: amount, online: true }); // Sort the array kingList.sort(function(a, b) { return b.tokens - a.tokens; }); cb.drawPanel(); if (currentKing != getKing().name) { cb.sendNotice(':' + cb.settings.tipper_crown + ' ' + getKing().name + ' is ' + cb.room_slug +'\'s new ' + cb.settings.tipper_prefix + '! Tip to attempt to take their throne.','','#3deae8','normal'); } } function updateSubject() { if (tipsRemaining() == 0) { if (subject_is_set_with_0) { return; } subject_is_set_with_0 = true; } else { subject_is_set_with_0 = false; } var remaining = tipsRemaining() + " tokens remaining"; if (tipsRemaining() == 0) { remaining = "Goal Reached"; } var new_subject = ""; if (enabled) { new_subject = cb.settings.goal_description + " [" + remaining + "] "; } new_subject += cb.settings.hashtags; cb.log("Changing subject to: " + new_subject); cb.changeRoomSubject(new_subject); } function tipsRemaining() { var r = cb.settings.tokens - tipsTowardsCurrentGoal; if (r < 0) { return 0; } else { return r; } } function formatUsername(val) { if (val === null) { return "--"; } else { return val.substring(0, 12); } } function announceKing() { var msgRoom = ''; if (cb.settings.timer == 'Never') return; if (getKing() != undefined) { msgRoom = ':' + cb.settings.tipper_crown + ' ' + getKing().name + ' is currently ' + cb.room_slug +'\'s ' + cb.settings.tipper_prefix + '! Tip to attempt to take their throne.'; } else { msgRoom = 'No ' + cb.settings.tipper_prefix + ' yet! Tip now and become ' + cb.room_slug +'\'s ' + cb.settings.tipper_prefix + '!'; } cb.sendNotice(msgRoom,'','#3deae8','normal'); cb.setTimeout(announceKing, (cb.settings.timer * 60000)); } function getKing() { var king = undefined; for (i = 0; i < kingList.length; i++) { if (kingList[i].online) { king = kingList[i]; break; } } return king; } /* * Setting up the bot at start */ function init() { updateSubject(); announceKing(); } init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.