Apps Home
|
Create an App
Private show 2
Author:
loulouw
Description
Source Code
Launch App
Current Users
Created by:
Loulouw
/** * App: Private Show with Timer * Version: 1.2 * Author: zingknaat * Date: 01.30.15 */ var guestList = []; var lastAllowedUser = '--'; var tipReceived = 0; var lastTipper = '--'; var timeLeft = 0; var showStarted = false; var showEnded = false; var showPrice = 0; var showLength = 0; var minsShowStarts = 0; { // cb. { // cb.settings_choices cb.settings_choices = [ {name:'minimum_tip_amount', type:'int', minValue:1, label:'Minimum Tip Amount', defaultValue:200}, {name:'show_length', type:'int', label:'Length of Show (in minutes; 0 = infinite)', defaultValue:0}, {name:'minutes_left', type:'int', minValue:1, label:'Minutes Before Show Starts', defaultValue:60}, {name:'allow_late_tippers', type:'choice', label:'Allow Late Tippers', defaultValue:'No', choice1:'Yes', choice2:'No'}, {name:'notification_time', type:'choice', label:'Notification Time (in minutes)', choice1:1, choice2:2, choice3:3, choice4:4, choice5:5, choice6:10, choice7:15, choice8:20, choice9:25, choice10:30, defaultValue:5} ]; } { // cb.onTip cb.onTip(function (tip) { lastTipper = tip['from_user']; tipReceived += parseInt(tip['amount']); if(parseInt(tip['amount']) >= showPrice) { if(!showStarted) { addUser(tip['from_user']); lastAllowedUser = tip['from_user']; } else if(cb.settings.allow_late_tippers == 'No') { cb.sendNotice('Sorry, but you are too late. The show has already started.', tip['from_user']); } else { addUser(tip['from_user']); cb.limitCam_addUsers([tip['from_user']]); } } cb.drawPanel(); }); } { // cb.onDrawPanel cb.onDrawPanel(function(user) { if(showStarted) { if (cb.settings.allow_late_tippers == 'Yes') { return { 'template': '3_rows_12_21_31', 'row1_label': 'Tip Received', 'row1_value': tipReceived + ' token(s)', 'row2_label': 'Private :', 'row2_value': 'Show in progress', 'row3_value': 'Tip ' + showPrice + ' to join the show' } } else { return { 'template': '3_rows_12_21_31', 'row1_label': 'Tip Received :', 'row1_value': tipReceived + ' token(s)', 'row2_label': 'Private :', 'row2_value': 'Show in progress', 'row3_label': 'Time remaining :', 'row3_value': getTimeLeft() } } } else if(showEnded) { return { 'template': '3_rows_12_21_31', 'row1_label': 'Tip Received', 'row1_value': tipReceived + ' token(s)', 'row2_label': 'Private :', 'row2_value': 'Show has ended', 'row3_value': 'Thank you for your support!' } } else { return { 'template': '3_rows_12_22_31', 'row1_label': 'Tip Received :', 'row1_value': tipReceived + ' token(s)', 'row2_label': 'Join Private :', 'row2_value': 'Tip ' + showPrice, 'row3_label': 'Countdown :', 'row3_value': getTimeLeft() } } }); } { // cb.onEnter cb.onEnter(function(user) { if (!cb.room_slug) { var msg = 'Welcome to my room, ' + user['user'] + '. \n'; msg += 'A ' +showLength+ ' mins Private Show will be starting in ' + getTimeLeft() + '. \n'; msg += 'If you would like to join, please tip ' + showPrice + ' tokens. \n'; msg += 'Type /guestlist to see the guest list.'; cb.sendNotice(msg, user['user'], '', '#FF0000', 'bold'); } else { var msg = 'A ' +showLength+ ' mins Private Show will be starting in ' + getTimeLeft() + '. \n'; msg += 'If you would like to join, please tip ' + showPrice + ' tokens. \n'; msg += 'Type /guestlist to see the guest list.'; cb.sendNotice(msg, cb.room_slug, '', '#FF0000', 'bold'); } }); } { // cb.onMessage cb.onMessage(function(msg) { if(msg['m'].match(/\/guestlist/i)) { msg['X-Spam'] = true; showGuestList(msg['user']); } if(msg['m'].match(/\/restartapp/i)) { msg['X-Spam'] = true; if(msg['user'] == cb.room_slug) { resetApp(); } } if(msg['m'].match(/\/stopshow/i)) { msg['X-Spam'] = true; if(msg['user'] == cb.room_slug) { stopShow(); } } if(msg['m'].match(/\/changeprice/i)) { msg['X-Spam'] = true; if(msg['user'] == cb.room_slug) { var userMsg = msg['m'].trim().split(' '); var newPrice = parseInt(userMsg[1]); if(newPrice) { showPrice = newPrice; cb.sendNotice('The private show price has been changed to ' + newPrice + ' tokens.', '', '#000000', '#ffffff', 'bold'); } } } if(msg['m'].match(/\/changelength/i)) { msg['X-Spam'] = true; if(msg['user'] == cb.room_slug) { var userMsg = msg['m'].trim().split(' '); var newLength = parseInt(userMsg[1]); if(newLength) { var previousTimeLeft = timeLeft; showLength = newLength; if((showLength > 0) && (showStarted)) { timeLeft = showLength * 60; if((previousTimeLeft <= 0) && (timeLeft > 0)) { updateTimeLeft(); } } cb.sendNotice('The private show length has been changed to ' + newLength + ' mins.', '', '#000000', '#ffffff', 'bold'); } } } if(msg['m'].match(/\/changecountdown/i)) { msg['X-Spam'] = true; if(msg['user'] == cb.room_slug) { var userMsg = msg['m'].trim().split(' '); var newLength = parseInt(userMsg[1]); if(newLength) { var previousTimeLeft = timeLeft; minsShowStarts = newLength; timeLeft = minsShowStarts * 60; if((previousTimeLeft <= 0) && (timeLeft > 0)) { updateTimeLeft(); } cb.sendNotice('The private show countdown has been changed to ' + newLength + ' mins.', '', '#000000', '#ffffff', 'bold'); } } } if(msg['m'].match(/\/add/i)) { msg['X-Spam'] = true; if(msg['user'] == cb.room_slug) { var userMsg = msg['m'].trim().split(' '); var username = userMsg[1]; if(username) { addUser(username); cb.limitCam_addUsers(guestList); } } } if(msg['m'].match(/\/remove/i)) { msg['X-Spam'] = true; if(msg['user'] == cb.room_slug) { var userMsg = msg['m'].trim().split(' '); var username = userMsg[1]; if(username) { var userIndex = guestList.indexOf(username); guestList.splice(userIndex,1); cb.limitCam_removeUsers([username]); cb.sendNotice(username + ' has been removed from the guest list.', '', '', '#006600'); } } } return msg; }); } } function addUser(username) { if(guestList.indexOf(username) < 0) { guestList.push(username); cb.sendNotice(username + ' has been added to the private show guest list.', '', '#CCFFCC', '', 'bold'); } } function resetApp() { timeLeft = minsShowStarts * 60; if(timeLeft > 0) { updateTimeLeft(); } showStarted = false; guestList = []; lastAllowedUser = '--'; tipReceived = 0; lastTipper = '--'; cb.sendNotice('A new private show will start in ' + getTimeLeft(), '', '', '#0000FF', 'bold'); cb.changeRoomSubject('Tip for Private Show'); } function secondsToHms(d) { 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 + ' hrs ' : '') + (m > 0 ? (h > 0 && m < 10 ? '0' : '') + m + ' mins ' : ' ') + (s < 10 ? '0' : '') + s + ' secs'); } function getTimeLeft() { if(timeLeft > 0) { return secondsToHms(timeLeft); } return 0; } function updateTimeLeft() { if(timeLeft) { if(showStarted && (timeLeft == 60)) { cb.sendNotice('WARNING: The private show will end in 1 minute. Please prepare yourself to go public.', cb.room_slug, '#FF0000', '#FFFFFF', 'bold'); for(var i=0;i<guestList.length;i++) { cb.sendNotice('WARNING: The private show will end in 1 minute.', guestList[i], '#FF0000', '#FFFFFF', 'bold'); } } if(!showStarted && (timeLeft == 60)) { cb.sendNotice('FINAL CALL: The private show will begin in 1 minute.', '', '#FF0000', '#FFFFFF', 'bold'); } cb.drawPanel(); timeLeft -= 5; cb.setTimeout(updateTimeLeft, 5000); } else if(showStarted && showLength > 0) { stopShow(); } else if(guestList.length > 0) { startShow(); } else { resetApp(); } } function startShow() { showStarted = true; cb.changeRoomSubject('Private show in progress'); cb.sendNotice('The private show has started.', cb.room_slug, '#FF0000', '#FFFFFF', 'bold'); for(var i=0;i<guestList.length;i++) { cb.sendNotice('The private show has started.', guestList[i], '#FF0000', '#FFFFFF', 'bold'); } cb.limitCam_addUsers(guestList); if(cb.settings.allow_late_tippers == 'No') { cb.limitCam_start('Private show is in progress. Thanks for visiting!'); } else { cb.limitCam_start('Private show is in progress. Tip ' + showPrice + ' to join the show. Otherwise, thanks for visiting!'); } if(showLength > 0) { var previousTimeLeft = timeLeft; timeLeft = showLength * 60; if(previousTimeLeft <= 0) { updateTimeLeft(); } for(var i=0;i<guestList.length;i++) { var msg = 'The show will end in ' + getTimeLeft() + '.'; msg += 'Please pay attention to the countdown clock.'; msg += 'The show will end as soon as the clock turns 0.'; cb.sendNotice(msg, guestList[i], '', '#FF0000', 'bolder'); } } } function stopShow() { showStarted = false; showEnded = true; guestList = []; cb.limitCam_removeAllUsers(); cb.limitCam_stop(); cb.changeRoomSubject(cb.room_slug + "'s room"); cb.sendNotice('The private show has ended. Thank you for your support!', '', '#FF0000', '#FFFFFF', 'bold'); } function showGuestList(username) { cb.sendNotice('#### PRIVATE SHOW GUEST LIST ####', username); var rowNum = 0; for(var i=0;i<guestList.length;i++) { var rowNum = 1; cb.sendNotice(rowNum + ') ' + guestList[i], username); rowNum++; } if (rowNum == 0) { cb.sendNotice('Empty', username); } } function advertise() { { // BROADCASTER COMMANDS var msg = '\n'; msg += '================================\n'; msg += '=========== PRIVATE SHOW ===========\n'; msg += '================================\n'; msg += '----- BROADCASTER COMMANDS :\n'; msg += '----- Type /restartapp to restart the app.\n'; if(showStarted) { msg += '----- Type /stopshow to end the private show.\n'; } msg += '----- Type /add username to add a user to the guest list.\n'; msg += '----- Type /remove username to remove a user from the guest list.\n'; msg += '----- Type /changeprice number to change the private show price.\n'; msg += '----- Type /changelength number to change the length of the show (0 = infinite).\n'; msg += '----- Type /changecountdown number to change the countdown clock. \n'; msg += '================================\n'; cb.sendNotice(msg, cb.room_slug, '', '#006666', 'bold'); } { // PUBLIC INFO & COMMANDS var msg = '\n'; msg += '================================\n'; msg += '=========== PRIVATE SHOW ===========\n'; msg += '================================\n'; msg += '----- PUBLIC INFO : \n'; if(!showStarted || (cb.settings.allow_late_tippers == 'Yes')) { msg += '----- Tip ' + showPrice + ' to join the next '+ showLength + ' mins Private Show.\n '; } if(!showStarted && timeLeft) { msg += '----- Next Private Show starting in ' + getTimeLeft()+ '.\n'; } msg += '----- PUBLIC COMMAND : \n'; msg += '----- Type /guestlist to see the guest list. \n'; msg += '================================\n'; cb.sendNotice(msg, '', '', '#0066CC', 'bold'); } if(!showStarted) { cb.setTimeout(advertise, cb.settings.notification_time * 60000); } } function init() { cb.changeRoomSubject('Tip for Private Show'); showPrice = cb.settings.minimum_tip_amount; showLength = cb.settings.show_length; minsShowStarts = cb.settings.minutes_left; timeLeft = minsShowStarts * 60; cb.setTimeout(updateTimeLeft(), 1000); advertise(); } init();
© Copyright Chaturbate 2011- 2025. All Rights Reserved.