Apps Home
|
Create an App
Harper's Workout Menu
Author:
harperthefox
Description
Source Code
Launch App
Current Users
Created by:
Harperthefox
// Tip Menu App by Juirrl // Based on Tip Menu by FayNight V.1.0 // 7-11-14 // Variables var total_tips = 0; var goal_tips = 0; var last_tipper = null; var last_tip = 0; var ht_username = null; var ht_amount = 0; var goal = 0; var tipper_array = new Object(); // Apparently tipper_array is not an array. var menu_string = ""; var leaderboard_string = ""; var leaderboard_outofdate = true; var leader_color = '#CCFF99'; var color_codes = { orange:'#FFCC66', green:'#CCFF99', purple:'#E6CCFF', blue:'#99FFFF', yellow:'#FFFF99', none:'', crown:'' }; // Settings cb.settings_choices = [{ name: 'goal', type: 'int', minValue: 0, defaultValue: 100, label: "Goal Amount (Set to 0 to Disable)" }, { name: 'reset', type: 'choice', choice1: 'Yes', choice2: 'No', label: "Reset the Goal when it is Met?" }, { name: 'goalAd', type: 'str', minLength: 0, MaxLength: 300, label: "Goal Description. Will automatically post in chat when Goal is reached (Optional)", required: false }, { name: 'item1', type: 'str', minLength: 1, maxLength: 30, label: "Menu Item 1 (required)" }, { name: 'price1', type: 'int', minValue: 0, defaultValue: 10, label: "Item 1 Price (required)" }, { name: 'item2', type: 'str', minLength: 1, maxLength: 50, label: "Menu Item 2 (required)" }, { name: 'price2', type: 'int', minValue: 0, defaultValue: 20, label: "Item 2 Price (required)" }, { name: 'item3', type: 'str', minLength: 1, maxLength: 50, label: "Menu Item 3", required: false }, { name: 'price3', type: 'int', minValue: 0, label: "Item 3 Price", required: false }, { name: 'item4', type: 'str', minLength: 1, maxLength: 50, label: "Menu Item 4", required: false }, { name: 'price4', type: 'int', minValue: 0, label: "Item 4 Price", required: false }, { name: 'item5', type: 'str', minLength: 1, maxLength: 50, label: "Menu Item 5", required: false }, { name: 'price5', type: 'int', minValue: 0, label: "Item 5 Price", required: false }, { name: 'item6', type: 'str', minLength: 1, maxLength: 50, label: "Menu Item 6", required: false }, { name: 'price6', type: 'int', minValue: 0, label: "Item 6 Price", required: false }, { name: 'item7', type: 'str', minLength: 1, maxLength: 50, label: "Menu Item 7", required: false }, { name: 'price7', type: 'int', minValue: 0, label: "Item 7 Price", required: false }, { name: 'item8', type: 'str', minLength: 1, maxLength: 50, label: "Menu Item 8", required: false }, { name: 'price8', type: 'int', minValue: 0, label: "Item 8 Price", required: false }, { name: 'item9', type: 'str', minLength: 1, maxLength: 50, label: "Menu Item 9", required: false }, { name: 'price9', type: 'int', minValue: 0, label: "Item 9 Price", required: false }, { name: 'item10', type: 'str', minLength: 1, maxLength: 50, label: "Menu Item 10", required: false }, { name: 'price10', type: 'int', minValue: 0, label: "Item 10 Price", required: false }, { name: 'chat_ad', type: 'int', minValue: 0, maxValue: 999, defaultValue: 10, label: 'Advertise Menu in Chat Every _____ Mins (Set 0 to Disable)' }, { name: 'defaultHTcolor', type: 'choice', choice1: 'blue', choice2: 'green', choice3: 'orange', choice4: 'purple', choice5: 'yellow', choice6: 'none', choice7: 'crown', label: "Background color for high tipper", defaultValue: 'green' }, { name: 'modControl', type: 'choice', choice1: 'No', choice2: 'Yes', label: "Room mods can control app", defaultValue: 'No' }, { name: 'requests', type: 'choice', choice1: 'Yes', choice2: 'No', label: "Be notified when a user requests /menu" } ]; // Handlers cb.onTip(function (tip) { total_tips += tip['amount']; goal_tips += tip['amount']; leaderboard_outofdate = true; for (var i = 0; i <= listMenu.length; i++) { if (eval('tip[\'amount\'] === cb.settings.price' + i)) { eval('cb.sendNotice(cb.settings.item' + i + ',\'\',\'#99FFFF\')'); } } update_app(); last_tip = tip['amount']; last_tipper = tip['from_user']; if (! (tip['from_user'] in tipper_array) ) { tipper_array[tip['from_user']] = 0; } tipper_array[tip['from_user']] += tip['amount']; if (ht_username === tip['from_user']) { ht_amount += tip['amount']; cb.sendNotice('High tip total is now ' + ht_amount + '!','',color_codes[cb.settings.defaultHTcolor]); } else { if (tipper_array[tip['from_user']] > ht_amount) { ht_amount = tipper_array[tip['from_user']]; ht_username = tip['from_user']; cb.sendNotice('New high tipper! ' + capitaliseFirstLetter(ht_username) + ' with ' + ht_amount + ' tokens!', '', color_codes[cb.settings.defaultHTcolor]); leader_color = cb.settings.defaultHTcolor; } } cb.drawPanel(); }); // Chat Commands cb.onMessage(function (msg) { // Perhaps I should set a variable to the first word or two and change all these ifs to one switch statement var index; if(msg['m'].charAt(0) == '/') { //don't print this message to chat msg['X-Spam'] = true; } else { if (msg['user'] == ht_username) { if ( leader_color == 'crown' ) { msg['m'] = ':smallCrown ' + msg['m']; } msg['background'] = color_codes[leader_color]; } return msg; } if (msg['m'] == '/menu') { drawMenu(msg['user']); if (msg['user'] != cb.room_slug) { if (cb.settings.requests === "Yes") { cb.sendNotice(capitaliseFirstLetter(msg['user']) + ' requested the menu.', cb.room_slug) } } } if (msg['m'] == '/commands' && msg['user'] ) { drawCommands(msg['user'], msg['is_mod']); } if (msg['m'] == '/showmenu' && ( msg['user'] == cb.room_slug || ( msg['is_mod'] && cb.settings.modControl == 'Yes' ) ) ) { drawMenu(); } if (msg['m'] == '/goal reset' && ( msg['user'] == cb.room_slug || ( msg['is_mod'] && cb.settings.modControl == 'Yes' ) ) ) { reset_goal(); } if (msg['m'] == '/show ad' && ( msg['user'] == cb.room_slug || ( msg['is_mod'] && cb.settings.modControl == 'Yes' ) ) ) { showAd(); } if (msg['m'] == '/goal off' && ( msg['user'] == cb.room_slug || ( msg['is_mod'] && cb.settings.modControl == 'Yes' ) ) ) { cb.sendNotice('Goal disabled, type /menu to see other foxy options.'); goal += 1; goal_tips = cb.settings.goal; cb.drawPanel(); } if (msg['m'].substr(0,9) == '/disable ' && ( msg['user'] == cb.room_slug || ( msg['is_mod'] && cb.settings.modControl == 'Yes' ) ) ) { index = Number(msg['m'].substr(9)); if (index > 0 && index < 11) { eval('cb.settings.price' + index + ' = undefined'); cb.sendNotice('Menu option '+ index + ' has been deleted, type /menu to see current menu.'); update_menu(); } } if (msg['m'].substr(0,8) == '/enable ' && ( msg['user'] == cb.room_slug || ( msg['is_mod'] && cb.settings.modControl == 'Yes' ) ) ) { index = Number(msg['m'].substr(8, 2)); if (index > 0 && index < 11) { var cut_str = msg['m'].substr(8); cut_str = cut_str.substr(cut_str.search(' ') + 1); var amount = Number(cut_str.substr(0, cut_str.search(' '))); var activity = cut_str.substr(cut_str.search(' ') + 1); if (amount > 0 && activity !== undefined) { eval('cb.settings.price' + index + ' = amount'); eval('cb.settings.item' + index + ' = activity'); cb.sendNotice('Menu option ' + index + ' has been added, type /menu to see current menu.'); update_menu(); } } } if (msg['m'].substr(0,13) == '/goal amount ' && ( msg['user'] == cb.room_slug || ( msg['is_mod'] && cb.settings.modControl == 'Yes' ) ) ) { index = Number(msg['m'].substr(13)); if (index > 0) { cb.settings.goal = index; cb.drawPanel(); cb.sendNotice('Goal amount changed to ' + index + ' tokens.'); update_app(); } } if (msg['m'].substr(0,10) == '/goal set ' && ( msg['user'] == cb.room_slug || ( msg['is_mod'] && cb.settings.modControl == 'Yes' ) ) ) { cb.settings.goalAd = index = msg['m'].substr(10); cb.drawPanel(); cb.sendNotice('Reward for reaching goal changed to ' + cb.settings.goalAd); update_app(); } if (msg['m'].substr(0,10) == '/ad timer ' && ( msg['user'] == cb.room_slug || ( msg['is_mod'] && cb.settings.modControl == 'Yes' ) ) ) { index = Number(msg['m'].substr(10)); if (index > 0) { cb.settings.chat_ad = index; cb.setTimeout(chatAd, (cb.settings.chat_ad * 60000)); cb.sendNotice('Ad timer set to ' + index + ' minutes', msg['m']); } } if (msg['m'] == '/goal reset toggle' && ( msg['user'] == cb.room_slug || ( msg['is_mod'] && cb.settings.modControl == 'Yes' ) ) ) { goalResetToggle(msg['user']); } if (msg['m'] == '/notify toggle' && ( msg['user'] == cb.room_slug || ( msg['is_mod'] && cb.settings.modControl == 'Yes' ) ) ) { notificationToggle(msg['user']); } if (msg['m'] == '/mod toggle' && ( msg['user'] == cb.room_slug || ( msg['is_mod'] && cb.settings.modControl == 'Yes' ) ) ) { modToggle(msg['user']); } if (msg['m'] == '/leaderboard') { drawLeaderboard(msg['user']); } if (msg['m'].substr(0,7) == '/color ' && ( ( msg['user'] == cb.room_slug || ( msg['is_mod'] && cb.settings.modControl == 'Yes' ) ) || msg['user'] == ht_username ) ) { setLeaderColor(msg['user'], msg['m']); } if (msg['m'].substr(0,14) == '/room subject ' && ( ( msg['user'] == cb.room_slug || ( msg['is_mod'] && cb.settings.modControl == 'Yes' ) ) || msg['user'] == ht_username ) ) { cb.changeRoomSubject(msg['m'].substr(14)); } return msg; }); // Display Panels cb.onDrawPanel(function (user) { if (cb.settings.goal === 0) { return { 'template': '3_rows_12_22_31', 'row1_label': 'Tip Menu Active!', 'row1_value': 'Type /menu to see foxy options.', 'row2_label': 'Highest Tip:', 'row2_value': nullCheck(ht_username) + '(' + ht_amount + ')', 'row3_value': 'Tip ' + cb.settings.price1 + 'tks For "' + cb.settings.item1 + '"' }; } if (cb.settings.reset === "Yes") { return { 'template': '3_rows_12_22_31', 'row1_label': 'Goal:', 'row1_value': goal_tips + '/' + cb.settings.goal + '(' + total_tips + ')', 'row2_label': 'Tip Menu is Active!', 'row2_value': 'Type /menu to see foxy options', 'row3_value': 'Tip ' + cb.settings.price1 + 'tks For "' + cb.settings.item1 + '"' }; } else { return { 'template': '3_rows_12_22_31', 'row1_label': 'Goal:', 'row1_value': goal_tips + '/' + cb.settings.goal, 'row2_label': 'Tip Menu is Active!', 'row2_value': 'Type /menu to see foxy options', 'row3_value': 'Tip ' + cb.settings.price1 + 'tks For "' + cb.settings.item1 + '"' }; } }); var listMenu; update_menu(); // Functions // Makings of the Menu function update_menu() { // Need to get rid of these menu1 variables and replace with menu[1] // Or skip that whole step and add them to menu_string directly for (var i = 1; i < 11; i++) { if (eval('cb.settings.price' + i + ' !== undefined')) { eval( 'var menu' + i + ' = \':foxxfurryfriends Option \' + i + \' - \' + cb.settings.price' + i + ' + \' tokens - \' + cb.settings.item' + i ); } else { eval( 'var menu' + i + ' = \'--\'' ) } } listMenu = [menu1, menu2, menu3, menu4, menu5, menu6, menu7, menu8, menu9, menu10]; // I'm not sure I need this step menu_string = ''; for (var i = 0; i <= listMenu.length; i++) { // This needs to be moved to update_menu() if (eval('cb.settings.price' + i + ' !== undefined')) { if (i > 1) menu_string += '\n'; menu_string += listMenu[i-1]; } } } function update_app() { if (cb.settings.goal === 0) { } else if (goal_tips >= cb.settings.goal) { goal_reached(); } } function goal_reached() { if (tips_remaining() === 0) { if (cb.settings.reset === "Yes") { reset_goal(); } else; goal += 1; { if (goal <= 1) { cb.sendNotice("Goal Reached! " + cb.settings.goalAd,'','#99FF99'); } } } } function reset_goal() { goal_tips -= cb.settings.goal; goal -= 1; cb.sendNotice('Goal Reset! Tip ' + tips_remaining() + ' more tokens to reach again for ' + cb.settings.goalAd); cb.drawPanel(); } function tips_remaining() { var r = cb.settings.goal - goal_tips; if (r < 0) { return 0; } else { return r; } } function nullCheck(str) { if (str === null) { return "---"; } else return str.substring(0, 15); } function showAd() { cb.sendNotice('----- Tip Menu Is Active! Type /menu to see what your tips can accomplish. -----','','#99FFFF'); if ( tips_remaining() > 0) { cb.sendNotice('----- Goal Is Active! Tip ' + tips_remaining() + ' more tokens for: ' + cb.settings.goalAd + " -----", '','#99FF99'); } } function chatAd() { showAd(); cb.setTimeout(chatAd, (cb.settings.chat_ad * 60000)); } cb.setTimeout(chatAd, (cb.settings.chat_ad * 60000)); function init() { update_app(); } function drawMenu(user) { // I like having the goal in a different color but I should consolidate these to one sendNotice cb.sendNotice('----- ' + capitaliseFirstLetter(cb.room_slug) + '\'s Tip Menu -----', user,'#99FFFF','','bold'); if ( tips_remaining() > 0) { cb.sendNotice('Goal: ' + tips_remaining() + ' more tokens for: ' + cb.settings.goalAd, user,'#99FF99') } cb.sendNotice(menu_string+'\nType /commands to see more commands',user,'#99FFFF'); } function capitaliseFirstLetter(string) { if (string === undefined) { return ""; } return string.charAt(0).toUpperCase() + string.slice(1); } function notificationToggle(user) { if (cb.settings.requests === "Yes") { cb.settings.requests = "No"; cb.sendNotice('Menu notifications OFF', user) } else { cb.settings.requests = "Yes"; cb.sendNotice('Menu notifications ON', user) } } function modToggle(user) { if (cb.settings.modControl === "Yes") { cb.settings.modControl = "No"; cb.sendNotice('Moderator control of App OFF', user) } else { cb.settings.modControl = "Yes"; cb.sendNotice('Moderator control of App ON', user) } } function goalResetToggle(user) { if (cb.settings.reset === "Yes") { cb.settings.reset = "No"; cb.sendNotice('Goal autoreset OFF', user) } else { cb.settings.reset = "Yes"; cb.sendNotice('Goal autoreset ON', user) } } function updateLeaderboard() { leaderboard_outofdate = false; leaderboard_string = "----------- Top Tippers -----------"; var temp_key; var tippers = new Object(); var index = 0; for (var key in tipper_array) { index++; tippers[index] = key; } if (index > 1) { var sorted = false; while (!sorted) { //A bubble sort, the only type I remember sorted = true; for (var i=1; i<index; i++) { if ( tipper_array[tippers[i]] < tipper_array[tippers[i+1]] ) { temp_key = tippers[i]; tippers[i] = tippers[i+1]; tippers[i+1] = temp_key; sorted = false; } } } } if (index <1) { leaderboard_string += "\nNo tips received yet." } else { for (var i=1; (i<=index && i<=5 ); i++) { leaderboard_string += "\n #" + i + ": " + tipper_array[tippers[i]] + " tokens - " + capitaliseFirstLetter(tippers[i]); } } } function drawLeaderboard(user) { if (leaderboard_outofdate) { updateLeaderboard(); } cb.sendNotice(leaderboard_string,user); } function setLeaderColor(user, message) { var words = message.split(" "); if (words[1] in color_codes) { leader_color = words[1]; } else { cb.sendNotice('Invalid color, valid colors are: orange, green, blue, purple, yellow, none, crown', user); return; } cb.sendNotice('High tipper background color changed to ' + words[1], user); if (user != ht_username) { cb.sendNotice('High tipper background color changed to ' + words[1] + ' by ' + user, ht_username); } } function drawCommands(user, is_mod) { var command_string = '-------------------------------------------------------------------------------\n' + '/menu - Shows the menu to yourself\n' + '/leaderboard - Shows the top 5 tippers so far this session\n'; if ( user == ht_username || user == cb.room_slug ) { command_string += '/color X - Change high tip color to X (orange, green, blue, purple, yellow, none, crown)\n' } if ( user == cb.room_slug || ( is_mod && cb.settings.modControl == 'Yes') ) { command_string += '/showmenu - Shows the menu to the whole room\n' + '/show ad - Shows the menu ad to the room\n' + '/goal reset - Resets the cumulative goal, useful if auto-reset is turned off\n' + '/goal off - Turns off the cumulative goal\n' + '/goal amount X - Changes the goal amount to X\n' + '/goal set STR - Changes the cumulative goal to STR\n' + '/goal reset toggle - Toggles autoresetting the cumulative goal on or off\n' + '/disable X - Disables menu option X\n' + '/enable X Y STR - Adds a new menu item, option X, cost Y, item STR\n' + '/ad timer X - Sets the ad to show every X minutes\n' + '/notify toggle - Toggles the menu request notification\n' + '/mod toggle - Toggles whether mods can control the app\n' + '/room subject STR - Changes the room subject to STR\n'; } command_string += '-------------------------------------------------------------------------------'; cb.sendNotice(command_string,user); } init(); showAd(); // Thanks for checking out my code!
© Copyright Chaturbate 2011- 2026. All Rights Reserved.