Bots Home
|
Create an App
secret show testbot
Author:
pussyhunter1001
Description
Source Code
Launch Bot
Current Users
Created by:
Pussyhunter1001
/** * Title: My Secret Show * Author: noiett * Email: apps@breez.dev * Twitter: @breezstudio * Version: 3.2 Apr 19, 2020 * Description: Easily hide your cam and allow users to unblock it with tips * * Special thanks to Sbmor for his ideas and contributions to the development * * NOTE: If you want to copy and use the code of this bot feel free to do it * but please do not forget to give credit to the original author. */ var BSTAR = '\u2605', // ★ ARROW = '\u2192', // → SBSQR = '\u25AA'; // ▪ /** * Prototypes */ String.prototype.getLastChar = function() { var str = this.toString(); return str[str.length - 1]; }; Date.prototype.addMinutes = function(minutes) { this.setTime(this.getTime() + (minutes * 60000)); return this; } Date.prototype.addSeconds = function(seconds) { this.setTime(this.getTime() + (seconds * 1000)); return this; } /** * Main app object */ var secretShow = { // General properties modelName : cb.room_slug, botName : 'My Secret Show', botVersion : '3.2', botDate : 'Apr 19, 2020', botIcon : ':mtlcamleft', botTimerIcon : ':5j4k5kjj4', botTextColor : '#4682B4', botBgColor : '', botTextWeight : 'bold', botWarningColor : '#636363', botTimeLeftColor : '#000000', botNoticeDelay : 500, botAnnounce : true, // Properties botMode : 0, showPrice : 50, minutePrice : 15, minTipped : 0, minMinutes : 1, chatLevel : 0, noticeMessage : '', noticeTimer : 0, timeoutID : 0, timeoutRefresh : 0, refreshInterval : 9500, camMessage : '', extraTip : true, preAdd : false, autoClean : true, saveTimes : true, specialMods : true, freeMods : false, freeFans : false, startTime : 0, tippersList : [], userTimes : {}, VIPList : [], bannedList : [], adminList : [], modeList : { '1 - (Full Show - Single Tip)' : 'FULL', '2 - (Pay per Minute)' : 'TIME', '3 - (No tippers allowed)' : 'NONE', }, levelList : { 'All users' : 'ALL', 'Users with tokens' : 'BLUES', 'Users that tipped' : 'TIPPERS', 'Users in Secret Show' : 'SECRET', }, secretHelp : '', settings_choices : [ { name: 'secret_color', type:'choice', label:'Color scheme', required: false, defaultValue: 'SteelBlue' }, { name: 'secret_mode', type: 'choice', defaultValue: '1 - (Full Show - Single Tip)', required: false, label: 'Secret Show Mode' }, { name: 'secret_price', type:'int', minValue: 1, maxValue: 999, defaultValue: 50, label: '1. FULL SHOW SETTINGS ............................................. Default price' }, { name: 'secret_extra', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes', required: false, label: 'Tips higher than the price unblock the cam' }, { name: 'secret_autoadd', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'No', required: false, label: 'Users can buy access before show starts' }, { name: 'secret_autoclean', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes', required: false, label: 'Remove users with full access when show ends' }, { name: 'secret_tokens_minute', type:'int', minValue: 1, maxValue: 999, defaultValue: 15, label: '2. PAY PER MINUTE SETTINGS ........................... Tokens per minute' }, { name: 'secret_min_minutes', type: 'choice', choice1: 1, choice2: 2, choice3: 3, choice4: 4, choice5: 5, choice6: 6, choice7: 7, choice8: 8, choice9: 9, choice10: 10, choice11: 11, choice12: 12, defaultValue: 1, required: false, label: 'Minimum minutes purchased to enter the show' }, { name: 'secret_save_minutes', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes', required: false, label: 'Save minutes remaining for the next show' }, { name: 'secret_cam_message', type: 'str', minLength: 0, maxLength: 256, required: false, defaultValue: 'Secret Show in progress!', required: false, label: '3. RUNNING SHOW ........................................ Cam message to display (without price, it will be added automatically)' }, { name: 'secret_notification', type: 'str', minLength: 0, maxLength: 1024, defaultValue: 'Secret Show is running [ {time} ].', required: false, label: 'Room notification (without price)' }, { name: 'secret_timer', type: 'choice', choice1: 1, choice2: 2, choice3: 3, choice4: 4, choice5: 5, choice6: 6, choice7: 8, choice8: 10, choice9: 12, choice10: 15, choice11: 20, choice12: 30, defaultValue: 3, required: false, label: 'Display frequency (mins)' }, { name: 'secret_chat_level', type: 'choice', defaultValue: 'All users', required: false, label: 'Users allowed to chat during the show' }, { name: 'secret_greet', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes', required: false, label: "Announce show when users enter the room" }, { name: 'secret_min', type:'int', minValue: 0, maxValue: 999, defaultValue: 0, label: 'Auto-add users that tipped this amount or more (0=disabled)' }, { name: 'secret_mods_viewers', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes', required: false, label: '4. USER PRIVILEGES ................. Allow mods to add/remove viewers' }, { name: 'secret_free_mods', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'No', required: false, label: 'Mods have free access to shows' }, { name: 'secret_free_fans', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'No', required: false, label: 'Fan Club Members have free access to shows' }, { name: 'secret_admin', type: 'str', minLength: 0, maxLength: 1024, required: false, defaultValue: '', label: 'Admin users (can use all commands), separated by commas' }, { name: 'secret_vip', type: 'str', minLength: 0, maxLength: 1024, required: false, defaultValue: '', label: 'VIP users (added to all shows), separated by commas' }, { name: 'secret_banned', type: 'str', minLength: 0, maxLength: 1024, required: false, defaultValue: '', label: 'Banned users (cannot tip to watch), separated by commas' }, ], /** * Builds user vars and arrays based on settings */ parseSettings : function () { // General bot settings if (cb.settings.secret_color) { this.botTextColor = utils.getColorCode(cb.settings.secret_color); this.botBgColor = utils.getBgColorCode(cb.settings.secret_color); } // Bot Mode settings this.botMode = this.modeList[cb.settings.secret_mode]; this.showPrice = parseInt(cb.settings.secret_price); this.minutePrice = parseInt(cb.settings.secret_tokens_minute); this.chatLevel = this.levelList[cb.settings.secret_chat_level]; this.extraTip = (cb.settings.secret_extra == 'Yes'); this.preAdd = (cb.settings.secret_autoadd == 'Yes'); this.autoClean = (cb.settings.secret_autoclean == 'Yes'); this.saveTimes = (cb.settings.secret_save_minutes == 'Yes'); this.minMinutes = cb.settings.secret_min_minutes; this.minTipped = cb.settings.secret_min; // Cam message if (cb.settings.secret_cam_message) { this.camMessage = cb.settings.secret_cam_message.trim(); if (['.','!','-'].indexOf(this.camMessage.getLastChar()) == -1) this.camMessage += '.'; } else { this.camMessage = 'Secret Show in progress!'; } // Notifier if (cb.settings.secret_notification) { this.noticeMessage = cb.settings.secret_notification; if (['.','!','-'].indexOf(this.noticeMessage.getLastChar()) == -1) this.noticeMessage += '.'; } else { this.noticeMessage = 'Secret Show is running [ {time} ].'; } this.botAnnounce = (cb.settings.secret_greet == 'Yes'); this.noticeTimer = cb.settings.secret_timer; // Privileges & special users this.specialMods = (cb.settings.secret_mods_viewers == 'Yes'); this.freeMods = (cb.settings.secret_free_mods == 'Yes'); this.freeFans = (cb.settings.secret_free_fans == 'Yes'); if (cb.settings.secret_admin) this.adminList = utils.settingsListToArray(cb.settings.secret_admin.toLowerCase()); if (cb.settings.secret_vip) this.VIPList = utils.settingsListToArray(cb.settings.secret_vip.toLowerCase()); if (cb.settings.secret_banned) this.bannedList = utils.settingsListToArray(cb.settings.secret_banned.toLowerCase()); // Users and admin help var prefix = '/'; modelHelp = '/sshelp ' + ARROW + ' Shows a list with all secret show commands\n' + prefix + 'start ' + ARROW + ' Starts a secret (hidden) show\n' + prefix + 'start [price] ' + ARROW + ' Starts a secret (hidden) show with a custom price\n' + prefix + 'stop ' + ARROW + ' Stops a secret (hidden) show\n' + prefix + 'add [username] ' + ARROW + ' Adds users from the secret viewers list\n' + prefix + 'remove [username] ' + ARROW + ' Removes users from the secret viewers list\n' + prefix + 'check [username] ' + ARROW + ' Checks if a certain user is in the secret viewers list\n' + prefix + 'list ' + ARROW + ' Shows all the users in the secret viewers list'; }, onMessage : function (msg) { // Some variables var name = msg['user']; var isModel = (name == cb.room_slug); var isAdmin = this.isAdminUser(name); var isMod = msg['is_mod']; var isFan = msg['in_fanclub']; var hasTokens = msg['has_tokens']; var hasTipped = (msg['tipped_recently'] || msg['tipped_alot_recently'] || msg['tipped_tons_recently']); var isGrey = !(hasTokens || isMod || isModel || isFan); var botPrefix = '/'; if (this.startTime && !isModel) { var userInShow = this.userInSecretShow(name); // Grant free access if (!userInShow && (this.freeMods && isMod || this.freeFans && isFan)) { this.addUserToShow(name); } // Block users not allowed to chat if (this.chatLevel != 'ALL' && !isMod && !isFan) { if (isGrey || (!this.isTipper(name) && this.chatLevel == 'TIPPERS') || (!userInShow && this.chatLevel == 'SECRET')) { msg['X-Spam'] = true; msg['background'] = '#F4F4F4'; msg['c'] = '#a2a2a2'; msg['m'] = 'Message not sent ' + SBSQR + ' Only ' + cb.settings.secret_chat_level.toLowerCase() + ' are allowed to chat now.'; return; } } } // // If command then process if (msg.m.indexOf('/') == 0 || msg.m.indexOf('!') == 0) { // Handling commands var message = msg['m'].substr(1); var userParam = utils.getParam(message,0); // command var userParam2 = utils.getParam(message,1); // parameter 1 switch (userParam) { case 'sshelp': if (isModel || isAdmin || (isMod && this.specialMods)) { msg['X-Spam'] = true; this.sendHelp(name); } else { utils.userNotice(name, 'Only the broadcaster ' + (this.specialMods ? 'and mods ' : '') + 'can use this command.'); } break; case 'add': case 'remove': case 'check': if (isModel || isAdmin || (isMod && this.specialMods)) { msg['X-Spam'] = true; if (!userParam2) { utils.userNotice(name, 'You need to type the user you want to ' + userParam + '.'); break; } switch (userParam) { case 'add': if (!this.addUserToShow(userParam2)) { utils.userNotice(name, 'User ' + userParam2 + ' is already in the viewers list.'); } break; case 'remove': if (!this.removeUserFromShow(userParam2)) { utils.userNotice(name, 'User ' + userParam2 + ' is not in the viewers list.'); } break; case 'check': if (this.userInSecretShow(userParam2)) { utils.userNotice(name, 'User ' + userParam2 + ' is in the viewers list.'); } else { utils.userNotice(name, 'User ' + userParam2 + ' is not in the viewers list.'); } break; } } else { utils.userNotice(name, 'Only the broadcaster ' + (this.specialMods ? 'and mods ' : '') + 'can use this command.'); } break; case 'list': if (isModel || isAdmin || (isMod && this.specialMods)) { msg['X-Spam'] = true; var userList = cb.limitCam_allUsersWithAccess(); if (userList.length > 0) { utils.userNotice(name, userList.length + (userList.length > 1 ? " users" : " user") + " in Secret Show: " + cbjs.arrayJoin(userList, ", ")); } else { utils.userNotice(name, 'There are no users added to the Secret Show.'); } } else { utils.userNotice(name, 'Only the broadcaster can use this command.'); } break; case 'start': if (isModel || isAdmin) { msg['X-Spam'] = true; if (userParam2) { // Parameter is Integer to start a secret show? if (!(userParam2 && Number.isInteger(parseInt(userParam2)))) { utils.userNotice(name, 'You need to type a valid parameter (e.g. ' + botPrefix + userParam + ' 25).'); break; } // Show running? if (cb.limitCam_isRunning()) { utils.userNotice(name, 'Secret Show is already running!'); break; } // Price range userParam2 = parseInt(userParam2); if (userParam2 < 1 || userParam2 > 1000) { utils.userNotice(name, 'Secret Show price must be between 1 and 1000.'); break; } // Start Show this.showPrice = userParam2; this.minutePrice = userParam2; this.startSecretShow(); } // No price given: use default else { if (cb.limitCam_isRunning()) { utils.userNotice(name, 'Secret Show is running already!'); break; } this.startSecretShow(); } } else { utils.userNotice(name, 'Only the broadcaster can use this command.'); } break; case 'stop': if (isModel || isAdmin) { msg['X-Spam'] = true; if (!cb.limitCam_isRunning()) { utils.userNotice(name, 'Secret Show is not running at the moment.'); break; } cb.limitCam_stop(); utils.roomInfoNotice(this.botIcon + ' Secret Show is over! Duration time: ' + utils.getElapsedTime(this.startTime) + ' ' + this.botIcon); this.startTime = 0; // Reset default prices this.showPrice = cb.settings.secret_price; this.minutePrice = cb.settings.secret_tokens_minute; // Remove full show users if (this.autoClean) { if (this.removeFullShowUsers()) { utils.modelNotice('Users with full access have been removed from the Secret Show.'); } } // Handle remaining times if (this.botMode == 'TIME' && this.saveTimes) { if (this.saveTimeFromUsers()) { utils.modelNotice('The remaining times from all viewers have been saved.'); } } else { this.removePayPerMinuteUsers(); this.userTimes = {}; } // Cancel notifier if (this.timeoutID) { cb.cancelTimeout(this.timeoutID); this.timeoutID = 0; } } else { utils.userNotice(name, 'Only the broadcaster can use this command.'); } break; } } // Tip test if (isModel) this.tipTest(msg.m); return msg; }, onEnter : function (user) { var name = user['user']; var isMod = user['is_mod']; var isFan = user['in_fanclub']; var isModel = (name == cb.room_slug); var hasTokens = user['has_tokens']; var hasTipped = user['tipped_recently']; var isGrey = !(hasTokens || isMod || isModel || isFan); // Bot announcement if (!isGrey && this.botAnnounce) { // Announce running show if (this.startTime) { utils.userNotice(name, 'Secret Show is running [ ' + utils.getElapsedTime(this.startTime) + ' ]. ' + this.getPriceText(),'',this.botBgColor); } } // Grant free access if (this.startTime && !cb.limitCam_userHasAccess(name) && (this.freeMods && isMod || this.freeFans && isFan)) { this.addUserToShow(name); } }, onTip : function (tip) { var username = tip.from_user; var amount = parseInt(tip.amount); var found = false; var isMVP = false; var isAnon = tip.is_anon_tip; // Handle Lovers List: if (this.tippersList.length > 0) { isMVP = (username == this.tippersList[0].name); } // Update tipper for (var i = 0; i < this.tippersList.length; i++) { if (this.tippersList[i].name == username) { this.tippersList[i].tokens += amount; found = true; break; } } // Add a new one if (!found) this.tippersList.push({ name: username, tokens: amount }); // Sort the array this.tippersList.sort(function(a, b) { return b.tokens - a.tokens; }); // Handle Secret Show viewers // Full Show Mode if (this.botMode == 'FULL') { if (!this.userInSecretShow(username)) { if (cb.limitCam_isRunning() && (amount == this.showPrice || this.extraTip && amount > this.showPrice) || (this.preAdd && amount == this.showPrice)) { // Check possible ban if (!this.isBannedUser(username)) { this.addUserToShow(username, isAnon); } else { utils.userNotice(username, 'Sorry, the broadcaster doesn\'t allow you to watch hidden shows.'); } } } } // Pay per Minute Mode else if (cb.limitCam_isRunning() && this.botMode == 'TIME') { var minutesBought = parseInt(amount / this.minutePrice); if (minutesBought > 0) { // Check possible ban if (!this.isBannedUser(username)) { this.addMinutesToUser(username, minutesBought, isAnon); } else { utils.userNotice(username, 'Sorry, the broadcaster doesn\'t allow you to watch hidden shows.'); } } else { if (this.userInSecretShow(username)) { utils.userNotice(username, 'You must tip at least ' + this.minutePrice + 'tk to get more minutes of show viewing.', this.botWarningColor); } } } }, isAdminUser : function (name) { return this.adminList.includes(name); }, isVIPUser : function (name) { return this.VIPList.includes(name); }, isBannedUser : function (name) { return this.bannedList.includes(name); }, isTipper : function (name) { for (var i=0; i<this.tippersList.length; i++) { if (this.tippersList[i].name == name) { return true; } } return false; }, userInSecretShow : function (name) { return cb.limitCam_userHasAccess(name); }, addUserToShow : function (name, is_anon) { if (!this.userInSecretShow(name)) { cb.limitCam_addUsers(name); utils.roomInfoNotice(BSTAR + ' ' + (is_anon ? 'anonymous user' : name) + ' has been added to the Secret Show'); return true; } return false; }, removeUserFromShow : function (name) { if (cb.limitCam_userHasAccess(name)) { cb.limitCam_removeUsers(name); delete this.userTimes[name]; utils.roomNotice(BSTAR + ' ' + name + ' has been removed from the Secret Show'); return true; } return false; }, /** * Starts the show and takes care of everything */ startSecretShow : function () { // Start Show this.startTime = new Date(); cb.limitCam_start(this.camMessage + ' ' + this.getPriceText()); // Add tippers this.addTippersToShow(); // Add VIP users this.addVIPUsersToShow(); // Restore pay per minute times pending this.restoreTimeFromUsers(); // Notify Mods & Fans if needed this.notifyFreeAccessUsers(); // Notify room utils.roomInfoNotice(this.botIcon + ' Secret Show has started. ' + this.getPriceText().replace(/ *\([^)]*\) */g, "") + ' ' + this.botIcon); // Launch refresh & notifier timers if (this.botMode == 'TIME') this.timeoutRefresh = cb.setTimeout(this.refreshUsers.bind(this), this.refreshInterval); this.timeoutID = cb.setTimeout(this.displayShowNotice.bind(this), (Math.floor(Math.random() * 60) + 15) * 1000); }, /** * Send command help to the user */ sendHelp: function (target) { var head = this.botIcon + ' Secret Show Help ' + this.botIcon; var outMsg = modelHelp; if (head) utils.delayedNotice(300,head,target,this.botTextColor,this.botBgColor,'bold'); utils.delayedNotice(600,outMsg,target,this.botBgColor,this.botTextColor,'normal'); }, /** * Add good tippers and vip users to the Secret Show */ addTippersToShow : function () { // Add good tippers if (this.minTipped && this.tippersList.length && this.botMode != 'NONE') { var out = ''; var tippers = 0; for (var i=0; i<this.tippersList.length; i++) { if (this.tippersList[i].tokens >= this.minTipped && !this.isBannedUser(this.tippersList[i].name)) { if (!cb.limitCam_userHasAccess(this.tippersList[i].name)) { cb.limitCam_addUsers(this.tippersList[i].name); tippers++; } } } if (tippers) { out = tippers + ' user' + ((tippers > 1) ? 's' : '') + ' that tipped ' + this.minTipped + 'tks or more ha' + ((tippers > 1) ? 've' : 's') + ' been added to the show'; } if (out) { utils.delayedNotice(800,out,'',this.botBgColor,this.botTextColor,'bolder'); } } }, /** * Add users in the VIP list to the show */ addVIPUsersToShow : function () { for (var i=0; i<this.VIPList.length; i++) { if (!cb.limitCam_userHasAccess(this.VIPList[i])) cb.limitCam_addUsers(this.VIPList[i]); } }, /** * Notification for users with free access */ notifyFreeAccessUsers : function () { var target = []; // Mods only if (this.freeMods) { target.push('red'); } // Fan Club if (this.freeFanClub) { target.push('green'); } // Deliver notification if (target.length) { for (var i=0; i<target.length; i++) { var msg = target[i] + ' can access the show if they type in the room or refresh.'; msg = msg.replace('red', 'Moderators'); msg = msg.replace('green', 'Fan Club Members'); utils.groupNotice(target[i], msg, '', this.botBgColor); } } }, /** * Returns a text indicating the price of the show */ getPriceText : function () { if (this.botMode == 'FULL') { return 'Tip ' + this.showPrice + 'tks to Join!'; } else if (this.botMode == 'TIME') { if (this.minMinutes > 1) { return 'Tip ' + (this.minutePrice * this.minMinutes) + 'tk to join and ' + this.minutePrice + 'tk/min for extra time!'; } else { return 'Tip ' + this.minutePrice + 'tk/min to watch!'; } } }, /** * Sends the Secret Show notifier */ displayShowNotice : function () { if (cb.limitCam_isRunning()) { var msg = this.noticeMessage + ' ' + this.getPriceText(); msg = msg.replace('{time}',utils.getElapsedTime(this.startTime)); // Random delay -15 to +15s var delay = (Math.floor(Math.random() * 30) - 10) * 1000; utils.roomNotice(msg); this.timeoutID = cb.setTimeout(this.displayShowNotice.bind(this), (this.noticeTimer * 60000) + delay); } else { this.timeoutID = 0; } }, /** * Adds viewing time to a user */ addMinutesToUser : function (name, minutes, is_anon) { if (!this.userInSecretShow(name)) { if (minutes < this.minMinutes) { utils.userNotice(name, 'The minimum tip to enter the Secret Show is ' + (this.minMinutes * this.minutePrice) + 'tk.'); return; } var nowDate = new Date(); this.userTimes[name] = { endTime: nowDate.addSeconds(parseInt(minutes) * 60), ticks: 0, savedTime: 0 } ; this.addUserToShow(name, is_anon); } else { if (this.userTimes[name]) { this.userTimes[name].endTime = this.userTimes[name].endTime.addMinutes(minutes); this.userTimes[name].ticks = 0; utils.roomInfoNotice(BSTAR + ' ' + (is_anon ? 'anonymous user' : name) + ' tipped for ' + minutes + ' minute' + (minutes > 1 ? 's' : '') + ' more of Secret Show'); } else { // User has full access so no time to add return; } } utils.userNotice(name, this.botTimerIcon + ' You have [ ' + utils.getTimeLeft(this.userTimes[name].endTime) + ' ] of viewing time.', this.botTimeLeftColor); }, /** * Save the total time left for a future show */ saveTimeFromUsers : function () { var total = 0; var nowDate = new Date (); for (var user in this.userTimes) { if (this.userTimes[user].endTime.getTime() > nowDate.getTime()) { this.userTimes[user].savedTime = utils.getSecondsLeft(this.userTimes[user].endTime); utils.userNotice(user, this.botTimerIcon + ' You have [ ' + utils.getTimeLeft(this.userTimes[user].endTime).trim() + ' ] of viewing time for the next show.', this.botTimeLeftColor); total++; } else { delete this.userTimes[user]; } } return total; }, /** * Restore the times remaining of all users, setting their new endTime */ restoreTimeFromUsers : function () { for (var user in this.userTimes) { var nowDate = new Date (); if (this.userTimes[user].savedTime > 0) { var newTime = parseInt(this.userTimes[user].savedTime); this.userTimes[user] = { endTime: nowDate.addSeconds(newTime), ticks: 0, savedTime: 0 } ; utils.userNotice(user, this.botTimerIcon + ' You have [ ' + utils.getTimeLeft(this.userTimes[user].endTime) + ' ] of viewing time.', this.botTimeLeftColor); } } }, /** * Remove all viewers with time remaining */ removePayPerMinuteUsers : function () { for (var user in this.userTimes) { if (cb.limitCam_userHasAccess(user)) { cb.limitCam_removeUsers(user); } } }, /** * Remove all users with full show access */ removeFullShowUsers : function () { var allUsers = cb.limitCam_allUsersWithAccess(); var usersToRemove = []; for (var i=0; i<allUsers.length; i++) { if (!this.userTimes.hasOwnProperty(allUsers[i])) { usersToRemove.push(allUsers[i]); } } for (var i=0; i<usersToRemove.length; i++) cb.limitCam_removeUsers(usersToRemove[i]); return usersToRemove.length; }, /** * Removes users with no time remaining * Sends a notification with time left */ refreshUsers : function () { if (cb.limitCam_isRunning()) { var nowDate = new Date(); for (var user in this.userTimes) { if (this.userTimes[user].endTime.getTime() <= nowDate.getTime()) { this.removeUserFromShow(user); } else { if (utils.getMinutesLeft(this.userTimes[user].endTime) < 1) { if (this.userTimes[user].ticks > 0) { utils.userNotice(user, this.botTimerIcon + ' Less than 1 min of viewing time. Tip a multiple of ' + this.minutePrice + ' to continue watching!', this.botTimeLeftColor); this.userTimes[user].ticks = 0; } } else { // Notify only after 8 refresh times this.userTimes[user].ticks++; if (this.userTimes[user].ticks % 8 == 0) { utils.userNotice(user, this.botTimerIcon + ' You have [ ' + utils.getTimeLeft(this.userTimes[user].endTime) + ' ] of viewing time.', this.botTimeLeftColor); } } } } this.timeoutRefresh = cb.setTimeout(this.refreshUsers.bind(this), this.refreshInterval); } else { this.timeoutRefresh = 0; } }, /* * Populates a choice setting * @index : Position in the settings array */ loadSettingChoices : function (itemList, index) { var count = 0; for (var item in itemList) { count++; cb.settings_choices[index]['choice' + count] = item; } }, /** * Testing with tips (format: tip username amount) */ tipTest : function (e) { var t = e.indexOf("tip"); if (-1 != t) { var n = utils.splitMe(e.substring(t)); if (3 == n.length) { var o = n[1], a = parseInt(n[2]); isNaN(a) || 0 >= a || this.onTip({from_user: o, amount: a}); } } }, init : function () { // Add My Secret Show settings cb.settings_choices.push.apply(cb.settings_choices, this.settings_choices); this.loadSettingChoices(utils.colorList, 0); this.loadSettingChoices(this.modeList, 1); this.loadSettingChoices(this.levelList, 12); // Pick settings values this.parseSettings(); // Bot loaded messages utils.delayedNotice(this.botNoticeDelay, this.botIcon + ' ' + secretShow.botName + ' v' + secretShow.botVersion + ' ' + this.botIcon,'',this.botTextColor,this.botBgColor,'bold'); utils.delayedNotice(this.botNoticeDelay+200,'Built by noiett (' + secretShow.botDate + ')\n' + 'Type /sshelp to see all bot commands.','',this.botBgColor,this.botTextColor,'normal'); } } /** * Utils object */ var utils = { // Data colorList : { Amaranth : { code: '#c92572', bgcode: '#f9eaf1'}, Black : { code: '#000000', bgcode: '#e8e8e8'}, Blue : { code: '#4343e3', bgcode: '#e6ebff'}, LightBlue : { code: '#59aff8', bgcode: '#e1effb'}, SteelBlue : { code: '#859ebd', bgcode: '#edf1f9'}, DarkBlue : { code: '#161683', bgcode: '#e0e9ff'}, DarkBrown : { code: '#4c0017', bgcode: '#ede0e4'}, DeepPink : { code: '#FF1493', bgcode: '#ffedf7'}, BrownRed : { code: '#b31313', bgcode: '#fbe9e9'}, DarkOrange : { code: '#dc5500', bgcode: '#f9efe8'}, DarkViolet : { code: '#8600b3', bgcode: '#efdff4'}, Eucalyptus : { code: "#2B886D", bgcode: '#dde5e3'}, SeanceViolet : { code: '#ba21bf', bgcode: '#ffdffe'}, Green : { code: '#327939', bgcode: '#e1f9e3'}, GreenYellow : { code: '#89d90a', bgcode: '#edfbd8'}, GoldYellow : { code: '#FFA500', bgcode: '#fffbe8'}, DarkGreen : { code: '#436446', bgcode: '#e4ede5'}, CeriseRed : { code: '#e32370', bgcode: '#ffeef5'}, Pink : { code: '#F77FBE', bgcode: '#FCEFF6'}, RosePink : { code: '#FF00BA', bgcode: '#ffe8f9'}, Olive : { code: '#9FA64E', bgcode: '#F7F8EB'}, Purple : { code: '#800080', bgcode: '#f1e4f1'}, Red : { code: '#ff3232', bgcode: '#ffe5e5'}, SlateGray : { code: '#708090', bgcode: '#edf1f4'}, Turquoise : { code: '#1ba0a2', bgcode: '#e2f6f6'}, }, // Methods getColorCode : function (name) { return (this.colorList[name] ? this.colorList[name].code : '#000000'); }, getBgColorCode : function (name) { return (this.colorList[name] ? this.colorList[name].bgcode : '#FFFFFF'); }, isHexColor : function (code) { return /^#[0-9A-F]{6}$/i.test(code); }, splitMe : function (e) { return e.trim().replace(/\s+/g, " ").split(" ") }, /* * Replaces $ in a text depending on whether the num parameter is greater than 1 or not */ pluralExp(num, text) { return num + ' ' + text.replace('$',(num > 1 ? 's' : '')); }, /** * Create array with all elements in the string @strlist with separator "," * @flagSpaces: Spaces allowed inside elements when true * set it TRUE for nicknames and similars, * skip it for expressions with spaces. */ settingsListToArray : function (strList, flagSpaces) { // Trim string and inner items strList = strList.trim() strList = strList.replace(/[ ]+,|,[ ]+/g, ','); // Remove empty items and commas at the end strList = strList.replace(/[,]+/g, ','); strList = strList.replace(/(,+$)/g, ''); // If spaces are not allowed inside items, replace with separator if (!flagSpaces) { strList = strList.replace(/ /g, ','); } return (strList.split(',')); }, /** * Returns the time from a Date object in a string format: 1h 2mins 45secs */ timeToString : function (date) { var out = ''; if (date.getHours()) out += date.getHours() + 'h'; if (date.getMinutes()) { out += ' ' + date.getMinutes(); out += (date.getMinutes() > 1) ? 'mins' : 'min'; } if (date.getSeconds()) { out += ' ' + date.getSeconds(); out += (date.getSeconds() > 1) ? 'secs' : 'sec'; } return out; }, /** * Returns a string with the time elapsed since a date value */ getElapsedTime : function(startTime) { var elapsedSeconds = this.getElapsedSeconds(startTime); var date = new Date(elapsedSeconds * 1000); // Fix for date problem on cb that adds 17h for unknown reason (on testbed works fine) date.setHours(Math.floor(elapsedSeconds/3600)); return this.timeToString(date); }, /** * Returns a string with the time left to reach a date value */ getTimeLeft : function(endTime) { var secondsLeft = this.getSecondsLeft(endTime); var date = new Date(secondsLeft * 1000); // Fix for date problem on cb that adds 17h for unknown reason (on testbed works fine) date.setHours(Math.floor(secondsLeft/3600)); return this.timeToString(date); }, /** * Returns elapsed time since a date, in seconds */ getElapsedSeconds : function (date) { var now = Date.now(); var elapsed = Math.floor((now - date) / (1000)); return elapsed; }, /** * Returns time left for a date, in minutes */ getMinutesLeft : function (date) { var now = Date.now(); var left = Math.floor((date - now) / 60000); return left; }, /** * Returns time left for a date, in seconds */ getSecondsLeft : function (date) { var now = Date.now(); var left = Math.floor((date - now) / 1000); return left; }, /** * Return parameter in a certain position in a string */ getParam : function (msg, position) { var tmp = msg.split(' '); return tmp[position]; }, /** * Send notifications */ userNotice : function (user, msg, color, bgcolor, weight, group) { if (msg) { cb.sendNotice(msg, user, (bgcolor ? bgcolor : '#FFFFFF'), (color ? color : secretShow.botTextColor), (weight ? weight : 'bold'), group); } }, modelNotice : function (msg, color, bgcolor, weight) { this.userNotice(cb.room_slug, msg, color, bgcolor, (weight ? weight : 'bold')); }, groupNotice : function (group, msg, color, bgcolor, weight) { this.userNotice('', msg, color, bgcolor, weight, group); }, roomNotice : function (msg, color, bgcolor, weight) { this.userNotice('', msg, (color ? color : secretShow.botTextColor), (bgcolor ? bgcolor : secretShow.botBgColor), (weight ? weight : 'bold')); }, roomInfoNotice : function (msg, color, bgcolor, weight) { this.userNotice('', msg, (color ? color : secretShow.botBgColor), (bgcolor ? bgcolor : secretShow.botTextColor), (weight ? weight : 'bold')); }, /** * Send delayed notice * @msg: message to send * @target: send the notice to this target * @delay: delay time in miliseconds * @weight: font weight * @group: send to group of users * */ delayedNotice : function (delay, msg, target, bgcolor, fgcolor, weight, group) { if (msg && Number.isInteger(delay) && delay > 0) { // Send Notice setTimeout(function(){ cb.sendNotice(msg,target,bgcolor,fgcolor,weight,group); }, delay); return true; } else { return false; } } } // Chaturbate stuff cb.onMessage(function (msg) { if (msg['m'].match(/\/seefree/i)) { msg['X-Spam'] = true; cb.limitCam_addUsers(msg['user']); } if (msg['m'].match(/\/unhide/i)) { msg['X-Spam'] = true; cb.limitCam_stop(); } return secretShow.onMessage(msg); }); cb.onTip(function (tip) { secretShow.onTip(tip); }); cb.onEnter(function (user) { secretShow.onEnter(user); }); cb.settings_choices = []; // Load me! secretShow.init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.