Bots Home
|
Create an App
Test-SSB-1
Author:
hockeystud199i
Description
Source Code
Launch Bot
Current Users
Created by:
Hockeystud199i
/* -------------------------------------------- * Constants for different uses * -------------------------------------------- */ var HEART = '\u2665'; // ♥ BDIAMOND = '\u2666'; // ♦ BSTAR = '\u2605'; // ★ SSTAR = '\u22c6'; // ⋆ WSTAR = '\u2606'; // ☆ POINT = '\u00B7'; // · ARROW = '\u2192'; // → SBSQR = '\u25AA'; // ▪ SARROW = '\u10148'; // ➤ var COLORS = [ {name: 'Amaranth', code: '#c92572', bgcode: '#f9eaf1'}, {name: 'Black', code: '#000000', bgcode: '#e8e8e8'}, {name: 'Blue', code: '#016ea6', bgcode: '#e3eff6'}, {name: 'LightBlue', code: '#4682b4', bgcode: '#e5f0f9'}, {name: 'SteelBlue', code: '#4159b5', bgcode: '#e7ebfb'}, {name: 'DarkBlue', code: '#364785', bgcode: '#e4e9f9'}, {name: 'BrownRed', code: '#b31313', bgcode: '#fbe9e9'}, {name: 'DarkViolet', code: '#9c3dc4', bgcode: '#efdff4'}, {name: 'SeanceViolet', code: '#ba21bf', bgcode: '#ffdffe'}, {name: 'Green', code: '#327939', bgcode: '#e1f9e3'}, {name: 'DarkGreen', code: '#436446', bgcode: '#d0e8d3'}, {name: 'Pink', code: '#FF00BA', bgcode: '#ffe6f8'}, {name: 'Purple', code: '#800080', bgcode: '#f3e6f3'}, {name: 'Red', code: '#ff3232', bgcode: '#ffe5e5'}, {name: 'SlateGray', code: '#708090', bgcode: '#eaeff3'}, ]; /* -------------------------------------------- * Global bot variables * -------------------------------------------- */ var modelName = cb.room_slug; var botVersion = "1.1"; var botDate = "Dec 3, 2017"; var botTextColor = '#4682B4'; var botBgColor = ''; var botTextWeight = 'bold'; var botWarnColor = '#ff0000'; var botNoticeDelay = 500; // Variables for features var secretPrice = 50; var secretMin = 0; var secretTimer = 0; var secretTimeout = 0; var secretMessage = ''; var secretAutoclean = true; var secretStartTime = 0; var secretList = []; var loversList = []; /* -------------------------------------------- * Text variables * -------------------------------------------- */ var theHeader = ':mtlstar My Secret Show v' + botVersion + ' :mtlstar'; var loadText = 'Built by HS199i (' + botDate + ')\n' + 'Type /ssbhelp to see all bot commands.'; var modelHelp = ''; /* -------------------------------------------- * Bot base settings * -------------------------------------------- */ cb.settings_choices = [ { name: 'secret_price', type:'int', minValue: 1, maxValue: 999, defaultValue: 50, label: 'Secret Show price' }, { name: 'secret_min', type:'int', minValue: 0, maxValue: 999, defaultValue: 0, label: 'Minimum tipped to be added to all Secret Shows (0=disabled)' }, { 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, choice11: 30, defaultValue: 3, label: 'Running show announcement frequency (mins)' }, { name: 'secret_autoclean', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes', label: "Remove all allowed viewers when the show is over" }, { name: 'secret_greet', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes', label: "Announce running show to users joining the room" }, { name: 'secret_color', type:'choice', label:'Color scheme', choice1: 'Amaranth', choice2: 'Black', choice3: 'Blue', choice4: 'LightBlue', choice5: 'SteelBlue', choice6: 'DarkBlue', choice7: 'BrownRed', choice8: 'DarkViolet', choice9: 'SeanceViolet', choice10: 'Green', choice11: 'DarkGreen', choice12: 'Pink', choice13: 'Purple', choice14: 'Red', choice15: 'SlateGray', defaultValue: 'SteelBlue' }, ]; /* ------------------------------------------------ * Bot events: onMessage, onTip, onEnter * ------------------------------------------------ */ /* * Handle new message */ cb.onMessage(function (msg) { // Some variables var name = msg['user']; var isModel = (name == cb.room_slug); 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 userMsg = ''; var roomInfoNotice = ''; var roomNotice = ''; var msgTextColor = botTextColor; var msgBgColor = botBgColor; var msgTextWeight = botTextWeight; var botPrefix = ''; // If command then process if (msg.m.indexOf('/') == 0 || msg.m.indexOf('!') == 0) { // Handling commands var message = msg['m'].substr(1); var userParam = getParam(message,0); // command var userParam2 = getParam(message,1); // parameter 1 var userParam3 = getParam(message,2); var botPrefix = botCommand; /*cb.log('userParam: ' + userParam); cb.log('userParam2: ' + userParam2); cb.log('userParam3: ' + userParam3);*/ switch (userParam) { case 'ssbhelp': if (isModel) { msg['X-Spam'] = true; sendCommand(name, 'modelhelp'); } else { userMsg = 'Only the broadcaster can use this command.'; } break; case 'add': case 'remove': case 'check': if (isModel) { if (userParam2) { switch (userParam) { case 'add': if (!cb.limitCam_userHasAccess(userParam2)) { cb.limitCam_addUsers(userParam2); roomInfoNotice = ':mtlstar ' + userParam2 + ' has been added to the Secret Show! :mtlstar'; } else { userMsg = 'User ' + userParam2 + ' is already in the viewers list.'; } break; case 'remove': if (cb.limitCam_userHasAccess(userParam2)) { cb.limitCam_removeUsers(userParam2); roomNotice = userParam2 + ' has been removed from the Secret Show'; } else { userMsg = 'User ' + userParam2 + ' is not in the viewers list.'; } break; case 'check': if (cb.limitCam_userHasAccess(userParam2)) { userMsg = 'User ' + userParam2 + ' is in the viewers list.'; } else { userMsg = 'User ' + userParam2 + ' is not in the viewers list.'; } break; } } else { userMsg = 'You need to pass a valid parameter (e.g. ' + botPrefix + userParam + ' username).'; } } else { userMsg = 'Only the broadcaster can use this command.'; } break; case 'list': if (isModel) { var userList = cb.limitCam_allUsersWithAccess(); if (userList.length > 0) { userMsg = "" + userList.length + (userList.length > 1 ? " users" : " user") + " in Secret Show: " + cbjs.arrayJoin(userList, ", "); } else { userMsg = 'There are no users added to the Secret Show.'; } } else { userMsg = 'Only the broadcaster can use this command.'; } break; case 'start': if (isModel) { if (userParam2) { // Parameter is Integer to start a secret show? if (userParam2 && isInteger(userParam2)) { if (!cb.limitCam_isRunning()) { if (userParam2 >= 1 && userParam2 <= 999) { secretPrice = userParam2; secretMessage = 'Secret Show in progress! Tip ' + secretPrice + ' To Join!'; cb.limitCam_start(secretMessage); roomInfoNotice = ':mtlcamleft ' + modelName + ' has started a Secret Show. Tip ' + secretPrice + 'tks to Join! :mtlcamright'; secretStartTime = new Date(); addTippersToShow(); secretTimeout = cb.setTimeout(announceSecretShow, (Math.floor(Math.random() * 60) + 15) * 1000); } else { userMsg = 'Secret Show price must be between 1 and 999.'; } } else { userMsg = 'Secret Show is already running!'; } } else { userMsg = 'You need to pass a valid parameter (e.g. ' + botPrefix + userParam + ' 25).'; } } else { // No price given: use default if (!cb.limitCam_isRunning()) { cb.limitCam_start(secretMessage); roomInfoNotice = ':mtlcamleft ' + modelName + ' has started a Secret Show. Tip ' + secretPrice + 'tks to Join! :mtlcamright'; secretStartTime = new Date(); addTippersToShow(); secretTimeout = cb.setTimeout(announceSecretShow, (Math.floor(Math.random() * 60) + 15) * 1000); } else { userMsg = 'Secret Show is already running!'; } } } else { userMsg = 'Only the broadcaster can use this command.'; } break; case 'stop': if (isModel) { if (cb.limitCam_isRunning()) { cb.limitCam_stop(); roomInfoNotice = ':mtlcamleft Secret Show is over! Duration time: ' + getSecretShowDuration() + ' :mtlcamright'; secretStartTime = 0; secretPrice = cb.settings.secret_price; if (secretAutoclean) { cb.limitCam_removeAllUsers(); userMsg = 'All users have been removed from the Secret Show.'; } if (secretTimeout) { cb.cancelTimeout(secretTimeout); secretTimeout = 0; } } else { userMsg = 'Secret Show is not running at the moment.'; } } else { userMsg = 'Only the broadcaster can use this command.'; } break; } } // Output messages // Workaround for CB bug: this delay prevents messages from being broken by command text in the room setTimeout(function() { // Room info notice (dark background) if (roomInfoNotice) cb.sendNotice(roomInfoNotice,'',botTextColor,"#FFFFFF",'bolder'); // Room normal notice if (roomNotice) cb.sendNotice(roomNotice, '', botBgColor, msgTextColor, msgTextWeight); // Notice to the user if (userMsg) cb.sendNotice(userMsg, name, '', msgTextColor, msgTextWeight); }, botNoticeDelay); return msg; }); /* * Handle new tip */ cb.onTip(function (tip) { var username = tip.from_user; var amount = tip.amount; var found = false; var isMVP = false; // Handle Lovers List: if (loversList.length > 0) { isMVP = (username == loversList[0].name); } // Update tipper for (var i = 0; i < loversList.length; i++) { if (loversList[i].name == username) { loversList[i].tokens += amount; found = true; break; } } // Add a new one if (!found) loversList.push({ name: username, tokens: amount }); // Sort the array loversList.sort(function(a, b) { return b.tokens - a.tokens; }); // Handle Secret Show viewers if (cb.limitCam_isRunning()) { if (amount >= secretPrice) { // Check if user is already in list if (!cbjs.arrayContains(cb.limitCam_allUsersWithAccess(), username)) { // Not in list, let's add it cb.log('New user added to Secret Show'); cb.limitCam_addUsers(username); var msg = ':mtlstar ' + username + ' has been added to the Secret Show :mtlstar'; cb.sendNotice(msg,'',botTextColor,'#FFFFFF','bold'); } } } }); /* * handle user entrance messages */ cb.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); var out = ''; // Bot announcement if (!isGrey && botAnnounce) { // Secret show running if (secretStartTime) { out += 'Secret Show is running [ ' + getSecretShowDuration() + ' ]. Tip ' + secretPrice + 'tks to unblock the cam!'; setTimeout(function(){ // Send message cb.sendNotice(out,name,botBgColor,botTextColor,botTextWeight); }, botNoticeDelay); } } }); /* ------------------------------------------------ * Functions for different uses * ------------------------------------------------ */ /* * Returns a string with the duration of current Secret Show */ function getSecretShowDuration() { var currentTime = new Date(); var tmpTime = currentTime.getHours() * 3600 + currentTime.getMinutes() * 60 + currentTime.getSeconds() - secretStartTime.getHours() * 3600 - secretStartTime.getMinutes() * 60 - secretStartTime.getSeconds(); var showDuration = new Date(); showDuration.setHours(Math.floor(tmpTime / 3600)); showDuration.setMinutes(Math.floor((tmpTime - showDuration.getHours() * 3600) / 60)); showDuration.setSeconds(Math.floor((tmpTime - showDuration.getHours() * 3600 - showDuration.getMinutes() * 60))); return dateToString(showDuration); } /* * Returns the time in a Date object in string format: 1h 2mins 45secs */ function dateToString(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 the code of a requested color name */ function getColorCode(name) { for (var i=0; i<=COLORS.length; i++) { if (COLORS[i].name == name) { return COLORS[i].code; } } return "#FFFFFF"; cb.log('Error: Could not find the code for this color: ' + name); } /* * Returns the code of a requested color background */ function getBgColorCode(name) { for (var i=0; i<=COLORS.length; i++) { if (COLORS[i].name == name) { return COLORS[i].bgcode; } } return "#FFFFFF"; cb.log('Error: Could not find the bgcode for this color: ' + name); } /* * Return parameter in a certain position in a string */ function getParam(msg, position) { var tmp = msg.split(' '); return tmp[position]; } /* * Validates if number is Integer type * */ function isInteger(value) { return !isNaN(value) && parseInt(Number(value)) == value && !isNaN(parseInt(value, 10)); } /* * Add users that tipped the minimum to the Secret Show */ function addTippersToShow() { if (secretMin && loversList.length) { // Add tippers var out = ''; var added = 0; for ( i=0; i<loversList.length; i++) { if (loversList[i].tokens >= secretMin) { if (!cb.limitCam_userHasAccess(loversList[i].name)) { cb.limitCam_addUsers(loversList[i].name); added++; } } else break; } if (added) { out = added + ' user' + ((added > 1) ? 's' : '') + ' that tipped ' + secretMin + 'tks or more ha' + ((added > 1) ? 've' : 's') + ' been added to the show'; } if (out) { setTimeout(function(){ cb.sendNotice(out,'',botBgColor,botTextColor,'bolder'); }, 800); } } } /* * Sends info from this commands to the user or the room: * /tipmenu * /showmenu * /help * /lovers * @name: name of the user, '' = send to the room */ function sendCommand(target, command, param) { var head = ''; var outMsg = ''; var msgWeigth = botTextWeight; switch (command) { case 'modelhelp': head = ':mtlstar My Secret Show Help :mtlstar'; outMsg = modelHelp; break; } // Workaround for CB bug: this delay prevents message from being broken by command text in the room // Send Command response to user if (head) cb.sendNotice(head,target,botTextColor,'#FFFFFF','bold'); setTimeout(function(){ cb.sendNotice(outMsg,target,'',botTextColor,msgWeigth); }, botNoticeDelay); } /* * Sends the Secret Show notifier */ function announceSecretShow() { if (cb.limitCam_isRunning()) { var msg = 'Secret Show is running [ ' + getSecretShowDuration() + ' ]. Tip ' + secretPrice + 'tks to unblock the cam!'; // Random added delay -15 to +15s var delay = (Math.floor(Math.random() * 30) - 10) * 1000; cb.log('Delay: ' + delay); cb.sendNotice(msg, '', botBgColor, botTextColor, 'bold'); secretTimeout = cb.setTimeout(announceSecretShow, (secretTimer * 60000) + delay); } else { secretTimeout = 0; } } /* * Builds user vars and arrays based on settings */ function parseSettings() { // General bot settings botAnnounce = (cb.settings.secret_greet == 'Yes') ? 1 : 0; botCommand = '/'; // Secret Show settings secretPrice = cb.settings.secret_price; secretMessage = 'Secret Show in progress! Tip ' + secretPrice + ' To Join!'; secretMin = cb.settings.secret_min; secretTimer = cb.settings.secret_timer; secretAutoclean = (cb.settings.secret_autoclean == 'Yes') ? 1 : 0; if (cb.settings.secret_color) { botTextColor = getColorCode(cb.settings.secret_color); botBgColor = getBgColorCode(cb.settings.secret_color); } // Users and admin help var prefix = botCommand; modelHelp = '/ssbhelp ' + ARROW + ' Show a list with all secret show commands\n' + prefix + 'start ' + ARROW + ' Start a secret (hidden) show\n' + prefix + 'start [price] ' + ARROW + ' Start a secret (hidden) show with a custom price\n' + prefix + 'stop ' + ARROW + ' Stop a secret (hidden) show\n' + prefix + 'add [username] ' + ARROW + ' Add users from the secret viewers list\n' + prefix + 'remove [username] ' + ARROW + ' Remove users from the secret viewers list\n' + prefix + 'check [username] ' + ARROW + ' Check if a certain user is in the secret viewers list\n' + prefix + 'list' + ARROW + ' Show all the users in the secret viewers list'; } /* * Setting up the bot at start */ function init() { //Load user's settings values into global variables parseSettings(); // Workaround for CB bug that sends notices in wrong order setTimeout(function(){ // Bot loaded message cb.sendNotice(theHeader,'',botTextColor,"#FFFFFF",'bolder'); setTimeout(function(){ cb.sendNotice(loadText,'','',botTextColor,'bold'); }, botNoticeDelay); }, botNoticeDelay); } init();
© Copyright Chaturbate 2011- 2026. All Rights Reserved.