Apps Home
|
Create an App
___zzz
Author:
testgaysian
Description
Source Code
Launch App
Current Users
Created by:
Testgaysian
// vars var last_tipper = null; var next_tip_amount = 1; var total_remaining = 0; var times_goal_reached = 0; var highest_tip = 0; var highest_tipper = null; var tippers = {}; // modifiable vars var sGoal = ""; var nValue = 0; var ticketPrice = 50; // var version = 4 // Limit goal description as we add some text cb.settings_choices = [ { name: 'goal_description', type: 'str', minLength: 1, maxLength: 180 }, { name: 'goal_reached_message', type: 'str', minLength: 1, maxLength: 180, label: "Goal reached message", defaultValue: "Yay!!! We reached the goal! Let's go get tacos!" }, { name: 'goal_value', type: 'int', minValue: 1, maxValue: 100, default: 50 }, { name: 'order', type: 'choice', choice1: 'ascending', choice2: 'descending', default: 'ascending', required: false }, { name: 'tipper_to_show', type: 'choice', choice1: 'last', choice2: 'highest', default: 'last', required: false }, { name: 'ticket_show_price', type: 'int', minValue: 1, maxValue: 1000, defaultValue: 50, label: "Total tokens needed to join the ticket show", required: false}, { name: 'join_show_in_progress', type: 'choice', choice1: 'allow', choice2: "don't allow", default: 'allow', label: "Allow users to join ticket show in progress?", required: false}, { name: 'always_allow_mods', type: 'choice', choice1: 'allow', choice2: "don't allow", default: 'allow', label: "Always allow mods to see the ticket show?", required: false}, { name: 'always_allow_users_list', type: 'str', minLength: 1, maxLength: 180, defaultValue: '', label: "Always allow these users into the ticket show (user1,user2,user3)", required: false } ]; cb.onMessage(function (msg) { if (msg['user'] == cb.room_slug && msg['m'].charAt(0) == '/') { var cmdLine = msg['m'].substring(1).split(' '); var sCmd = cmdLine.shift(); var sArg = cmdLine.join(' '); var bUpdate = false; msg['X-Spam'] = true; //do not show the command switch(sCmd) { case "s": case "subject": if (sArg === null || sArg == "") { notifyModel("The subject you entered was empty. If this was not intended, please try again.", "error"); } else { sGoal = sArg; notifyModel("Great success! The room subject has been changed to: " + sGoal, "success"); bUpdate = true; } break; case "g": case "goal": var val = parseInt(sArg); if (isNaN(val) || val < 1) { notifyModel("The goal value you entered is too low. The goal value has not been changed and remains at: " + nValue + ". Total remaining: " + total_remaining + ".", "error"); } else { nValue = val; if (!getIsAsc() || next_tip_amount > nValue) { next_tip_amount = nValue; } total_remaining = calcTotal(getIsAsc() ? next_tip_amount : 0, nValue); notifyModel("Great success! The goal value has been changed to: " + nValue + ". Total remaining: " + total_remaining + "." , "success"); bUpdate = true; } break; case "reset": reset(); bUpdate = true; break; // ticket show commands - start case "start": if(!cb.limitCam_isRunning()) { var message = 'Ticket show in progress!' + getJoinInProgressMessage(); cb.limitCam_start(message); cb.chatNotice(cb.room_slug + ' has started a ticket show!'); } break; case "stop": if(cb.limitCam_isRunning()) { cb.limitCam_stop(); cb.chatNotice(cb.room_slug + ' has ended the ticket show!'); } break; case "price": var val = parseInt(sArg); if (isNaN(val) || val < 1) { notifyModel("The ticket price value you entered is too low. It is currently: " + ticketPrice + ".", "error"); } else { ticketPrice = val; notifyModel("Great success! The ticket price has been changed to: " + ticketPrice + ".", "success"); } break; case "add": if (!sArg) { notifyModel("Please specify the user you want to allow to see the ticket show.", "error"); } else { cb.limitCam_addUsers([sArg]); notifyModel("Added " + sArg + " to the ticket show guest list.", "success"); } break; case "remove": if (!sArg) { notifyModel("Please specify the user you want to no longer allow to see the ticket show.", "error"); } else if (cbjs.arrayContains(cb.limitCam_allUsersWithAccess(), sArg)) { cb.limitCam_removeUsers([sArg]); notifyModel("Removed " + sArg + " from the ticket show guest list.", "success"); } else { notifyModel(sArg + " did not have a ticket for the show.", "success"); } break; case "listUsers": notifyModel("The following users have access to the ticket show: " + cb.limitCam_allUsersWithAccess().join(", "), "success"); break; // ticket show commands - end default: msg['X-Spam'] = false; //not our command, show it break; } //push changes to room if (bUpdate) { update_subject(); cb.drawPanel(); } } return msg; }); cb.onTip( function (tip) { var diff = tip['amount']; var values = new Array(); var sMsg = "Thank you "; var user = tip['from_user']; var goalsReached = 0; updateTippers(user, diff); // update total tips for this user for ticket mode permission if (diff < next_tip_amount) { cb.sendNotice("Thanks for the tip; if you want to advance the sequence, please tip " + next_tip_amount + " or more.", user); return; } if (diff > highest_tip) { highest_tip = diff; highest_tipper = user; } while (diff > 0) { diff -= next_tip_amount; if (diff >= 0) { values.push(next_tip_amount); goalsReached += setNextTipNeeded(); } } if(tip['amount'] >= 1000) { cb.sendNotice(":1000tips"); } if (values.length > 0) { last_tipper = user; sMsg += last_tipper + "! The last "; update_subject(); if (values.length > 1) { while (values.length > 20) { values.shift(); } sMsg += values.length + " values your tip covered were: " + values.join(", "); } else { sMsg += "value your tip covered was: " + values[0]; } sMsg += ". Total remaing to reach goal: " + total_remaining; cb.sendNotice(sMsg, "", "", "", "bold", ""); cb.drawPanel(); } if (goalsReached > 0) { cb.sendNotice(user + ", you rock!\n" + cb.settings.goal_reached_message, "", "#01DF01", "", "bold"); cb.sendNotice(":leocheers1"); } } ); cb.onDrawPanel( function (user) { return { 'template': '3_rows_of_labels', 'row1_label': 'Next Tip Needed:', 'row1_value': next_tip_amount, 'row2_label': (getShowLast() ? 'Last' : 'Highest') + ' Tip From:', 'row2_value': (getShowLast() ? format_username(last_tipper) : format_username(highest_tipper) + ' (' + highest_tip + ')'), 'row3_label': 'Reached Goal:', 'row3_value': '' + times_goal_reached + ' times' }; } ); cb.onEnter(function(user) { var friends = cb.settings.always_allow_users_list.replace(/\s/g, '').split(','); if ((user['is_mod'] && cb.settings.always_allow_mods === "allow") || cbjs.arrayContains(friends, user['user'])) { cb.limitCam_addUsers([user['user']]); } }); // helper functions function update_subject() { var new_subject = sGoal; new_subject += (getIsAsc() ? " [Tip in ascending order from 1 to " : " [Tip in descending order from ") + nValue + (getIsAsc() ? ". " : " to 0. ") + "Next tip needed: " + next_tip_amount + ". Goal reached " + times_goal_reached + " times.]"; cb.changeRoomSubject(new_subject); } function format_username(val) { if (val === null) { return "--"; } else { return val.substring(0, 14); } } function setNextTipNeeded() { var goalReached = 0; if (getIsAsc()) { if (next_tip_amount >= nValue) { reset(); goalReached = 1; } else { total_remaining -= next_tip_amount; next_tip_amount++; } } else { if (next_tip_amount <= 1) { reset(); goalReached = 1; } else { total_remaining -= next_tip_amount; next_tip_amount--; } } times_goal_reached += goalReached; return goalReached; } function calcTotal(startVal, endValue) { var nTotal = startVal; for (var i = endValue; i > startVal; i--) { nTotal += i; } return nTotal; } function reset() { next_tip_amount = getIsAsc() ? 1 : nValue total_remaining = calcTotal(0, nValue); } function updateTippers(user, tip) { tippers[user] = tippers[user] || 0; tippers[user] += tip; if (tippers[user] >= ticketPrice) { cb.limitCam_addUsers([user]); } } // chat helper function notifyModel(message, status) { cb.sendNotice(message, cb.room_slug, (status === "error" ? "#FF8000" : "#01DF01"), "", "bold"); } // getter functions function getIsAsc() { return (cb.settings.order == 'ascending'); } function getShowLast() { return (cb.settings.tipper_to_show == 'last'); } function getJoinInProgressMessage() { return (cb.settings.join_show_in_progress == 'allow' ? ' Tip at least ' + cb.settings.min_join_tokens + ' tokens to join!' : ''); } function init() { sGoal = cb.settings.goal_description; nValue = cb.settings.goal_value; ticketPrice = cb.settings.ticket_show_price; reset(); update_subject(); } init();
© Copyright Chaturbate 2011- 2025. All Rights Reserved.