Bots Home
|
Create an App
My Lover's leaderboard
Author:
nice_cpl_sex
Description
Source Code
Launch Bot
Current Users
Created by:
Nice_Cpl_Sex
/* * Title: My Lover's leaderboard * Author: nice_cpl_sex * Email: nicecplx75@gmail.com * Twitter: nicecplx75 * Version: 1.1 nov 29, 2017 * Description: A nice-looking, customizable leaderboard app * * */ // CONSTANTS var COLORS = [ {name: 'Black', code: '#000000'}, {name: 'Blue', code: '#4159b5'}, {name: 'DarkBlue', code: '#1b1b7b'}, {name: 'Brown', code: '#8B0000'}, {name: 'DarkViolet', code: '#9c3dc4'}, {name: 'Green', code: '#327939'}, {name: 'IndianRed', code: '#CD5C5C'}, {name: 'Orange', code: '#dd5d0c'}, {name: 'Pink', code: '#FF00BA'}, {name: 'Purple', code: '#800080'}, {name: 'Red', code: '#FF0000'}, {name: 'DarkRed', code: '#C10000'}, {name: 'SlateGray', code: '#708090'}, {name: 'SteelBlue', code: '#4682B4'}, {name: 'Yellow', code: '#FFA500'} ]; var HEARTS = [ {name: 'Fuchsia', icon: ':mtlhfu'}, {name: 'Pink', icon: ':mtlhpi'}, {name: 'Purple', icon: ':mtlhpu'}, {name: 'Red', icon: ':mtlhre'} ]; // Some useful characters var HEART = '\u2665'; // ♥ BDIAMOND = '\u2666'; // ♦ BSTAR = '\u2605'; // ★ WSTAR = '\u2606'; // ☆ // Number of Top Lovers to show var ITEMS_LB = 3; // Variables for Settings var loversListColor = ''; var loversListTimer = 0; var loversHearts = true; var heartsIcon = ''; var loversAnnounce = true; // Special design for headers in a separate notice (buggy due to cb problems) var niceHeaders = true; // VARIABLES var botVersion = "1.2"; var botDate = "Jul 26, 2017"; var noticeDelay = 400; var loversList = []; var modelName = cb.room_slug; // TEXTS var botCommand = '/bot'; var theHeader = ':mtlstar My Top Lovers v' + botVersion + ' :mtlstar'; var loadText = 'Built by noiett (' + botDate + ')'; // SETTINGS cb.settings_choices = [ { name: 'color_lb', type:'choice', label:'Color for notices in room', choice1: 'Black', choice2: 'Blue', choice3: 'DarkBlue', choice4: 'Brown', choice5: 'DarkViolet', choice6: 'Green', choice7: 'IndianRed', choice8: 'Orange', choice9: 'Pink', choice10: 'Purple', choice11: 'Red', choice12: 'DarkRed', choice13: 'SlateGray', choice14: 'SteelBlue', choice15: 'Yellow', defaultValue: 'Purple' }, { name: 'hearts_lb', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes', label: 'Hearts before Top Lover\'s messages' }, { name: 'icons_lb', type: 'choice', label: 'Hearts color', choice1: 'Fuchsia', choice2: 'Pink', choice3: 'Purple', choice4: 'Red', defaultValue: 'Pink' }, { name: 'announce_lb', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes', label: "Announce new Top Lover" }, { name: 'timer_lb', 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: 6, label: 'Top Lovers Display frequency (mins)' }, ]; // FUNCTIONS cb.onMessage(function (msg) { // Some variables var name = msg['user']; var model = cb.room_slug; // Command /lovers if (msg.m.indexOf('/lovers') == 0 || msg.m.indexOf('!lovers') == 0) { var head = ''; var userMsg = ''; model = model.charAt(0).toUpperCase() + model.slice(1); msg['m'] = msg['m'] + " (lovers list sent to " + msg['user'] + ")"; if (loversList.length > 0) { head = ':mtlpheart ' + model + '\'s Lovers list :mtlpheart2'; for (var i = 0; i < loversList.length; i++){ /* Add \n before starting a new line */ if (i > 0) { userMsg += '\n'; } /* Add a new tipper if available */ if (i < loversList.length) { userMsg += '' + (i + 1) + '. ' + loversList[i].name + ' (' + loversList[i].tokens + ' tks)'; } else { userMsg += '' + (i + 1) + '. ---------------------'; } } } else { userMsg = 'No lovers yet! Tip now and become the top lover!'; } if (!niceHeaders) { userMsg = head + '\n' + userMsg; head = ''; } // Workaround for CB bug: this delay prevents message from being broken by command text in the room setTimeout(function(){ // Send Command response to user if (head) cb.sendNotice(head,name,loversListColor,'#FFFFFF','bold'); cb.sendNotice(userMsg,name,'',loversListColor,'normal'); }, noticeDelay); } // Top Tipper? Let's add a heart to the msg if (loversHearts) { var pos = getTopLover(msg['user']); if (pos > 0) { msg['m'] = '' + heartsIcon + pos + ' ' + msg['m']; } } 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; }); /* Is new Top Lover? Let's announce it! */ if (!isMVP && loversList[0].name == username && loversAnnounce) { var msg = ':mtlstar ' + loversList[0].name + ' :mtlstar is the new Top Lover with ' + loversList[0].tokens + ' tokens!'; cb.sendNotice(msg,'',loversListColor,'#FFFFFF','bold'); } }); /* * Returns the name of the lover with more tokens */ function getTopLover(name) { if (loversList.length > 0) { for (var i=0; i<Math.min(loversList.length, 3); i++) { if (loversList[i].name == name) { return i+1; } } } cb.log('User not in the top 3 lovers.'); return 0; } /* * Returns the name of the heart emote of a certain color */ function getHeartsIcon(name) { for (var i=0; i<HEARTS.length; i++) { if (HEARTS[i].name == name) { return HEARTS[i].icon; } } return false; cb.log('Error: Could not find the icon for this heart color: ' + name); } /* * 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); } /* * Sends the lovers list to the room */ function announceLoversList() { var target = ''; var msgHead = ''; var msgRoom = ''; /* Build the lovers list */ if (loversList.length > 0) { /* Add header */ var name = cb.room_slug; name = name.charAt(0).toUpperCase() + name.slice(1); msgHead = ':mtlpheart ' + name + '\'s Top Lovers :mtlpheart2'; for (var i = 0; i < ITEMS_LB; i++){ /* Add \n before starting a new line */ if (i > 0) { msgRoom += '\n'; } /* Add a new tipper if exists */ if (i < loversList.length) { msgRoom += '' + (i + 1) + '. ' + loversList[i].name + ' (' + loversList[i].tokens + ' tks)'; } else { msgRoom += '' + (i + 1) + '. ---------------------'; } } /* More lovers? Invite viewers to see full list! */ if (loversList.length > ITEMS_LB) { msgRoom += '\nType /lovers to see the full list!'; } } else { msgRoom = 'No lovers yet! Tip now and become the top lover!'; } if (msgHead) cb.sendNotice(msgHead,target,loversListColor,'#FFFFFF','bold'); cb.sendNotice(msgRoom,target,'',loversListColor,'normal'); cb.setTimeout(announceLoversList, (loversListTimer * 60000)); } /* * Builds user vars and arrays based on settings */ function loadSettings() { if (cb.settings.color_lb) { loversListColor = getColorCode(cb.settings.color_lb); } loversListTimer = cb.settings.timer_lb; loversHearts = (cb.settings.hearts_lb == 'Yes') ? 1 : 0; loversAnnounce = (cb.settings.announce_lb == 'Yes') ? 1 : 0; heartsIcon = getHeartsIcon(cb.settings.icons_lb); if (!heartsIcon) heartsIcon = ':001h'; } /* * Setting up the bot at start */ function init() { //Load values in settings to global variables loadSettings(); // Start Lovers list cb.setTimeout(announceLoversList, (loversListTimer * 70000)); // Bot loaded message cb.sendNotice(theHeader,'',loversListColor,"#FFFFFF",'bolder'); cb.sendNotice(loadText,'','',loversListColor,'bold'); } init();
© Copyright Chaturbate 2011- 2026. All Rights Reserved.