Apps Home
|
My Uploads
|
Create an App
BlueApp
Author:
melezouriou
Description
Source Code
Launch App
Current Users
Created by:
Melezouriou
App Images
//Auto-Reset Tip Goal with Panel // vars var total_tipped = 0; var high_tip_username = null; var high_tip_amount = 0; var subject_is_set_with_0 = false; var times_goal_reached = 0; var last_time_goal_reached = null; var current_goal_tipped = 0; var set_tokens_command = '!settok'; var set_reached_command = '!setreached'; var panelConfig = cb.settings.panelConfig; var imageConfig = cb.settings.imageConfig; var imageSelec = cb.settings.imageSelec; var imageConfigTrue = cb.settings.imageConfigTrue; var row1_LabelText =cb.settings.row1_LabelText; var row1_LabelColor = cb.settings.row1_LabelColor; var row1_Color = cb.settings.row1_Color; var row2_LabelText = cb.settings.row2_LabelText; var row2_LabelColor = cb.settings.row2_LabelColor; var row2_Color = cb.settings.row2_Color; var row3_LabelText = cb.settings.row3_LabelText; var row3_LabelColor = cb.settings.row3_LabelColor; var row3_Color = cb.settings.row3_Color; cb.settings_choices = [ {name: 'tokens', type: 'int', minValue: 1, default: 100}, {name: 'goal_description', type: 'str', minLength: 1, maxLength: 255}, { name: "panelConfig", label:"Panel configuration", type: "choice", choice1:"classic", choice2:"image", defaultValue:"image" },{ name: "imageSelec", label:"Select an image ID.", type: "choice", choice1:"Image ID written in next section", choice2:"3960c2c1-f59e-4351-bfc6-20c6315b7734", choice3:"12faf938-fbba-44d4-8f23-2606ca657aa1", choice4:"9c17a91e-3827-49db-a9b7-ceebb17ebb38", choice5:"abf6ae1d-9ef0-4806-a66e-86065772f0c3", choice6:"cd656aff-14e3-4719-a84c-67fa2293c722", choice7:"a32fbc6d-9f37-4ebf-a114-a3f15e8871ae", choice8:"fa9d87de-dded-4b0e-998a-336c0bb9fa96", choice9:"d3a38bae-74d3-4b47-b838-642829178c60", choice10:"c79059a3-ffce-4139-af4a-ddb7406fac1a", choice11:"30f0a81c-c2da-4050-8cd2-16614cc8704a", defaultValue:"Image ID written in next section", },{ name: "imageConfig", label:"Image Panel configuration, select: Image ID", type: 'str', minLength: 1, maxLength: 50, value: ('cb.settings.imageSelec'), defaultValue:"3960c2c1-f59e-4351-bfc6-20c6315b7734", required: true },{ name: "row1_LabelText", label:"Row1 Label Text, default: Tip Received/Goal (Total)", type: 'str', minLength: 1, maxLength: 26, defaultValue:"Tip Received/Goal (Total):", required: true },{ name: "row1_LabelColor", label:"Color Row1 Label", type: 'str', minLength: 1, maxLength: 50, defaultValue:"black", required: true },{ name: "row1_Color", label:"Row1 Text Color", type: 'str', minLength: 1, maxLength: 50, defaultValue:"black", required: true },{ name: "row2_LabelText", label:"Row2 Label Text, default: Hit Goal For: ", type: 'str', minLength: 1, maxLength: 26, defaultValue:"Hit Goal For:", required: true },{ name: "row2_LabelColor", label:"Row2 Label Color", type: 'str', minLength: 1, maxLength: 50, defaultValue:"black", required: true },{ name: "row2_Color", label:"Row2 Tex Color", type: 'str', minLength: 1, maxLength: 50, defaultValue:"black", required: true },{ name: "row3_LabelText", label:"Row3 Label Text, default: Highest Tip: ", type: 'str', minLength: 1, maxLength: 26, defaultValue:"Highest Tip: ", required: true },{ name: "row3_LabelColor", label:"Row3 Label Color", type: 'str', minLength: 1, maxLength: 50, defaultValue:"black", required: true },{ name: "row3_Color", label:"Row3 Color", type: 'str', minLength: 1, maxLength: 50, defaultValue:"black", required: true }, ]; // handlers if(imageSelec != "Image ID written in next section"){ imageConfigTrue = imageSelec } else { imageConfigTrue = imageConfig }; cb.onTip(function(tip) { total_tipped += tip['amount'] if (total_tipped > cb.settings.tokens) { total_tipped = cb.settings.tokens; } current_goal_tipped += tip['amount'] if (current_goal_tipped >= cb.settings.tokens) { goalReached(tip['from_user']); } update_subject(); if (tip['amount'] > high_tip_amount) { high_tip_amount = tip['amount'] high_tip_username = tip['from_user'] } cb.drawPanel(); }); cb.onDrawPanel(function(user) { /*return { 'template': '3_rows_of_labels', //'row1_label': 'Tip Received / Goal :', 'row1_label': row1_LabelText + ':', 'row1_value': '' + total_tipped + ' / ' + cb.settings.tokens, //'row2_label': 'Hit Goal For:', 'row2_label': row2_LabelText + ':', 'row2_value': " " + times_goal_reached + ' times', //'row3_label': 'Highest Tip:', 'row3_label': row3_LabelText + ':', 'row3_value': " " + format_username(high_tip_username) + ' (' + high_tip_amount + ')', //'row3_label': 'Highest Tip:' }; }); */ if (cb.settings.panelConfig == "image"){ return { "template": "image_template", "layers": [ {'type': 'image', 'fileID': imageConfigTrue}, { 'type': 'text', 'text': row1_LabelText, 'top': 5, 'left': 10, 'font-size': 11, //'text-align': 'center', 'font-weight': 'bold', 'color': row1_LabelColor, }, { 'type': 'text', 'text': row2_LabelText, 'top': 29, 'left': 10, 'font-size': 11, //'text-align': 'center', 'font-weight': 'bold', 'color': row2_LabelColor, }, { 'type': 'text', 'text': row3_LabelText, 'top': 52, 'left': 10, 'font-size': 11, //'text-align': 'center', 'font-weight': 'bold', 'color': row3_LabelColor, },{ 'type': 'text', 'text': '' + current_goal_tipped + ' / ' + cb.settings.tokens + ' (' + ((times_goal_reached * cb.settings.tokens) + current_goal_tipped) + ')', 'top': 5, 'left': 147, 'font-size': 11, //'text-align': 'center', 'font-weight': 'bold', 'color': row1_Color, }, { 'type': 'text', 'text': " " + times_goal_reached + ' times', 'top': 29, 'left': 147, 'font-size': 11, //'text-align': 'center', 'font-weight': 'bold', 'color': row2_Color, }, { 'type': 'text', 'text': " " + format_username(high_tip_username) + ' (' + high_tip_amount + ')', 'top': 52, 'left': 147, 'font-size': 11, //'text-align': 'center', 'font-weight': 'bold', 'color': row3_Color, }, ], }; } }); cb.drawPanel(); cb.onMessage(function (msg) { if (msg['m'][0] == '!') { if (msg['user'] == cb.room_slug) { if (startsWith(msg['m'], set_tokens_command)) { msg['X-Spam'] = true; var number = msg['m'].slice(set_tokens_command.length); times_goal_reached = Math.floor(number / cb.settings.tokens); current_goal_tipped = number % cb.settings.tokens; last_time_goal_reached = new Date(); cb.drawPanel(); cb.chatNotice('The tokens received has been updated!', msg['user']); } else if (startsWith(msg['m'], set_reached_command)) { msg['X-Spam'] = true; var number = msg['m'].slice(set_reached_command.length); times_goal_reached = number; last_time_goal_reached = new Date(); current_goal_tipped = 0; cb.drawPanel(); cb.chatNotice('The number of times reached has been updated!', msg['user']); } } } }); // helper functions function update_subject() { if (tips_remaining() == 0) { if (subject_is_set_with_0) { return; } subject_is_set_with_0 = true; } else { subject_is_set_with_0 = false; } var new_subject = cb.settings.goal_description + " [" + tips_remaining() + " tokens remaining]"; cb.log("Changing subject to: " + new_subject); cb.changeRoomSubject(new_subject); } function tips_remaining() { var r = cb.settings.tokens - total_tipped; if (r < 0) { return 0; } else { return r; } } function format_username(val) { if (val === null) { return "--"; } else { return val.substring(0, 12); } } function refresh() { cb.log("Refresh called"); cb.setTimeout(refresh, 20000); cb.drawPanel(); } function update_subject() { var new_subject = cb.settings.goal_description + " [" + tips_remaining() + " tokens remaining]"; cb.log("Changing subject to: " + new_subject); cb.changeRoomSubject(new_subject); } function goalReached(userName) { last_time_goal_reached = new Date(); var curr_times_reached = Math.floor(current_goal_tipped / cb.settings.tokens); for (var i = 0; i < curr_times_reached; i++) { times_goal_reached++; current_goal_tipped -= cb.settings.tokens; cb.chatNotice("Goal was reached for the " + getNumberString(times_goal_reached) + " time!"); cb.chatNotice('The user ' + userName + ' has reached the goal.', cb.room_slug, "#FEF9CD", "#1A1AD7", "bold"); } } function getNumberString(number) { var numberString = null; var lastChar = String(number).charAt(String(number).length - 1); if ((lastChar == '1') && ((number % 100) != 11)) { numberString = number + "st"; } else if ((lastChar == '2') && ((number % 100) != 12)) { numberString = number + "nd"; } else if ((lastChar == '3') && ((number % 100) != 13)) { numberString = number + "rd"; } else { numberString = "" + number + "th"; } return (numberString); } function tips_remaining() { var r = cb.settings.tokens - current_goal_tipped; if (r < 0) { return 0; } else { return r; } } function startsWith(source, str) { return source.substring(0, str.length) === str; } function init() { update_subject(); } init(); cb.setTimeout(refresh, 20000);
© Copyright Chaturbate 2011- 2025. All Rights Reserved.