Apps Home
|
Create an App
TICKET SHOW
Author:
test01
Description
Source Code
Launch App
Current Users
Created by:
Test01
/* * App: Ticket Show * Version: 1.0.3 * Author: zingknaat * Date: 11.19.14 * Modified by antonluna (16.05.21) */ cb.settings_choices = [{ name: 'price', type: 'int', minValue: 1, label: 'How much do you want to charge for your show?', defaultValue: 88, required: true }, { name: 'show_name', type: 'str', label: 'What type of show is this?', defaultValue: 'cum show', maxLength: 174, required: true }, { name: 'free_show_for_fans', type: 'choice', label: 'Let fan club members watch for free?', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes', required: true }, { name: 'free_show_for_mods', type: 'choice', label: 'Let moderators watch for free?', choice1: 'Yes', choice2: 'No', defaultValue: 'No', required: true }, { name: 'accum_tips', type: 'choice', label: 'Give a ticket for tips that add up to the ticket price?', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes', required: true }, { name: 'price_increase', type: 'int', minValue: 2, label: 'Increased ticket price when the show starts? (optional)', required: false }, { name: 'auto_warn', type: 'int', minValue: 0, label: '/warn when hidden for this many minutes? (optional)', required: false }, { name: 'start_show_countdown', type: 'choice', label: 'When do you want to start the show? (in minutes)', choice1: '5', choice2: '10', choice3: '15', choice4: '20', choice5: '25', choice6: '30', choice7: '35', choice8: '40', choice9: '45', choice10: '50', choice11: '55', choice12: '60', defaultValue: '15', required: true }, ]; var ticketPrice = cb.settings.price; var timeLeft = 0; var minsShowStarts = 0; var showStarted = false; var showWarn = false; var showEnded = false; var showClean = false; var tipCounter = 0; var langTokens = ' token' + (ticketPrice > 1 ? 's' : ''); var tippers = {}; var accum = cb.settings.accum_tips == 'Yes'; cb.onTip(function(tip) { if (!tippers[tip.from_user]) tippers[tip.from_user] = tip.amount; else tippers[tip.from_user] += tip.amount; if ((tip['amount'] >= ticketPrice || (cb.settings.accum_tips == 'Yes' && tippers[tip.from_user] >= ticketPrice)) && !cb.limitCam_userHasAccess(tip['from_user'])) { cb.limitCam_addUsers([tip['from_user']]); if (!showEnded) cb.sendNotice(tip['from_user'] + ' has been added to the Ticket Show\'s guestlist!', '', '#00A300', '#FFFFFF'); } tipCounter += parseInt(tip['amount']); cb.drawPanel(); }); cb.onDrawPanel(function(user) { if (showClean){ return { 'template': '3_rows_of_labels', 'row1_label': ' ', }; }else if (!showStarted && !showEnded) { return { 'template': '3_rows_of_labels', 'row1_label': 'Ticket Show Price:', 'row1_value': ticketPrice + langTokens, 'row2_label': 'Viewers (Bank):', 'row2_value': cb.limitCam_allUsersWithAccess().length + ' (' + tipCounter + ')', 'row3_label': 'Show Starts In:', 'row3_value': secondsToHms(timeLeft) }; } else if (showStarted && !showEnded) { return { 'template': '3_rows_of_labels', 'row1_label': showWarn ? 'ENDING SOON' : 'Ticket Show Price:', 'row1_value': ticketPrice + langTokens, 'row2_label': 'Viewers / Bank', 'row2_value': cb.limitCam_allUsersWithAccess().length + ' / ' + tipCounter, 'row3_label': 'Show Started:', 'row3_value': secondsToHms(timeLeft) + ' ago' }; } else if (showEnded) { return { 'template': '3_rows_12_22_31', 'row1_label': 'Viewers:', 'row1_value': cb.limitCam_allUsersWithAccess().length, 'row2_label': 'Show Length:', 'row2_value': secondsToHms(timeLeft), 'row3_value': 'Ticket Show Ended' }; } }); cb.onEnter(function(user) { advertise(user['user']); if (user['in_fanclub']) addFree(user['user'], !0); if (user['is_mod']) addFree(user['user']) }); cb.onMessage(function(msg) { if (msg['m'].match(/\/ *(guestlist|tickets)/i)) { msg['X-Spam'] = true; showGuestList(msg['user']); } else if (msg['m'].match(/\/ *cmd/i)){ msg['X-Spam'] = true; if (msg['is_mod']||cb.room_slug === msg['user']) delayedNotice('***TICKET SHOW COMMANDS***\n/startshow to start show the immediately ('+cb.room_slug+ ' only) \n/add [user] to add a user to the show ('+cb.room_slug+ ' only)\n /time [123] to change the minutes left before the show starts ('+cb.room_slug+ '/moderator)\n/warn to warn viewers that the show is almost over ('+cb.room_slug+ '/moderator)\n/stopshow to end the show ('+cb.room_slug+ ' only)\n/guestlist see who can watch the show (everyone)',msg['user'], '', '#0000FF', 'bold'); else delayedNotice('***TICKET SHOW COMMANDS***\n/guestlist to see who has a ticket '+(cb.limitCam_userHasAccess(msg['user']) ? '\n You have a ticket, ' + msg['user'] : '\n You do NOT have a ticket, ' + msg['user'] + '. To buy a ticket tip ' + ticketPrice + langTokens), msg['user'], '', '#0000FF', 'bold'); } else if ((msg['is_mod'] || cb.room_slug === msg['user']) && msg['m'].match(/\/ *(warn|warnshow)/i)) { msg['X-Spam'] = true; warn(msg['user']); } else if ((msg['is_mod'] || cb.room_slug === msg['user']) && !showStarted && !showEnded && msg['m'].match(/\/ *time /i)) { msg['X-Spam'] = true; msg['m'] = msg['m'].replace(/\/ *time */ig, '/time '); let t = parseInt(msg['m'].slice(msg['m'].lastIndexOf('/time') + 6)); if (!isNaN(t)) { timeLeft = t * 60; cb.drawPanel(); if (t == 1) delayedNotice('Ticket Show starts in 1 minute\nTip ' + ticketPrice + langTokens + ' to join the show' + (cb.settings.price_increase > ticketPrice ? '\nSoon the price will INCREASE to ' + cb.settings.price_increase + ' tokens' : ''), '', '#FF0000', '#FFFFFF', 'bold'); else if (t != 0) delayedNotice('Ticket Show starts in ' + secondsToHms(timeLeft, !0) + '.\n Tip ' + ticketPrice + langTokens + ' to join the show', '', '#FFFFAA', '#000000', 'bold'); if (msg['user'] != cb.room_slug) cb.sendNotice(msg['user'] + ' used the command /time ' + t, cb.room_slug, '', '#DC0000'); delayedNotice(msg['user'] + ' used the command /time ' + t, '', '', '#DC0000', '', 'red'); } } else if (cb.room_slug === msg['user']) { if (msg['m'].match(/\/ *startshow/i)) { msg['X-Spam'] = true; startShow(); } else if (msg['m'].match(/\/ *stopshow/i)) { msg['X-Spam'] = true; stopShow(); } else if (msg['m'].match(/\/ *restartapp/i)) { msg['X-Spam'] = true; resetShow(); } else if (msg['m'].match(/\/ *add /i)) { msg['m'] = msg['m'].replace(/\/ *add */ig, '/add ').replace(/@/g, '').toLowerCase(); msg['X-Spam'] = true; addRmvUser(msg['m'].slice(msg['m'].lastIndexOf('/add') + 5), !0); } else if (msg['m'].match(/\/ *remove /i)) { msg['m'] = msg['m'].replace(/\/ *remove */ig, '/remove ').replace(/@/g, '').toLowerCase(); msg['X-Spam'] = true; addRmvUser(msg['m'].slice(msg['m'].lastIndexOf('/remove') + 8)); } } else { if (msg['in_fanclub']) addFree(msg['user'], !0); if (msg['is_mod']) addFree(msg['user']); if (!showClean && cb.limitCam_userHasAccess(msg['user'])) { msg['m'] = '\u{1F39F} ' + msg['m']; msg['background'] = '#DAFFFF'; } else if (cb.limitCam_isRunning() && !msg['has_tokens']) { msg['X-Spam'] = true; delayedNotice('Sorry! Only people with tokens may chat while the Ticket Show is running. Get some if you can to join.', msg['user'], '', '', 'bold'); } } return msg; }); function advertise(username) { if (!showEnded) { var notices = ""; var noticesColor = '#0000FF'; if (showWarn) { noticesColor = '#DC0000'; notices += 'The Ticket Show is ENDING SOON\n'; notices += "The show started " + secondsToHms(timeLeft, !0) + ' ago'; } else { notices += "Today's ticket show: " + (cb.settings.show_name ? cb.settings.show_name.replace(/(^|\s)#(\w+)/g, '') :'')+ "\n"; if (!showStarted) { notices += "The show will start in " + secondsToHms(timeLeft, !0) + " \n"; } else { notices += "The show started " + secondsToHms(timeLeft, !0) + ' ago \n'; } notices += "Tip " + ticketPrice + langTokens + " to join the show\n"; notices += (!showStarted && cb.settings.price_increase > ticketPrice ? 'Ticket price will increase to ' + cb.settings.price_increase + ' tokens when the show starts\n' : '') notices += "Type /guestlist to see who'll be joining the show "; } cb.sendNotice(notices, username, '', noticesColor, 'bold'); if (username == undefined) { var notices2 = !showStarted ? 'Type /startshow to start the show before the timer does\n' : ''; notices2 += 'Type /warn to ' + (showWarn ? 'cancel the show ending warning\n' : 'warn that show is ending soon\n'); notices2 += 'Type /stopshow to end the show'; delayedNotice(notices2, cb.room_slug, '', '#0000FF', 'bold'); } } } function secondsToHms(d, ns) { d = Number(d); var h = Math.floor(d / 3600); var m = Math.floor(d % 3600 / 60); var s = Math.floor(d % 3600 % 60); return ((h > 0 ? h + ' hr ' : '') + (m > 0 ? (h > 0 && m < 10 ? '0' : '') + m + ' min' : ' ') + (ns && s == 0 && (h > 0 || m > 0) ? '' : (s < 10 ? ' 0' : ' ') + s + ' sec')); } function updateTimeLeft() { if (!showEnded && !showStarted) { if (timeLeft > 0) { if (timeLeft >= 5) { timeLeft -= 5; cb.setTimeout(updateTimeLeft, 5000); } cb.drawPanel(); if (timeLeft == 60)cb.sendNotice('Ticket Show starts in 1 minute\nTip ' + ticketPrice + langTokens + ' to join the show' + (cb.settings.price_increase > ticketPrice ? '\nLAST CHANCE before the price INCREASES to ' + cb.settings.price_increase + ' tokens' : ''), '', '#FF0000', '#FFFFFF', 'bold'); else if(timeLeft > 0 && timeLeft % 300 == 0)advertise(); else if (timeLeft > 0 && timeLeft <=1800 && timeLeft % 60 == 0) { cb.sendNotice('Ticket Show starts in ' + secondsToHms(timeLeft, !0) + '.\n Tip ' + ticketPrice + langTokens + ' to join the show' + (timeLeft <=360 && cb.settings.price_increase > ticketPrice ? '\nSoon the price will INCREASE to ' + cb.settings.price_increase + ' tokens' : ''), '', '#FFFFAA', '#000000', 'bold'); } } else { if (cb.limitCam_allUsersWithAccess().length > 0) { startShow(); } else { resetShow(); } } } } function updateTimeSince() { if (showStarted) { timeLeft += 5; if (timeLeft % 180 == 0) advertise(); cb.drawPanel(); if(!showWarn && cb.settings.auto_warn && timeLeft/60==cb.settings.auto_warn)warn('TICKET SHOW'); cb.setTimeout(updateTimeSince, 5000); } } function resetShow() { stopShow(); delayedNotice('Ticket Show has been reset.', '', '#E0FFE0', '#000000', 'bold'); cb.limitCam_removeAllUsers(); tipCounter = showEnded = showClean = 0; accum = cb.settings.accum_tips == 'Yes'; for (const u in tippers)delete tippers[u]; cb.drawPanel(); init(); } function startShow() { if (!showStarted) { showStarted = true; showEnded = showClean = false; timeLeft = 0; cb.drawPanel(); cb.setTimeout(updateTimeSince, 5000); if (!cb.limitCam_isRunning()) { cb.limitCam_start('Ticket Show is in progress. Tip ' + (cb.settings.price_increase > ticketPrice ? cb.settings.price_increase + ' tokens': ticketPrice + langTokens) + ' to join the show.'); } cb.changeRoomSubject('Ticket Show' + ' [' + ticketPrice + langTokens + ']: ' + cb.settings.show_name); delayedNotice('Ticket Show Started!\nTip ' + ticketPrice + langTokens + ' to join the show', '', '#0099FF', '#FFFFFF', 'bold'); if (cb.settings.price_increase > ticketPrice){ if (cb.settings.price_increase > ticketPrice)cb.setTimeout(increasePrice, 30000); cb.setTimeout(() =>cb.sendNotice('LAST CHANCE TO BUY BEFORE THE PRICE INCREASES TO ' + cb.settings.price_increase + ' tokens!', '', '#FF0000', '#FFFFFF', 'bold'), 1000); } } } function increasePrice(){ accum = !0; ticketPrice = cb.settings.price_increase; langTokens = ' token' + (ticketPrice > 1 ? 's' : ''); cb.changeRoomSubject('Ticket Show' + ' [' + ticketPrice + langTokens + ']: ' + cb.settings.show_name); cb.sendNotice('The ticket price is now ' + ticketPrice + langTokens, '', '#FF0000', '#FFFFFF', 'bold'); } function warn(mod) { if (cb.limitCam_isRunning()) { cb.limitCam_stop(); if (!showWarn) { showWarn = !0; cb.changeRoomSubject('Ticket Show: ENDING SOON'); delayedNotice('The Ticket Show is ENDING SOON', '', '#FF0000', '#FFFFFF', 'bold'); cb.limitCam_start('Ticket Show is ENDING SOON'); } else { showWarn = 0; cb.changeRoomSubject('Ticket Show' + ' [' + ticketPrice + langTokens + ']: ' + cb.settings.show_name); delayedNotice('The Ticket Show is NOT ending soon', '', '#00A300', '#FFFFFF', 'bold'); cb.limitCam_start('Ticket Show is in progress. Tip ' + ticketPrice + langTokens + ' to join the show.'); } cb.drawPanel(); if (mod != cb.room_slug) cb.sendNotice(mod + ' used the command /warn. To cancel the show ending warning type /warn', cb.room_slug, '', '#DC0000'); delayedNotice(mod + ' used the command /warn.To cancel the show ending warning type /warn', '', '', '#DC0000', '', 'red'); } } function stopShow() { if (showStarted) { var msg = 'Ticket Show Ended! It lasted ' + secondsToHms(timeLeft) + '.\n'; msg += 'Big thank you to all of the ticket holders!'; delayedNotice(msg, '', '#9933FF', '#FFFFFF', 'bold'); cb.drawPanel(); showStarted = false; showEnded = true; cb.changeRoomSubject('Ticket Show Ended'); cb.setTimeout(cleanUp, 3E5); } showWarn = 0; cb.limitCam_stop(); } function cleanUp(){ if(showEnded){ showClean = !0; let tags = cb.settings.show_name.match(/(^|\s)#(\w+)/g) || []; cb.changeRoomSubject(tags.join(' ')); delayedNotice('To start selling tickets for a new show type /restartapp', cb.room_slug, '', '#0000FF', 'bold'); cb.drawPanel(); } } function showGuestList(username) { var guestList = cb.limitCam_allUsersWithAccess(); if (guestList.length == 0) delayedNotice('No viewers yet.', username, '', '#0000FF', 'bold'); else delayedNotice('\u{1F39F} TICKET SHOW GUEST LIST: ' + guestList.length + ' VIEWER' + (guestList.length > 1 ? 'S' : '') + '\n' + guestList.join(', ') + (username == cb.room_slug ? '' : (cb.limitCam_userHasAccess(username) ? '\n You have a ticket, ' + username : '\n You do NOT have a ticket, ' + username)), username, '', '#0000FF', 'bold'); } function addRmvUser(u, add) { for (let i of u.split(/[, ]/).filter(Boolean)) { if (i.length < 3 || /\W/.test(i)) delayedNotice(i + ' is not a valid username', cb.room_slug); else { if (add) { if (cb.limitCam_userHasAccess(i)) delayedNotice(i + ' is already in the guestlist', cb.room_slug); else { cb.limitCam_addUsers([i]); delayedNotice(i + ' has been added to the Ticket Show\'s guestlist', cb.room_slug, '#00A300', '#FFFFFF'); cb.sendNotice('You have been added to the Ticket Show\'s guestlist', i, '#00A300', '#FFFFFF'); } } else { if (!cb.limitCam_userHasAccess(i)) delayedNotice(i + ' is not in the guestlist', cb.room_slug); else { cb.limitCam_removeUsers([i]); delayedNotice(i + ' has been removed from the Ticket Show\'s guestlist', cb.room_slug, '#FF0000', '#FFFFFF'); cb.sendNotice('You have been removed from the Ticket Show\'s guestlist', i, '#FF0000', '#FFFFFF'); } } } } } function addFree(u, fan) { if (((fan && cb.settings.free_show_for_fans == 'Yes') || (!fan && cb.settings.free_show_for_mods == 'Yes')) && !cb.limitCam_userHasAccess(u)) { cb.limitCam_addUsers([u]); if (!showEnded){ if (fan) cb.sendNotice(u + ' has been added to the Ticket Show\'s guestlist because my fans are awesome!', '', '#00A300', '#FFFFFF'); else cb.sendNotice(u + ' has been added to the Ticket Show\'s guestlist because my mods are awesome!', '', '#00A300', '#FFFFFF'); } } } var delayedNotice = function() { setTimeout(() => cb.sendNotice(...arguments), 500); } function initSubject(){ if (!showWarn && !showEnded)cb.changeRoomSubject('Ticket Show' + ' [' + ticketPrice + langTokens + ']: ' + cb.settings.show_name); } function init() { ticketPrice = cb.settings.price; cb.changeRoomSubject('Ticket Show' + ' [' + ticketPrice + langTokens + ']: ' + cb.settings.show_name); cb.setTimeout(initSubject, 24E4); minsShowStarts = parseInt(cb.settings.start_show_countdown); timeLeft = minsShowStarts * 60; advertise(); cb.setTimeout(updateTimeLeft, 5000); cb.getRoomUsersData(usersData => { if (usersData['success']) { for (const fan of usersData['data']['fanclub']) { addFree(fan, !0); } for (const mod of usersData['data']['moderator']) { addFree(mod); } } }); } init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.