Apps Home
|
Create an App
weekend_dream_show_breaze
Author:
weekend_dream
Description
Source Code
Launch App
Current Users
Created by:
Weekend_Dream
const maxPanelLength = 20; function shortenStr(value, minus) { if (value.length <= maxPanelLength) { return value; } return value.substring(0, maxPanelLength - 3).concat('...'); } function arrayToChoices(array, defaultValue) { return array.reduce((obj, choice, idx) => { obj[`choice${idx + 1}`] = choice; return obj; }, {defaultValue}); } const colors = { white: 'black', black: 'white', gold: 'black', indigo: 'white', coral: 'mintcream' } const choiceYes = 'yes'; const choiceNo = 'no'; const choiceYesNo = { choice1: choiceYes, choice2: choiceNo }; const goalOrders = { asc: 'Ascending', desc: 'Descending', random: 'Random' } cb.settings_choices = [{ name: 'color', type: 'choice', ...arrayToChoices(Object.keys(colors), 'black'), required: true, label: 'App Color' }, { name: 'modify_room_subject', type: 'choice', ...choiceYesNo, defaultValue: choiceYes, required: true, label: 'Should the app change the room subject to display the goal and show name?' }, { name: 'room_subject_suffix', type: 'str', maxValue: 60, required: false, label: 'Optional suffix (i.e. Tags) to append to the goal name in the room subject', }, { name: 'print_info_interval', type: 'int', minValue: 60, maxValue: 900, defaultValue: 300, required: true, label: 'Interval in seconds to print the remaining tokens for a goal or show in chat' }, { name: 'msg_ticket_bought', type: 'str', minLength: 1, required: true, defaultValue: 'Thank you, $user, for buying a ticket!', label: 'Message to print, if a user buys a ticket for the show' }, { name: 'msg_anonymous_user_1', type: 'str', maxLength: maxPanelLength * 2, required: false, defaultValue: 'Do you enjoy the show?', label: 'Optional message towards anonymous users in second panel row' }, { name: 'msg_anonymous_user_2', type: 'str', maxLength: maxPanelLength * 2, required: false, defaultValue: 'Register and support me, please)', label: 'Optional message towards anonymous users in third panel row' }, { name: 'goal_token', type: 'int', minValue: 1, maxValue: 9999, defaultValue: 50, required: true, label: 'Required token amount for each goal' }, { name: 'goal_order', type: 'choice', ...arrayToChoices(Object.values(goalOrders), 'Ascending'), required: true, label: 'Sort order of goals' }]; const numberOfGoals = 50; for (let i = 1; i <= numberOfGoals; i++) { cb.settings_choices.push({ name: `goal${i}`, type: 'str', maxLength: 100, required: false, label: `Goal ${i}` }); } const numberOfShows = 4; for (let i = 1; i <= numberOfShows; i++) { cb.settings_choices.push({ name: `show${i}_name`, type: 'str', maxLength: 100, required: false, label: `Show ${i} - Name (Leave empty to disable show ${i})` }, { name: `show${i}_token`, type: 'int', minValue: 0, maxValue: 9999, defaultValue: 1000, required: true, label: `Show ${i} - Token to start show` }, { name: `show${i}_ticket_token`, type: 'int', minValue: 0, maxValue: 9999, defaultValue: 0, required: true, label: `Show ${i} - Ticket price for show (Set to 0 for public show)` }, { name: `show${i}_duration`, type: 'int', minValue: 30, maxValue: 3600, defaultValue: 900, required: true, label: `Show ${i} - Duration in seconds` }, { name: `show${i}_extended_duration`, type: 'int', minValue: 0, maxValue: 3600, defaultValue: 0, required: true, label: `Show ${i} - Amount of seconds the show time can be extended (Set to 0 for no extended show time)` }, { name: `show${i}_extended_token`, type: 'int', minValue: 1, maxValue: 9999, defaultValue: 500, label: `Show ${i} - Tokens required to fully extend the show time` }, { name: `show${i}_prep_time`, type: 'int', minValue: 0, maxValue: 600, defaultValue: 0, required: true, label: `Show ${i} - Amount of seconds before starting the show (preparation time)` }, { name: `show${i}_counter`, type: 'str', maxLength: maxPanelLength - 8, required: false, label: `Show ${i} - Name of an action counter (Leave empty for no counted action)` }, { name: `show${i}_counter_max`, type: 'int', minValue: 1, maxValue: 100, defaultValue: 10, required: true, label: `Show ${i} - Maximum number of times the action can be performed` }, { name: `show${i}_counter_token`, type: 'int', minValue: 1, maxValue: 9999, defaultValue: 25, required: true, label: `Show ${i} - Tokens required to increase the action counter` }); } const defaultRoomSubject = cb.room_slug.slice(-1) === 's' ? `${cb.room_slug}' Room` : `${cb.room_slug}'s Room`; let fontColor = 'black'; let bgColor = 'white'; let modifyRoomSubject = false; let subjectSuffix = ''; // Total tipped before a show starts let totalTipped = 0; let goalToken = 0; let goalRemaining = 0; let goals = []; // Increase Goal Index on App Startup let goalIndex = -1; let goalsEnabled = false; let shows = []; // Increase Show Index on App Startup let showIndex = -1; let showsEnabled = false; let showRemaining = 0; let showShortName = ''; let showLabel = 'Show'; // Is the show started let showStarted = false; let showRunning = false; let showEndsAt = new Date(); let showTimeStr = '0:0'; let maxShowTimeLabel = 'Max Time'; let maxShowTimeStr = '0:0'; let extendedShowTimeToken = 0; let extendedShowMilliseconds = 0; let millisecondsPerToken = 0; let boughtShowMilliseconds = 0; // Preperation Time let prepEndsAt = new Date(); let prepTimeStr = '0:0'; // Show Action Counters let counterEnabled = false; let counterLabel = ''; let counterName = ''; let counterDescription = ''; let counterToken = 0; let counterTimes = 0; let counterMaxTimes = 0; // Paused show state let showPaused = false; let showPausedAt = new Date(); // Show Timeouts let showTickTimeout = null; let tokenByUser = new Map(); let highestTipper = '-' let highestTipperStr = 'Highest Tip'; let highestTip = 0; let lastTipper = '-'; let ticketBuyers = new Map(); let ticketOwners = new Set(); // The info label and value either displays the goal or the number of tippers let infoLabel = ''; let infoValue = ''; // Limit the times the panel can update, if somebody spams with tips const drawPanelTimeoutMillis = 1000; let drawPanelTimeout = null; let drawPanelRequest = false; function drawPanelLimited() { if (drawPanelTimeout === null) { drawPanelTimeout = cb.setTimeout(() => { drawPanelTimeout = null; if (drawPanelRequest) { drawPanelRequest = false; drawPanelLimited(); } }, drawPanelTimeoutMillis); cb.drawPanel(); } else { drawPanelRequest = true; } } function substituteUsername(msg, user) { return msg.replace('$user', user); } function setDefaultRoomSubject() { if (modifyRoomSubject) { cb.changeRoomSubject(subjectSuffix === '' ? defaultRoomSubject : subjectSuffix); } } function setGoalAsRoomSubject() { if (modifyRoomSubject) { let roomSubject = `${goals[goalIndex]} [${goalRemaining} Token]`; if (subjectSuffix !== '') { roomSubject += ' ' + subjectSuffix; } cb.changeRoomSubject(roomSubject); } } function setShowAsRoomSubject() { if (modifyRoomSubject) { let showName = shows[showIndex].name; if (showRemaining > 0) { showName += ` [${showRemaining} Token]`; } const suffix = subjectSuffix; const addSuffix = suffix !== ''; cb.changeRoomSubject(addSuffix ? `${showName} ${suffix}` : showName); } } function changeSubjectSuffix(suffix) { subjectSuffix = suffix; if (goalsEnabled) { setGoalAsRoomSubject(); } else if (showsEnabled) { setShowAsRoomSubject(); } else { setDefaultRoomSubject(); } } function sortGoals() { switch (cb.settings['goal_order']) { case goalOrders.desc: goals = goals.reverse(); break; case goalOrders.random: let newIndex, tempGoal; for (let i = goals.length - 1; i > 0; i--) { newIndex = Math.floor(Math.random() * (i + 1)); tempGoal = goals[i]; goals[i] = goals[newIndex]; goals[newIndex] = tempGoal; } } } function listGoals() { let msg; if (goals.length === 0) { msg = 'No Goals Defined'; } else { let goalList = goals.slice(goalIndex); const randomizeGoals = cb.settings['goal_order'] === goalOrders.random; if (!randomizeGoals) { goalList = goalList.concat(goals.slice(0, goalIndex)); } msg = goalList.reduce((currMsg, goal, index) => currMsg += ` ${index}. ${goal}`, 'Goals:'); if (randomizeGoals) { msg += '\n All following goals will be shuffled again'; } } cb.sendNotice(msg, cb.room_slug, bgColor, fontColor); } function nextGoal() { // Goals should only be enabled, when they are reached before the show goal if (showStarted) { return; } if (goals.length === 0 || (showsEnabled && showRemaining <= goalToken)) { infoLabel = 'Tipper Count'; infoValue = tokenByUser.size.toString() + (tokenByUser.size === 1 ? ' User' : ' Users'); goalsEnabled = false; if (showsEnabled) { setShowAsRoomSubject(); } return; } goalsEnabled = true; // Update the index of the current goal if (++goalIndex >= goals.length) { // End of goal array reached if (cb.settings['goal_order'] === goalOrders.random) { const lastGoalIdx = goals.length - 1; let thisGoal = goals[lastGoalIdx]; // Randomize the order of goals again sortGoals(); if (goals.length > 1 && thisGoal === goals[0]) { // The new first goal should not be the last goal goals[0] = goals[lastGoalIdx]; goals[lastGoalIdx] = thisGoal; } } goalIndex = 0; } // Set current goal data if (goalRemaining <= 0) { // Only update remaining amount of tokens, if the previous goal was reached goalRemaining = goalToken; } infoValue = shortenStr(goals[goalIndex]); infoLabel = `Goal (${goalRemaining})`; setGoalAsRoomSubject(); } function inviteUserToShow(user) { cb.limitCam_addUsers([user]); ticketOwners.add(user); ticketBuyers.delete(user); const msg = substituteUsername(cb.settings['msg_ticket_bought'], user); cb.sendNotice(msg, user, bgColor, fontColor, 'bold'); } function timeToString(milliseconds) { const seconds = Math.floor(milliseconds / 1000); const minutes = Math.floor(seconds / 60); const secondsOfMinute = seconds % 60; return secondsOfMinute > 9 ? `${minutes}:${secondsOfMinute}` : `${minutes}:0${secondsOfMinute}`; } function onShowEnd() { cb.sendNotice('Show end reached', '', bgColor, fontColor, 'bold'); cb.limitCam_stop(); cb.limitCam_removeAllUsers(); // Reset total tipped for following shows totalTipped = 0; ticketBuyers.clear(); ticketOwners.clear(); showStarted = false; showRunning = false; showsEnabled = false; // If no goals are defined, set default room subject if (goals.length === 0) { setDefaultRoomSubject(); } nextGoal(); nextShow(); cb.drawPanel(); } function setShowRunning() { prepEndsAt = null; // Reset Total tipped for valid show time and action count calculations totalTipped = 0; showRunning = true; if (shows[showIndex].isTicket) { cb.limitCam_start(`Ticket Show [${shows[showIndex].name}] ACTIVE - Ticket Price [${shows[showIndex].ticketToken} Token]`); } } function onShowTick() { // Milliseconds of full show tiem const milliseconds = showEndsAt - new Date(); // Distinguish between running show and started show (with preparation time) if (prepEndsAt === null) { if (milliseconds <= 0) { onShowEnd(); return; } showTimeStr = timeToString(milliseconds + boughtShowMilliseconds); if (extendedShowTimeToken > 0) { maxShowTimeStr = timeToString(milliseconds + extendedShowMilliseconds); const tokenPaid = Math.min(extendedShowTimeToken, totalTipped); maxShowTimeLabel = `Max Time (${tokenPaid}/${extendedShowTimeToken})`; } else { // Show something interesting, if there is no extended show time configured maxShowTimeStr = highestTipper; maxShowTimeLabel = highestTipperStr; } } else { const prepMillis = prepEndsAt - new Date(); prepTimeStr = timeToString(prepMillis); maxShowTimeStr = highestTipper; maxShowTimeLabel = highestTipperStr; if (prepMillis <= 0) { // End of preparation time; Start the Show if (milliseconds <= 0) { // The show could have been stopped before it even started onShowEnd(); return; } setShowRunning(); } } cb.drawPanel(); if (!showPaused) { showTickTimeout = cb.setTimeout(onShowTick, drawPanelTimeoutMillis); } } function pauseShow() { if (!showRunning) { cb.sendNotice('No show to pause is running!', cb.room_slug, bgColor, fontColor, 'bold'); return; } if (showPaused) { cb.sendNotice('Show is already paused! Use /resumeShow command to unpause the show.', cb.room_slug, bgColor, fontColor, 'bold'); return; } showPaused = true; showPausedAt = new Date(); showTimeStr += ' (paused)'; cb.cancelTimeout(showTickTimeout); showTickTimeout = null; cb.sendNotice('Show paused. Use /resumeShow command to unpause the show.', cb.room_slug, bgColor, fontColor, 'bold'); cb.drawPanel(); } function resumeShow() { if (showRunning && showPaused) { showPaused = false; const pausedMillis = new Date() - showPausedAt; showEndsAt.setMilliseconds(showEndsAt.getMilliseconds() + pausedMillis); onShowTick(); cb.sendNotice('Show resumed.', cb.room_slug, bgColor, fontColor, 'bold'); } } function startShow(checkPreConditions = true, sendNotice = true) { if (!showsEnabled) { cb.sendNotice('No show to start!', cb.room_slug, bgColor, fontColor, 'bold'); return; } showRemaining = 0; showStarted = true; showPaused = false; goalsEnabled = false; prepEndsAt = null; // Total tipped is used to calculate the extended show time on each tip totalTipped = 0; extendedShowTimeToken = shows[showIndex].extendedToken; extendedShowMilliseconds = shows[showIndex].extendedDuration * 1000; millisecondsPerToken = (extendedShowMilliseconds / shows[showIndex].extendedToken); counterToken = shows[showIndex].counterToken; counterTimes = 0; counterMaxTimes = shows[showIndex].counterMax; counterName = shows[showIndex].counter; counterEnabled = counterName !== ''; counterLabel = `Every ${counterToken} Token`; counterDescription = `${counterName} (0/${counterMaxTimes})`; boughtShowMilliseconds = 0; showTimeStr = 'Show starting ...'; // Check, if room status is public if (sendNotice) { cb.sendNotice(`Starting show: ${shows[showIndex].name}`, '', bgColor, fontColor, 'bold'); } if (checkPreConditions) { cb.getRoomOwnerData(ownerData => { const {success, errorMessage, data} = ownerData; if (success) { const {room_status: status} = data; if (status === 'public') { startShow(false, false); } else { if (sendNotice) { cb.sendNotice(`Room is currently ${status}. Go into public to start the show!`, cb.room_slug, bgColor, fontColor, 'bold'); } prepTimeStr = 'Waiting for Broadcaster'; showPaused = true; cb.setTimeout(() => startShow(true, false), 10000); cb.drawPanel(); } } else { cb.sendNotice('Failed to get room owner data. Skipping to check if room is online and start show immediately.'); startShow(false, false); } }); } else { cb.cancelTimeout(drawPanelTimeout); drawPanelTimeout = null; showLabel = 'Active Show'; if (shows[showIndex].prepSeconds > 0) { prepEndsAt = new Date(); prepEndsAt.setSeconds(prepEndsAt.getSeconds() + shows[showIndex].prepSeconds); } else { setShowRunning(); } showEndsAt = new Date(); showEndsAt.setSeconds(showEndsAt.getSeconds() + shows[showIndex].duration + shows[showIndex].prepSeconds); setShowAsRoomSubject(); onShowTick(); } } function printShowInfo() { if (shows.length > 0) { cb.sendNotice(`--- Selected Show Info --- Show Name: ${shows[showIndex].name} Token: ${shows[showIndex].token} Token Remaining: ${showRemaining} Ticket Price: ${shows[showIndex].isPublic ? 'No Tickets / Show is Public' : `${shows[showIndex].ticketToken} Token`} Duration: ${timeToString(shows[showIndex].duration * 1000)} Max Duration: ${timeToString((shows[showIndex].duration + shows[showIndex].extendedDuration) * 1000)} /enableShow Sets the current show as a final goal /nextShow Loads the next configured show`, cb.room_slug, bgColor, fontColor); } else { cb.sendNotice('No shows configured!', cb.room_slug, bgColor, fontColor, 'bold'); } } function nextShow() { if (showsEnabled) { cb.sendNotice('Cannot switch to next show, when a show is active. Use /disableshow command first.', cb.room_slug, bgColor, fontColor, 'bold'); return; } if (shows.length === 0) { cb.sendNotice('No shows configured', cb.room_slug, bgColor, fontColor); showIndex = 0; return; } if (++showIndex >= shows.length) { showIndex = 0; } showRemaining = Math.max(0, shows[showIndex].token - totalTipped); showLabel = `Show (${showRemaining})`; showShortName = shortenStr(shows[showIndex].name); printShowInfo(); } function enableShow() { if (showsEnabled) { cb.sendNotice('The show is already enabled!', cb.room_slug, bgColor, fontColor, 'bold'); return; } if (shows.length === 0) { cb.sendNotice('You did not configure a show!', cb.room_slug, bgColor, fontColor, 'bold'); return; } // Disable goals when the remaining tokens are more than for the show if (goalRemaining >= showRemaining) { goalsEnabled = false; infoLabel = 'Tipper Count'; infoValue = tokenByUser.size.toString() + (tokenByUser.size === 1 ? ' User' : ' Users'); } if (!goalsEnabled && showRemaining > 0) { setShowAsRoomSubject(); } showsEnabled = true; if (shows[showIndex].isTicket) { // There could be users that spent enough to obtain a ticket const {ticketToken} = shows[showIndex]; for (let buyer of ticketBuyers.entries()) { if (buyer[1] >= ticketToken) { inviteUserToShow(buyer[0]); } } } if (showRemaining <= 0) { startShow(); } cb.drawPanel(); } function disableShow() { if (!showsEnabled) { cb.sendNotice('There is no active show to disable!', cb.room_slug, bgColor, fontColor, 'bold'); return; } if (showStarted) { cb.sendNotice('A running show cannot be disabled!', cb.room_slug, bgColor, fontColor, 'bold'); return; } showsEnabled = false; if (!goalsEnabled) { nextGoal(); } if (!goalsEnabled) { setDefaultRoomSubject(); } cb.sendNotice('Disabled current show. See table in panel for more information.', cb.room_slug, bgColor, fontColor, 'bold'); cb.drawPanel(); } function printStatus(user = '') { if (!(goalsEnabled || showsEnabled) || showStarted) { return; } let msg = ''; if (goalsEnabled) { msg = `Goal: ${goals[goalIndex]} [${goalRemaining} Token]` if (showsEnabled) { msg += '\n'; } } if (showsEnabled) { msg += `Show: ${shows[showIndex].name} [${showRemaining} Token]`; } cb.sendNotice(msg, user, bgColor, fontColor, 'bold'); } function printStatusRepeated() { printStatus(); cb.setTimeout(printStatusRepeated, cb.settings['print_info_interval'] * 1000); } function loadSettings() { bgColor = cb.settings['color']; fontColor = colors[bgColor]; modifyRoomSubject = cb.settings['modify_room_subject'] === choiceYes; subjectSuffix = cb.settings['room_subject_suffix']; // Load the goals goalToken = cb.settings['goal_token']; for (let i = 1; i <= numberOfGoals; i++) { const goal = cb.settings[`goal${i}`].trim(); if (goal !== '') { goals.push(goal); } } sortGoals(); nextGoal(); if (!goalsEnabled) { setDefaultRoomSubject(); } // Load the shows for (let i = 1; i <= numberOfShows; i++) { const showName = cb.settings[`show${i}_name`].trim(); if (showName !== '') { const ticketToken = cb.settings[`show${i}_ticket_token`]; const extendedDuration = cb.settings[`show${i}_extended_duration`]; shows.push({ name: showName, token: cb.settings[`show${i}_token`], isTicket: ticketToken > 0, isPublic: ticketToken <= 0, ticketToken, duration: cb.settings[`show${i}_duration`], extendedDuration, extendedToken: extendedDuration === 0 ? 0 : cb.settings[`show${i}_extended_token`], prepSeconds: cb.settings[`show${i}_prep_time`], counter: cb.settings[`show${i}_counter`], counterMax: cb.settings[`show${i}_counter_max`], counterToken: cb.settings[`show${i}_counter_token`] }); } } nextShow(); // Only show goals and shows in chat, if there are any configured if (goals.length >= 0 || shows.length >= 0) { printStatusRepeated(); } cb.drawPanel(); } cb.onStart(user => loadSettings()); cb.onEnter(function (user) { const {user: username} = user; printStatus(username); }); function updateTipMap(target, user, amount) { let totalAmount = target.get(user); if (totalAmount === undefined) { totalAmount = amount; } else { totalAmount += amount; } target.set(user, totalAmount); return totalAmount; } cb.onTip(function (tip) { const amount = parseInt(tip['amount']); const {from_user: user, from_user_gender: gender} = tip; const isTicketOwner = ticketOwners.has(user); // Update token statistics if (!showRunning || shows[showIndex].isPublic || isTicketOwner) { totalTipped += amount; } const totalAmount = updateTipMap(tokenByUser, user, amount); const amountLength = totalAmount.toString().length; const userPanelOverflow = maxPanelLength - user.length - amountLength - 4; const userShort = userPanelOverflow < 0 ? user.slice(0, userPanelOverflow) + '...' : user; if (totalAmount > highestTip) { highestTip = totalAmount; highestTipper = `${userShort} (${highestTip})`; highestTipperStr = 'Highest Tip'; if (gender === 'm') { highestTipperStr = 'King'; } else if (gender === 'f') { highestTipperStr = 'Queen'; } } lastTipper = `${userShort} (${amount})`; // Handle show progress (before start) if (showRemaining > 0) { showRemaining = Math.max(0, showRemaining - amount); showLabel = `Show (${showRemaining})`; if (showRemaining === 0 && showsEnabled && !showStarted) { startShow(); } else if (!goalsEnabled) { // Print show as goal subject, if there are no goals to display setShowAsRoomSubject(); } } if (showsEnabled) { // Sell tickets, if ticket show if (shows[showIndex].isTicket && !isTicketOwner) { const buyerToken = updateTipMap(ticketBuyers, user, amount); const buyerRemaining = shows[showIndex].ticketToken - buyerToken; if (buyerRemaining <= 0) { inviteUserToShow(user); } } } else { updateTipMap(ticketBuyers, user, amount); } // Update goal progress if (goalsEnabled) { goalRemaining -= amount; if (goalRemaining <= 0) { cb.sendNotice(`Goal reached: ${goals[goalIndex]}`, '', bgColor, fontColor, 'bold'); nextGoal(); } else { infoLabel = `Goal (${goalRemaining})`; setGoalAsRoomSubject(); } } else { infoValue = tokenByUser.size.toString() + (tokenByUser.size === 1 ? ' User' : ' Users'); } if (showRunning) { if (boughtShowMilliseconds < extendedShowMilliseconds) { // Handle extended show time boughtShowMilliseconds = Math.min(extendedShowMilliseconds, Math.ceil(totalTipped * millisecondsPerToken)); } if (counterEnabled) { let timesPaid = Math.floor(totalTipped / counterToken); if (timesPaid > counterTimes) { timesPaid = Math.min(counterMaxTimes, timesPaid); cb.sendNotice(`${counterName} +${timesPaid - counterTimes} Time(s)`, '', bgColor, fontColor, 'bold'); counterTimes = timesPaid; counterDescription = `${counterName} (${counterTimes}/${counterMaxTimes})`; if (counterTimes >= counterMaxTimes) { cb.sendNotice(`${counterName} - Maximum of ${counterMaxTimes} Time(s) reached!`, '', bgColor, fontColor, 'bolder'); counterEnabled = false; } } } } if (!showStarted || showPaused) { drawPanelLimited(); } }); function printHelp() { cb.sendNotice(`Commands: /listGoals - Prints all goals in the order they will appear /nextGoal - Switches to the next goal /showInfo - Prints info about the current show /enableShow - Enables the currently selected show /disableShow - Disables the show /nextShow - Loads the next show /startShow - Starts the current show /pauseShow - Pauses show time of an active show /resumeShow - Resumes (unpauses) the show /skipWait - Skips the wait time and starts the show immediately /endShowNow - Immediatly ends an active show /soldTickets - Shows the number of sold tickets /invite [username]... - Invite user(s) to the next show /changeSubject [new-subject] - Changes the subject suffix`, cb.room_slug); } cb.onMessage(function (msg) { const {user, m: text} = msg; if (user === cb.room_slug && text.startsWith('/')) { msg['X-Spam'] = true; let commandEnd = text.indexOf(' '); if (commandEnd === -1) { commandEnd = text.length; } const command = text.substring(1, commandEnd).toLowerCase(); switch (command) { case 'listgoals': listGoals(); break; case 'nextgoal': nextGoal(); cb.drawPanel(); break; case 'showinfo': printShowInfo(); break; case 'enableshow': enableShow(); break; case 'disableshow': disableShow(); break; case 'nextshow': nextShow(); cb.drawPanel(); break; case 'startshow': if (showStarted) { cb.sendNotice('The show is already started!', cb.room_slug, bgColor, fontColor, 'bold'); } else { startShow(); } break; case 'pauseshow': pauseShow(); break; case 'resumeshow': resumeShow(); break; case 'skipwait': prepEndsAt = new Date(); break; case 'endshownow': resumeShow(); showEndsAt = new Date(); prepEndsAt = new Date(); break; case 'soldtickets': cb.sendNotice(`Sold ${ticketOwners.size} tickets`, cb.room_slug, bgColor, fontColor, 'bold'); break; case 'invite': text.substring(commandEnd).split(' ') .map(invitedUser => invitedUser.trim()) .forEach(invitedUser => inviteUserToShow(invitedUser)); cb.sendNotice('Invited user(s) to show', cb.room_slug, bgColor, fontColor, 'bold'); break; case 'changesubject': changeSubjectSuffix(text.substring(commandEnd)); break; case 'help': printHelp(); break; default: cb.sendNotice('Unknown command. Enter /help to get a list of all commands.', cb.room_slug, bgColor, fontColor, 'bold'); } } }); cb.onDrawPanel(function (user) { const {user: username} = user; if (username === '') { return { template: '3_rows_11_21_31', row1_value: defaultRoomSubject, row2_value: cb.settings['msg_anonymous_user_1'], row3_value: cb.settings['msg_anonymous_user_2'] }; } const isBroadcaster = username === cb.room_slug; if (isBroadcaster && !showsEnabled && shows.length > 0) { return { template: '3_rows_12_22_31', row1_label: infoLabel, row1_value: infoValue, row2_label: showLabel, row2_value: showShortName, row3_value: 'No Show Active - Type /enableShow or /nextShow' } } if (showsEnabled) { if (shows[showIndex].isPublic || isBroadcaster || ticketOwners.has(username)) { const showCounter = counterEnabled && showRunning; if (showStarted) { return { template: '3_rows_of_labels', row1_label: showCounter ? counterLabel : showLabel, row1_value: showCounter ? counterDescription : showShortName, row2_label: showPaused ? highestTipperStr : maxShowTimeLabel, row2_value: showPaused ? highestTipper : maxShowTimeStr, row3_label: showRunning ? 'Remaining Time' : 'Wait Time', row3_value: showRunning ? showTimeStr : prepTimeStr } } else { return { template: '3_rows_of_labels', row1_label: showLabel, row1_value: showShortName, row2_label: highestTipperStr, row2_value: highestTipper, row3_label: infoLabel, row3_value: infoValue } } } let ticketPaid = ticketBuyers.get(username); let ticketPrice = shows[showIndex].ticketToken; if (ticketPaid !== undefined) { ticketPrice = Math.max(0, ticketPrice - ticketPaid); } ticketValue = `${ticketPrice} Token`; if (showStarted) { return { template: '3_rows_of_labels', row1_label: showLabel, row1_value: showShortName, row2_label: 'Show Ticket', row2_value: ticketValue, row3_label: showRunning ? 'Show Time' : 'Wait Time', row3_value: showRunning ? showTimeStr : prepTimeStr } } else { return { template: '3_rows_of_labels', row1_label: showLabel, row1_value: showShortName, row2_label: 'Show Ticket', row2_value: ticketValue, row3_label: infoLabel, row3_value: infoValue } } } return { template: '3_rows_of_labels', row1_label: infoLabel, row1_value: infoValue, row2_label: highestTipperStr, row2_value: highestTipper, row3_label: 'Last Tip', row3_value: lastTipper } });
© Copyright Chaturbate 2011- 2024. All Rights Reserved.