Apps Home
|
Create an App
PRTIMER
Author:
crissymissy
Description
Source Code
Launch App
Current Users
Created by:
Crissymissy
/** * 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.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(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(function(user) { if(showStarted) { return { 'template': '3_rows_12_21_31', 'row1_label': 'Tip Received', 'row1_value': tipReceived + ' token(s)', 'row2_value': 'The show is in progress.', 'row3_value': 'Tip ' + showPrice + ' to join the show' } } else { if(showEnded) { return { 'template': '3_rows_12_21_31', 'row1_label': 'Tip Received', 'row1_value': tipReceived + ' token(s)', 'row2_value': 'The show has ended.', 'row3_value': 'Thank you for your support!' } } else { return { 'template': '3_rows_12_22_31', 'row1_label': 'Countdown', 'row1_value': getTimeLeft(), 'row2_label': 'Tip Received', 'row2_value': tipReceived + ' token(s)', 'row3_value': 'Tip ' + showPrice + ' to join the show' } } } }); cb.onEnter(function(user) { var msg = 'Welcome to my room, ' + user['user'] + '. \n'; msg += 'The 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'); }); 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. :tip25pvt', cb.room_slug, '#FF0000', '#FFFFFF', 'bold'); for(var i=0;i<guestList.length;i++) { cb.sendNotice('The private show has started. :tip25pvt', 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! :tip25pvt'); } else { cb.limitCam_start('Private show is in progress. Tip ' + showPrice + ' to join the show. Otherwise, thanks for visiting! :tip25pvt'); } 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 = 1; for(var i=0;i<guestList.length;i++) { cb.sendNotice(rowNum + ') ' + guestList[i], username); rowNum++; } } function advertise() { var msg = 'Private Show with Timer by zingknaat'; msg += 'Type /restartapp to restart the app.'; if(showStarted) { msg += 'Type /stopshow to end the private show.'; } msg += 'Type /add username to add a user to the guest list.'; msg += 'Type /remove username to remove a user from the guest list.'; msg += 'Type /changeprice number to change the private show price.'; msg += 'Type /changelength number to change the length of the show (0 = infinite).'; msg += 'Type /changecountdown number to change the countdown clock.'; cb.sendNotice(msg, cb.room_slug, '', '#0066CC', 'bold'); var msg = ':tip25pvt'; if(!showStarted && timeLeft) { msg += 'Show starting in ' + getTimeLeft(); } 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- 2026. All Rights Reserved.