Apps Home
|
Create an App
My's Tipper's
Author:
rousell_and_thaylor_xxx
Description
Source Code
Launch App
Current Users
Created by:
Rousell_And_Thaylor_Xxx
/* * Title: My's Tipper's * Author: Rousell_And_Thaylor_xxx * Version: 2.3 13/01/2020 * Description: Customizable leaderboard app * * */ // Some useful characters var HEART = '\u2665'; // ♥ BDIAMOND = '\u2666'; // ♦ BSTAR = '\u2605'; // ★ WSTAR = '\u2606'; // ☆ // Main app object var topLovers = { // General bot variables botName : 'My Top Lovers', botVersion : '2.2', botDate : 'Oct 31, 2018', botIconL : ':mtlpheart', botIconR : ':mtlpheart2', boardIconL : ':mtlpheart', boardIconR : ':mtlpheart2', noticeDelay : 500, // Variables for Settings modelName : '', textColor : '', bgColor : '', textWeight : 'normal', topLoversTimer : 0, useHearts : true, heartIcon : '', newTopNotify : true, maxItems : 3, // Data Array loversList : [], HeartIcons : [ {name: 'Fuchsia', icon: ':mtlhfu'}, {name: 'Pink', icon: ':mtlhpi'}, {name: 'Purple', icon: ':mtlhpu'}, {name: 'Red', icon: ':mtlhre'} ], settings_choices : [ { name: 'max_lb', type: 'choice', choice1: 3, choice2: 4, choice3: 5, defaultValue: 3, label: '1. BOT SETTINGS ................... Number of Top Lovers', }, { name: 'hearts_lb', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes', label: 'Display a heart in messages from Top Lovers' }, { name: 'icons_lb', type: 'choice', label: 'Color for Top Lover\'s hearts', choice1: 'Fuchsia', choice2: 'Pink', choice3: 'Purple', choice4: 'Red', defaultValue: 'Fuchsya' }, { name: 'announce_lb', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes', label: "Announce new Top Lover" }, { name: 'lovers_show_board', type: 'choice', choice1: 'Yes', choice2: 'No (Skip next setting)', defaultValue: 'Yes', label: 'Display leaderboard in the room' }, { 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: 25, choice13: 30, defaultValue: 6, label: 'Display frequency (mins)' }, { name: 'model_lb', type: 'str', minLength: 0, maxLength: 21, required: true, defaultValue: cb.room_slug.charAt(0).toUpperCase() + cb.room_slug.slice(1), label: '2. PERSONALIZATION ........ Model name in leaderboard' }, { name: 'lovers_special', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes', label: 'Display special icons in certain dates (e.g. Halloween)' }, { name: 'color_lb', type:'choice', label:'Color scheme', choice1: 'Custom (Define below)', choice2: 'Amaranth', choice3: 'Black', choice4: 'Blue', choice5: 'SteelBlue', choice6: 'DarkBlue', choice7: 'BrownRed', choice8: 'DarkViolet', choice9: 'SeanceViolet', choice10: 'Green', choice11: 'DarkGreen', choice12: 'Pink', choice13: 'Purple', choice14: 'Red', choice15: 'TorchRed', choice16: 'Turquoise', choice17: 'SlateGray', defaultValue: 'Purple' }, { name: 'lovers_custom_text', type: 'str', minLength: 0, maxLength: 7, required: false, label: 'Custom text color (HTML code with #)', defaultValue: '#000000' }, { name: 'lovers_custom_background', type: 'str', minLength: 0, maxLength: 7, required: false, label: 'Custom background color (HTML code with #)', defaultValue: '#F1F1F1' }, { name: 'lovers_highlight', type: 'choice', label: 'Use colored background', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes' }, ], // Handle new message onMessage : function (msg) { var name = msg['user']; var model = cb.room_slug; var isModel = (name == model); var isUnknownCmd = (msg.m.charAt(0) == '/'); // Command /lovers if (msg.m.indexOf('/lovers') == 0 || msg.m.indexOf('!lovers') == 0) { var message = msg['m'].substr(1); var userParam = utils.getParam(message,0); var userParam2 = utils.getParam(message,1); var userParam3 = utils.getParam(message,2); var userParam4 = utils.getParam(message,3); var head = ''; var userMsg = ''; isUnknownCmd = false; model = model.charAt(0).toUpperCase() + model.slice(1); msg['m'] = msg['m'] + " (lovers list sent to " + name + ")"; if (this.loversList.length > 0) { head = this.boardIconL + ' ' + this.modelName + '\'s Lovers List ' + this.boardIconR; for (var i = 0; i < this.loversList.length; i++){ /* Add \n before starting a new line */ if (i > 0) userMsg += '\n'; /* Add a new tipper if available */ if (i < this.loversList.length) { userMsg += '' + (i + 1) + '. ' + this.loversList[i].name + ' (' + this.loversList[i].tokens + ' tks)'; } else { userMsg += '' + (i + 1) + '. ---------------------'; } } } else { userMsg = 'No lovers yet! Tip now and become the top lover!'; } // Send results // Workaround for CB bug: this delay prevents message from being broken by command text in the room if (head) utils.delayedNotice(300,head,name,this.textColor,'#FFFFFF','bold'); utils.delayedNotice(600,userMsg,name,this.bgColor,this.textColor,'normal'); } // Top Tipper? Let's add a heart to the msg if (this.useHearts && !isUnknownCmd) { var pos = this.getTopLover(name); if (pos > 0) { msg['m'] = '' + this.heartIcon + pos + ' ' + msg['m']; } } // Tip test if (isModel) this.tipTest(msg.m); return msg; }, // Handle new tip onTip : function (tip) { var username = tip.from_user; var amount = parseInt(tip.amount); var found = false; var isMVP = false; // Handle Lovers List if (this.loversList.length > 0) { isMVP = (username == this.loversList[0].name); } // Update tipper for (var i = 0; i < this.loversList.length; i++) { if (this.loversList[i].name == username) { this.loversList[i].tokens += amount; found = true; break; } } // Add a new one if (!found) this.loversList.push({ name: username, tokens: amount }); // Sort the array this.loversList.sort(function(a, b) { return b.tokens - a.tokens; }); /* Is new Top Lover? Let's announce it! */ if (!isMVP && this.loversList[0].name == username && this.newTopNotify) { var msg = ':mtlstar ' + this.loversList[0].name + ' :mtlstar is the new Top Lover with ' + this.loversList[0].tokens + ' tokens!'; cb.sendNotice(msg,'',this.textColor,'#ffffff','bold'); } }, /* * Returns the heart icon of a certain name */ getHeartsIcon : function (name) { for (var i=0; i<this.HeartIcons.length; i++) { if (this.HeartIcons[i].name == name) { return this.HeartIcons[i].icon; } } cb.log('Error: Could not find the icon for this heart color: ' + name); return ''; }, /* * Returns the user object from the tippers list matching the name */ getTipper : function (name) { if (this.loversList.length > 0) { for (var i=0; i<this.loversList.length; i++) { if (this.loversList[i].name == name) { return this.loversList[i]; } } } return 0; }, /* * Returns the name of the lover with more tokens */ getTopLover : function (name) { if (this.loversList.length > 0) { for (var i=0; i<Math.min(this.loversList.length, this.maxItems); i++) { if (this.loversList[i].name == name) { return i+1; } } } cb.log('User not in the top ' + this.maxItems + ' lovers.'); return 0; }, // 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}); } } }, /* * Sends the lovers list to the room */ displayLoversList : function () { var msgHead = ''; var msgRoom = ''; /* Build the lovers list */ if (this.loversList.length > 0) { /* Add header */ msgHead = this.boardIconL + ' ' + this.modelName + '\'s Top Lovers ' + this.boardIconR; for (var i = 0; i < this.maxItems; i++){ /* Add \n before starting a new line */ if (i > 0) { msgRoom += '\n'; } /* Add a new tipper if exists */ if (i < this.loversList.length) { msgRoom += '' + (i + 1) + '. ' + this.loversList[i].name + ' (' + this.loversList[i].tokens + ' tks)'; } else { msgRoom += '' + (i + 1) + '. ---------------------'; } } /* More lovers? Invite viewers to see full list! */ if (this.loversList.length > this.maxItems) { 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,'',this.textColor,'#FFFFFF','bold'); cb.sendNotice(msgRoom,'',this.bgColor,this.textColor,'normal'); cb.setTimeout(this.displayLoversList.bind(this), (this.topLoversTimer * 60000)); }, specialDates : function () { var currentDate = new Date(); // Christmas period if (currentDate.getMonth() == 11 && (currentDate.getDate() > 22) && (currentDate.getDate() < 26)) { this.boardIconL = ':mtlsanta2'; this.boardIconR = ':mtlsanta'; } // Halloween if (currentDate.getMonth() == 9 && (currentDate.getDate() > 29)) { this.boardIconL = ':mtlpumpkin16'; this.boardIconR = ':mtlpumpkin16'; } }, /* * Builds user vars and arrays based on settings */ parseSettings : function () { var out = ''; if (cb.settings.model_lb) this.modelName = cb.settings.model_lb.trim(); if (!this.modelName) this.modelName = cb.room_slug.charAt(0).toUpperCase() + cb.room_slug.slice(1); if (cb.settings.color_lb) { if (cb.settings.color_lb != 'Custom (Define below)') { // Bot colors this.textColor = utils.getColorCode(cb.settings.color_lb); if (cb.settings.lovers_highlight == 'Yes') { this.bgColor = utils.getBgColorCode(cb.settings.color_lb); } } else { // Custom colors if (utils.isHexColor(cb.settings.lovers_custom_text)) { if (cb.settings.lovers_highlight == 'Yes') { if (utils.isHexColor(cb.settings.lovers_custom_background)) { cb.log(cb.settings.lovers_custom_text); cb.log(cb.settings.lovers_custom_background); this.textColor = cb.settings.lovers_custom_text; this.bgColor = cb.settings.lovers_custom_background; } else { this.textColor = utils.getColorCode('Purple'); this.bgColor = utils.getBgColorCode('Purple'); out += 'Error: Custom background color is not a valid HTML color code.'; } } else { this.textColor = cb.settings.lovers_custom_text; } } else { this.textColor = utils.getColorCode('Purple'); this.bgColor = utils.getBgColorCode('Purple'); out += 'Error: Custom text color is not a valid HTML color code.'; } } } this.maxItems = cb.settings.max_lb; if (cb.settings.lovers_show_board == 'Yes') { this.topLoversTimer = cb.settings.timer_lb; } else { this.topLoversTimer = 0; } this.useHearts = (cb.settings.hearts_lb == 'Yes'); this.newTopNotify = (cb.settings.announce_lb == 'Yes'); this.heartIcon = this.getHeartsIcon(cb.settings.icons_lb); if (!this.heartIcon) this.heartIcon = ':001h'; // Report errors if (out) { out = out.replace(/\.(?!$)/g,'.\n'); utils.delayedNotice(1000,out,cb.room_slug,'', '#ff0000','bold'); } }, // Set up bot and start! init : function () { // Add My Top Lovers settings cb.settings_choices.push.apply(cb.settings_choices, this.settings_choices); // Pick settings values this.parseSettings(); // Set icons for special dates if (cb.settings.lovers_special == 'Yes') this.specialDates(); // Start notifier if (this.topLoversTimer) cb.setTimeout(this.displayLoversList.bind(this), (this.topLoversTimer * 70000)); // Bot loaded messages utils.delayedNotice(this.noticeDelay,this.botIconL + ' ' + topLovers.botName + ' v' + topLovers.botVersion + ' ' + this.botIconR,'',this.textColor,'#FFFFFF','bold'); utils.delayedNotice(this.noticeDelay+200,'Built by noiett (' + topLovers.botDate + ')','','',this.textColor,'normal'); } } /* * Utils Object */ var utils = { // Data colors : [ { name: 'Amaranth', code: '#c92572', bgcode: '#f9eaf1'}, { name: 'Black', code: '#000000', bgcode: '#e8e8e8'}, { name: 'Blue', code: '#016ea6', bgcode: '#e3eff6'}, { 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: '#f1e4f1'}, { name: 'Red', code: '#ff3232', bgcode: '#ffebeb'}, { name: 'TorchRed', code: '#FF0040', bgcode: '#ffe5e5'}, { name: 'Turquoise', code: '#188b8c', bgcode: '#e2f6f6'}, { name: 'SlateGray', code: '#708090', bgcode: '#eaeff3'}, ], // Methods getColorCode : function (name) { for (var i=0; i<=this.colors.length; i++) { if (this.colors[i].name == name) { return this.colors[i].code; } } cb.log('Error: Could not find the code for this color: ' + name); return "#FFFFFF"; }, getBgColorCode : function (name) { for (var i=0; i<=this.colors.length; i++) { if (this.colors[i].name == name) { return this.colors[i].bgcode; } } cb.log('Error: Could not find the bgcode for this color: ' + name); return "#FFFFFF"; }, isHexColor : function (code) { return /^#[0-9A-F]{6}$/i.test(code); }, splitMe : function (e) { return e.trim().replace(/\s+/g, " ").split(" ") }, /* * Return parameter in a certain position in a string */ getParam : function (msg, position) { var tmp = msg.split(' '); return tmp[position]; }, /* * 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) { return topLovers.onMessage(msg); }); cb.onTip(function (tip) { topLovers.onTip(tip); }); cb.settings_choices = []; // Load me! topLovers.init();
© Copyright Freesexcam 2011- 2024. All Rights Reserved.