Bots Home
|
Create an App
suite
Author:
modelsuite
Description
Source Code
Launch Bot
Current Users
Created by:
Modelsuite
const MAX_TIP_MENU_ITEMS = 20; var lineBreak = '\n'; var everyone = ''; // status var Status = { DISABLED : -1, STOPPED : 0, RUNNING : 1, PAUSED : 2 }; // colors var colors = { orange : '#dc5500', red : '#ff0000', green : '#009900', darkpurple : '#5f497a' , lightpurple : '#be6aff', darkblue : '#1f497d', lightblue : '#6699aa', }; // unicodes var unicodeChars = { space : '\u0020', dot : '\u22c5', // dot star : '\u2605', // filled star whiteStar : '\u2606', // white star square : '\u25fc', triangleRight : '\u25b6', dashChar : '\u2500', whiteHeart : '\u2661', arrow : '\u2192', triangleDown : '\u25bc', }; var emojis = { } // bots unicodes var botsUnicodes = { tipMenuBot : emojis.lifter, }; var defaultSettings = { backgroundColor: '', foregroundColor : colors.lightpurple, tipMenu : { enabled : true, unicode : botsUnicodes.tipMenuBot, format : "line", happyTimeEnabled : false, happyTimeLength : 60, happyTimeTriggerTip : 1000, happyTimeDiscount : 50, fanClubDiscount : 20, noticeTimeout : 3, timeout : 180, tipForegroundColor : colors.white, tipBackgroundColor : colors.green, foregroundColor : colors.lightpurple, backgroundColor : colors.white, }, }; var botsData = { bots : { /////////////////////// // tip menu bot data // /////////////////////// tipMenu : { status : Status.DISABLED, name : 'Tip menu bot', enabled : false, fanClubDiscount : 0, discount : 0, timeoutId : undefined, timeout : 10, history : [], items : [], happyTimeEnabled : false, happyTimeTriggered : false, happyTimeEnd : 0, happyTimeTimeoutId : undefined, happyTimeElapsedTimeoutId : undefined, happyTimeTriggerTip : 0, happyTimeLength : 0, happyTimeDiscount : 1, }, }, start : 0, commandsConfig : { "/tmb": { cmd: "tipmenu all" }, "/ht": { cmd: "tipmenu happytime" }, "/tm": { cmd: "tipmenu" }, "/tipmenu":{ cmd: "tipmenu" }, }, helpMessages : { tipMenu : [ ['bmr', repeat(botsUnicodes.tipMenuBot,5) + ' COMMANDS FOR THE TIP MENU BOT' + repeat(botsUnicodes.tipMenuBot,5) ], ['bmr', botsUnicodes.tipMenuBot + ' "/tm help" : shows this help text'], ['bmr', botsUnicodes.tipMenuBot + ' "/tm or /tipmenu" : shows the tip menu'], ['bm', botsUnicodes.tipMenuBot + ' "tm history" : shows the tip menu history'], ['bm', botsUnicodes.tipMenuBot + ' "/tm counter" : shows the tip menu counter'], ['bm', botsUnicodes.tipMenuBot + ' "/tm rm <index>" : Removes from the menu the item with the index <index>'], ['bm', botsUnicodes.tipMenuBot + ' "/tm add <amount> <description>" : adds a new item to the tip menu'], ['bm', botsUnicodes.tipMenuBot + ' "/tm off" : stops tip menu bot'], ['bm', botsUnicodes.tipMenuBot + ' "/tm on" : starts the tip menu bot if it is not running'], ['bm', botsUnicodes.tipMenuBot + ' "/ht on" : enable happy time feature'], ['bm', botsUnicodes.tipMenuBot + ' "/ht off" : disable happy time feature'], ['bm', botsUnicodes.tipMenuBot + ' "/ht <percentage>" : sets percentage discount for happy time'], ['bm', botsUnicodes.tipMenuBot + ' "/ht time <seconds>" : sets happy time length in seconds'], ['bm', botsUnicodes.tipMenuBot + ' "/tm fan off" : disable fan club discount'], ['bm', botsUnicodes.tipMenuBot + ' "/tm fan on" : disable fan club discount'], ['bm', botsUnicodes.tipMenuBot + ' "/tm fan <percentage>" : sets percentage discount for fan club'], // broadcast messages ['bm', botsUnicodes.tipMenuBot + ' "/tmb" : shows the fit menu to everyone'], ['bm', botsUnicodes.tipMenuBot + ' "/tmb off" : stops the fit menu periodic notice'], ['bm', botsUnicodes.tipMenuBot + ' "/tmb on <minutes>" : shows the fit menu to everyone every <minutes> minutes'] ], }, welcomeMessages : [ ['', ' Welcome to my room $user ! :mclap'], ['', ' > type /tm or /tipmenu for my tip menu'], ], }; cb["settings_choices"] = []; cb.settings_choices.push( { name : "tipMenuEnabled", label : "1) TIP MENU BOT SETTINGS (Only items with a description and price will be considered) ............................................. Tip menu enabled ", type : "choice", choice1 : 'yes', choice2 : 'no', default : defaultSettings.tipMenu.enabled ? "yes" : "no", required : true }, { name : "happyTimeEnabled", label : "Enable happy time feature ", type : "choice", choice1 : "yes", choice2 : "no", default : defaultSettings.tipMenu.happyTimeEnabled ? "yes" : "no", required : true, }, { name : "happyTimeLength", label : "Happy time length in seconds (30 - 300)", type : "int", minValue : 30, maxValue : 300, default : defaultSettings.tipMenu.happyTimeLength, required : false }, { name : "happyTimeTriggerTip", label : "Tip amount that launches the happy time ", type : "int", minValue : 0, maxValue : 10000, default : defaultSettings.tipMenu.happyTimeTriggerTip, required : false }, { name : "happyTimeDiscount", label : "Sale % to apply to price (0 - 100)", type : "int", minValue : 0, maxValue : 100, default : defaultSettings.tipMenu.happyTimeDiscount, required : false }, { name : "fanClubDiscount", label : "Sale % to apply to price (0 - 100) for fan club members ", type : "str", minLength : 1, maxLength : 3, default : defaultSettings.tipMenu.fanClubDiscount, required : false }); for(i = 0; i < MAX_TIP_MENU_ITEMS; i++) { cb.settings_choices.push({ name : "tipMenuItemDescription" + i, label : "menu item " + (i+1) + " description ----> ", type : "str", minLength : 3, maxLength : 255, default : "", required : false }, { name : "tipMenuItemAmount" + i, label : "price ", type : "str", minLength : 1, maxLength : 255, default : "", required : false }); } function elapsed(begin, end) { var milliseconds = end - begin; //Get hours from milliseconds var hours = milliseconds / (1000*60*60); var absoluteHours = Math.floor(hours); // var h = absoluteHours > 9 ? absoluteHours : '0' + absoluteHours; //Get remainder from hours and convert to minutes var minutes = (hours - absoluteHours) * 60; var absoluteMinutes = Math.floor(minutes); // var m = absoluteMinutes > 9 ? absoluteMinutes : '0' + absoluteMinutes; //Get remainder from minutes and convert to seconds var seconds = (minutes - absoluteMinutes) * 60; var absoluteSeconds = Math.floor(seconds); // var s = absoluteSeconds > 9 ? absoluteSeconds : '0' + absoluteSeconds; return {hours: absoluteHours , minutes: absoluteMinutes , seconds: absoluteSeconds}; } ////////////////////////////////////// // welcome and help message methods // ////////////////////////////////////// function getWelcomeMessage(user) { var resultString = lineBreak; botsData.welcomeMessages.forEach(function(item){ if(item[0].length == 0 || item[0].indexOf("m") >= 1 && user.is_mod || item[0].indexOf("r") >= 1) resultString += item[1].replace('$user', user.user) + lineBreak ; }); return resultString; } function getFullHelp(message) { return getTipMenuHelp(message); } function getTipMenuHelp(message) { var resultString = lineBreak, isOwner = (message.user == cb.room_slug), isMod = (message.is_mod); botsData.helpMessages.tipMenu.forEach(function(item){ if(item[0].length == 0 || item[0].indexOf("m") >= 0 && isMod || item[0].indexOf("b") >= 0 && isOwner || item[0].indexOf("r") >= 0 && (!isOwner && !isMod)) resultString += item[1] + lineBreak ; }); return resultString.trim().length == 0? "" : resultString; } //////////// // Events // //////////// /** user: user who entered the room in_fanclub: is the user in the broadcaster’s fan club has_tokens: does the user have at least 1 token is_mod: is the user a moderator tipped_recently: is the user a “dark blue”? tipped_alot_recently: is the user a “purple”? tipped_tons_recently: is the user a “dark purple”? gender: “m” (male), “f” (female), “s” (trans), or “c” (couple) */ cb.onEnter(function(user){ sendWelcomeMessage(user); }); /** amount: amount of tip message: message in tip to_user: user who received tip from_user: user who sent tip from_user_in_fanclub: is the user in the broadcasters fan club from_user_has_tokens: does the user have at least 1 token from_user_is_mod: is the user a moderator from_user_tipped_recently: is the user a “dark blue”? from_user_tipped_alot_recently: is the user a “purple”? from_user_tipped_tons_recently: is the user a “dark purple”? from_user_gender: “m” (male), “f” (female), “s” (trans), or “c” (couple) */ cb.onTip(function( tipData ){ tip (tipData); }); /** c: message color m: the message text user: username of message sender f: message font in_fanclub: is the user in the broadcasters fan club has_tokens: does the user have at least 1 token is_mod: is the user a moderator tipped_recently: is the user a “dark blue”? tipped_alot_recently: is the user a “purple”? tipped_tons_recently: is the user a “dark purple”? gender: “m” (male), “f” (female), “s” (trans), or “c” (couple) */ cb.onMessage(function( message ){ var username = message.user, commandString = stripCommandFromMessage(message.m); // if it's a command, process it if (commandString) { var errorMsg = processCommand(message, commandString); if (errorMsg === false ) return message; if ( errorMsg ) sendErrorNotice(username, errorMsg, commandString); message['m'] = ''; message['X-Spam'] = true; return message; } return message; }); ///////////////// // Send notice // ///////////////// function sendNotice(user, message, foregroundColor, backgroundColor, group) { var fg = foregroundColor || botsData.foregroundColor; var bg = backgroundColor|| botsData.backgroundColor; var grp = group || ""; cb.sendNotice(message, user, bg, fg, 'normal', grp); } function sendBoldNotice(user, message, foregroundColor, backgroundColor, group) { var fg = foregroundColor || botsData.foregroundColor; var bg = backgroundColor|| botsData.backgroundColor; var grp = group || ""; cb.sendNotice(message, user, bg, fg, 'bold', grp); } function sendErrorNotice(username, message, commandString) { message = lineBreak + ' Error command : /' + commandString + lineBreak + unicodeChars.square + message + lineBreak; sendBoldNotice(username, message); } /////////// // Utils // /////////// function padRight(char, length) { return char + repeat(char, length); } function padLeft(char, length) { return repeat(char, length) + char; } function repeat(char, length) { var result = ""; while(length--) result += char; return result; } function bracket(string, unicode, length = 5, verticalPadding = 0) { var lines = string.trim().split(lineBreak), resultString = ''; lines.forEach( function( line, index ){ lines[index] = unicode + ' ' + line; }); resultString += (((unicode == '') && (unicode = '-'), length > 0 ? repeat(unicode, length) + lineBreak :'')); resultString += ((unicode == '') && (unicode = '|') , repeat((unicode + lineBreak), verticalPadding)) + lines.join('\n') + ((unicode == '') && (unicode = '|') , repeat((lineBreak + unicode), verticalPadding)) resultString += (((unicode == '') && (unicode = '-'), length > 0 ? (lineBreak + repeat(unicode, length)) :'')); return resultString; } function fanPrice(amount) { var fansDiscount = botsData.bots.tipMenu.fanClubDiscount; return Math.floor(amount * (1 - fansDiscount/100)); } function happyTimePrice(amount) { var happyTimeDiscount = botsData.bots.tipMenu.happyTimeDiscount; return Math.floor(amount * (1 - happyTimeDiscount/100)); } ///////// // tip // ///////// function checkTipMenu(user, amount) { var tipMenuBot = botsData.bots.tipMenu, happyTimeTriggered = tipMenuBot.happyTimeTriggered, tipMenuList = tipMenuBot.items; tipMenuBot.enabled && tipMenuList.forEach(function(item, index) { if (discountPrice(item.amount, user) == amount) { tipMenuList[index].times += 1; tipMenuBot.history.push({user: user.user, description:item.description, time: new Date().getTime(), happyTime: happyTimeTriggered}); sendTipMenuNotice( user.user, tipMenuList[index].description); } }); } function checkHappyTime(amount) { var tipMenuBot = botsData.bots.tipMenu; if (tipMenuBot.happyTimeEnabled && (amount == tipMenuBot.happyTimeTriggerTip)) { triggerHappyTime(); } } function objectSize(object) { var result = 0; for (var item in object) { if(object.hasOwnProperty(item)){ result++; } } return result; } function tip(tipData) { var amount = tipData.amount, multiGoalBot = botsData.bots.multiGoal, user = { user : tipData.from_user, in_fanclub : tipData.from_user_in_fanclub, // TODO change this is_mod : tipData.from_user_is_mod, has_tokens : tipData.from_user_has_tokens, tipped_recently : tipData.from_user_tipped_recently, tipped_alot_recently : tipData.from_user_tipped_alot_recently, tipped_tons_recently : tipData.from_user_tipped_tons_recently, gender : tipData.from_user_gender, }; // currentKingTipper = botsData.bots.tippersBot.kingTipper, // currentBombTipper = botsData.bots.tippersBot.bombTipper, // message = []; checkHappyTime(amount); checkTipMenu(user, amount); } //////////////////////// // Commands procesing // //////////////////////// function stripCommandFromMessage(originalMessage) { // cycle through the commands list for (var command in botsData.commandsConfig){ var index = originalMessage.toLowerCase().indexOf(command); // find alias in the message if (index >= 0) { // if alias is found var commandArray = splitBySpaces(originalMessage.substring(index)); // cut into pieces the message starting from the command return originalMessage.substring(index).replace(commandArray[0], botsData.commandsConfig[command]['cmd']); // return the message but replaced the alias for the command } } } function processCommand(message, commandString) { var commandArray = splitBySpaces(commandString.toLowerCase()), command = commandArray[0]; if ( command == 'tipmenu') { return processTipMenuCommand(message, commandArray, commandString); } return void 0; } function processTipMenuCommand(message, commandArray) { var tipMenuBot = botsData.bots.tipMenu; ////////////////////////////////// // first: commands for everyone // ////////////////////////////////// if (commandArray.length == 2 && commandArray[1] == 'help') { sendTipMenuHelp(message); return; } if (commandArray.length == 1) { sendTipMenu(message); return; } if (message.user !== cb.room_slug && !message.is_mod) { return false; } ///////////////////////////////////////////// // then: commands for mods and broadcaster // ///////////////////////////////////////////// // Add item to menu if (commandArray.length > 3 && commandArray[1] == 'add' && !isNaN(parseInt(commandArray[2]))){ var menuItem = commandArray.slice(3).join(' '), index = insertInTipMenu(commandArray[2], menuItem); sendAddTipMenuResult(message.user, menuItem, commandArray[2], index); return; } // remove item from menu if (commandArray.length == 3 && commandArray[1] == 'rm' && !isNaN(parseInt(commandArray[2]))) { removeFromTipMenu(parseInt(commandArray[2])); sendRemoveTipMenuResult(message.user, commandArray[2]); return; } // show history if (commandArray.length == 2 && 'history'.indexOf(commandArray[1].toLowerCase()) == 0) { sendTipMenuHistory(); return; } // show counter if (commandArray.length == 2 && 'counter'.indexOf(commandArray[1].toLowerCase()) == 0) { sendTipMenuCounter(); return; } // stop running bot if (commandArray.length == 2 && commandArray[1] == 'off') { stopBot(message.user, 'tipMenuBot'); return; } // run bot if (commandArray.length == 2 && commandArray[1] == 'on') { runBot(message.user,'tipMenuBot'); return; } // turn off happy time if (commandArray.length == 3 && 'happytime'.indexOf(commandArray[1].toLowerCase()) == 0 && commandArray[2] == 'off') { disableHappyTime(); return; } // turn on happy time if (commandArray.length >= 3 && 'happytime'.indexOf(commandArray[1].toLowerCase()) == 0 && commandArray[2] == 'on') { var discount = commandArray[3] && !isNaN(parseInt(commandArray[3])) ? (parseInt(commandArray[3]) > 99 ? 99 : parseInt(commandArray[3])) : undefined, trigger = commandArray[4] && !isNaN(parseInt(commandArray[4])) ? (parseInt(commandArray[4]) > 1000 ? 1000 : parseInt(commandArray[4])) : undefined; time = commandArray[5] && !isNaN(parseInt(commandArray[5])) ? (parseInt(commandArray[5]) > 300 ? 300 : parseInt(commandArray[5])) : undefined; botsData.bots.tipMenu.happyTimeDiscount = discount ? discount : defaultSettings.tipMenu.happyTimeDiscount; botsData.bots.tipMenu.happyTimeLength = time ? time : defaultSettings.tipMenu.happyTimeLength; botsData.bots.tipMenu.happyTimeTriggerTip = trigger ? trigger : defaultSettings.tipMenu.happyTimeTriggerTip; enableHappyTime(); return; } // broadcast tip menu if (commandArray.length == 2 && 'all'.indexOf(commandArray[1].toLowerCase()) == 0) { broadcastTipMenu(); return; } // stop periodic notice if (commandArray.length == 3 && 'all'.indexOf(commandArray[1].toLowerCase()) == 0 && commandArray[2] == 'off') { tipMenuBot.timeoutId = cb.cancelTimeout(tipMenuBot.timeoutId); sendTipMenuBroadcastOff(message.user); return; } // start periodic notice if (commandArray.length == 4 && commandArray[1] == 'all' && commandArray[2] == 'on' && !isNaN(parseInt(commandArray[3])) && parseInt(commandArray[3]) > 0) { tipMenuBot.timeoutId = cb.cancelTimeout(tipMenuBot.timeoutId); tipMenuBot.timeout = parseInt(commandArray[3]); broadcastTipMenuTimeout(); // feedback to user sendTipMenuBroadcastOn(message.user, parseInt(tipMenuBot.timeout)); return; } // show menu in a list if (commandArray.length == 2 && 'list'.indexOf(commandArray[1].toLowerCase().substring(2)) == 2) { botsData.bots.tipMenu.format = "list"; // feedback to user sendTipMenuFormat(message.user, "list"); return; } // show menu in a line if (commandArray.length == 2 && 'line'.indexOf(commandArray[1].toLowerCase().substring(2)) == 2) { botsData.bots.tipMenu.format = "line"; // feedback to user sendTipMenuFormat(message.user, "line"); return; } // enable fan discount if (commandArray.length >= 3 && 'fan'.indexOf(commandArray[1].toLowerCase()) == 0 && commandArray[2] == 'on') { var discount = commandArray[3] && !isNaN(parseInt(commandArray[3])) ? (parseInt(commandArray[3]) > 99 ? 99 : parseInt(commandArray[3])) : undefined; botsData.bots.tipMenu.fanClubDiscount = discount ? discount : defaultSettings.tipMenu.fanClubDiscount; enableFanClubDiscount(); return; } // disable fan discount if (commandArray.length == 3 && 'fan'.indexOf(commandArray[1].toLowerCase()) == 0 && commandArray[2] == 'off') { disableFanClubDiscount(); return; } // change fan club percentage if (commandArray.length == 3 && 'fan'.indexOf(commandArray[1].toLowerCase()) == 0 && !isNaN(parseInt(commandArray[2]))) { var discount = commandArray[2] ? (parseInt(commandArray[2]) > 99 ? 99 : parseInt(commandArray[3])) : undefined; botsData.bots.tipMenu.fanClubDiscount = discount ? discount : defaultSettings.tipMenu.fanClubDiscount; enableFanClubDiscount(); return; } return false; } function splitBySpaces(string) { return string.trim().replace(/\s+/g, ' ').split(' '); } ////////////////////// // tip menu // ////////////////////// function sendTipMenuHelp( message ) { sendNotice(message.user, getTipMenuHelp(message) ); } function insertInTipMenu( amount, description ) { var tipMenuList = botsData.bots.tipMenu.items; var index = tipMenuList.findIndex(function(item) { return amount <= item.amount; }); if (index < 0) { tipMenuList.push({amount: amount, description: description}); return tipMenuList.length-1; } tipMenuList.splice(index, 0, {amount: amount, description: description}); return index; } function removeFromTipMenu( index ) { var tipMenuList = botsData.bots.tipMenu.items; tipMenuList.splice(index, 1); } function sendAddTipMenuResult( username, item, price, index ) { var tipMenuBot = botsData.bots.tipMenu, resultString = '"' + item + '" (' + price + ') has been added to the tip menu in position ' + index; sendBoldNotice(username, resultString, tipMenuBot.foregroundColor, tipMenuBot.backgroundColor); } function sendRemoveTipMenuResult( username, index ) { var tipMenuBot = botsData.bots.tipMenu, resultString = 'Item #' + index + ' has been removed from the tip menu'; sendBoldNotice(username, resultString, tipMenuBot.foregroundColor, tipMenuBot.backgroundColor); } function sendTipMenu(message) { var resultString = '', tipMenuBot = botsData.bots.tipMenu, unicode = tipMenuBot.unicode||'*', tipMenuList = tipMenuBot.items, happyTimeMsg = `Happy time is enabled. Tip ${tipMenuBot.happyTimeTriggerTip} tokens and every item in the tip menu will be ${tipMenuBot.happyTimeDiscount}% cheaper for ${tipMenuBot.happyTimeLength} seconds.`; if (tipMenuBot.status != Status.RUNNING) { resultString = "The fit menu is not running"; sendBoldNotice(message.user, resultString, tipMenuBot.foregroundColor, tipMenuBot.backgroundColor); return; } tipMenuList.forEach(function(item, index){ var indexPrefix = ((message.user == cb.room_slug) || message.is_mod) ? '-[ ' + index +' ]- ' :'', amount = discountPrice(item.amount), fanAmount = fanPrice(amount), amountString; if (botsData.bots.tipMenu.format == "list") { amountString = ((amount == fanAmount)? amount : (message.in_fanclub ? fanAmount : (amount + " (" + fanAmount + " fan club members)"))) + (tipMenuBot.happyTimeTriggered ? ' ON SALE!!' : ''); resultString += `${lineBreak} ${unicode} -${indexPrefix}- ${amountString} | ${item.description}`; // TODO add more unicodes here } else { amountString = ((amount == fanAmount)?amount : (message.in_fanclub ? fanAmount : amount)) + (tipMenuBot.happyTimeTriggered ? ' ON SALE!!' : ''); resultString += ` ${unicode} ${indexPrefix} ${item.description} ${repeat(unicodeChars.dot, 1)} (${amountString}) `; // TODO add more unicodes here } }); if (tipMenuBot.format == "line" && !message.in_fanclub && tipMenuBot.fanClubDiscount > 0) { resultString += lineBreak + "All these prices will have a " + tipMenuBot.fanClubDiscount + "% discount for fan club members!"; } if (resultString.length == 0) { resultString = "The fit menu is empty"; sendBoldNotice(message.user, resultString, tipMenuBot.foregroundColor, tipMenuBot.backgroundColor); return; } resultString = lineBreak + repeat('-', 5) + " MY MENU " + repeat('-', 5) + (tipMenuBot.format == "line" ? '> ' : '') + resultString; sendBoldNotice(message.user, resultString + lineBreak, tipMenuBot.foregroundColor, tipMenuBot.backgroundColor); tipMenuBot.happyTimeEnabled && sendBoldNotice(message.user, unicode + ' ' + happyTimeMsg.toUpperCase(), colors.wine, tipMenuBot.foregroundColor); } function sendTipMenuHistory( username ) { var resultString = '', tipMenuBot = botsData.bots.tipMenu, unicode = tipMenuBot.unicode, history = tipMenuBot.history.reverse(), now = new Date().getTime(); history.forEach( function( item ){ var lapse = elapsed(item.time, now), seconds = lapse.seconds > 0 ? lapse.seconds + 'seconds ' : '', minutes = lapse.minutes > 0 ? lapse.minutes + 'minutes ' : '', hours = lapse.hours > 0 ? lapse.hours + 'hours ' : '', lapseString = hours + minutes + seconds + 'ago'; resultString += ( unicode + ' ---- ' + item.description + ' : ' + item.user + ' : ' + lapseString + lineBreak); }); resultString = (resultString.length == 0 ? repeat(unicode, 5) + " Tip menu history is empty " + repeat(unicode, 5) : resultString); sendBoldNotice(username, resultString, tipMenuBot.foregroundColor, tipMenuBot.backgroundColor); } function sendTipMenuCounter( username ) { var resultString = '', tipMenuBot = botsData.bots.tipMenu, unicode = tipMenuBot.unicode, tipMenuCounter = tipMenuBot.items.sort(function(a,b) { return (parseInt(b.times) - parseInt(a.times)); }); tipMenuCounter.forEach(function(item){ resultString += item.times > 0 ? ( unicode + ' ---- ' + item.times + ' | ' + item.description + lineBreak) : ''; // TODO add more unicodes here }); resultString = (resultString.length == 0 ? repeat(unicode, 5) + " Nobody has tipped for an item in the tip menu " + repeat(unicode, 5) : resultString); sendBoldNotice(username, resultString, tipMenuBot.foregroundColor, tipMenuBot.backgroundColor); } function sendTipMenuNotice( username, description) { var unicode = botsData.bots.tipMenu.unicode, resultString = repeat('-',20) + lineBreak + `${unicode} ${username.toUpperCase()} HAS TIPPED FOR ${description.toUpperCase()}${lineBreak}` + repeat('-',20) ; sendBoldNotice(everyone, resultString, botsData.bots.tipMenu.tipForegroundColor, botsData.bots.tipMenu.tipBackgroundColor); } /////////////////////// // commands feedback // /////////////////////// function sendTipMenuBroadcastOff( user ) { var tipMenuBot = botsData.bots.tipMenu, resultString = 'The tip menu will not be shown to the users'; sendBoldNotice(user, resultString, tipMenuBot.foregroundColor, tipMenuBot.backgroundColor); } function sendTipMenuBroadcastOn( user, minutes ) { var tipMenuBot = botsData.bots.tipMenu, resultString = 'The tip menu will be shown to the users every ' + minutes + ' minutes' ; sendBoldNotice(user, resultString, tipMenuBot.foregroundColor, tipMenuBot.backgroundColor); } function sendTipMenuFormat( user, format ) { var tipMenuBot = botsData.bots.tipMenu, resultString = 'The tip menu will be shown to the users as a ' + format ; sendBoldNotice(user, resultString, tipMenuBot.foregroundColor, tipMenuBot.backgroundColor); } function broadcastTipMenu() { sendTipMenu ( everyone ); } function broadcastTipMenuTimeout() { var tipMenuBot = botsData.bots.tipMenu; broadcastTipMenu (); tipMenuBot.timeout > 0 && (tipMenuBot.timeoutId = cb.setTimeout(broadcastTipMenuTimeout, tipMenuBot.timeout * 1000)); } //-- Happy time --// function discountPrice(amount, user) { var tipMenuBot = botsData.bots.tipMenu, isHappyTime = tipMenuBot.happyTimeTriggered, isFan = user ? user.in_fanclub : false; if (isHappyTime && isFan){ return fanPrice(happyTimePrice(amount)); } if (isHappyTime){ return happyTimePrice(amount); } if (isFan){ return fanPrice(amount); } return amount; } function sendHappyTimeTriggeredNotice() { var tipMenuBot = botsData.bots.tipMenu, timeLeft = Math.floor((tipMenuBot.happyTimeEnd - Date.now()) / 1000), msg = `Happy time is on for the next ${timeLeft} seconds!. Everything in the tip menu has a discount of ${tipMenuBot.happyTimeDiscount}% !!!`; sendBoldNotice('', msg, colors.white, tipMenuBot.foregroundColor); } function sendHappyTimeInfoNotice() { var tipMenuBot = botsData.bots.tipMenu, timeLeft = Math.floor((tipMenuBot.happyTimeEnd - Date.now()) / 1000), msg = `Happy time is on for the next ${timeLeft} seconds!. Everything in the tip menu has a discount of ${tipMenuBot.happyTimeDiscount}% !!!`; sendBoldNotice('', msg, colors.white, tipMenuBot.foregroundColor); tipMenuBot.happyTimeElapsedTimeoutId = cb.cancelTimeout(tipMenuBot.happyTimeElapsedTimeoutId); if (timeLeft > 30) { tipMenuBot.happyTimeElapsedTimeoutId = cb.setTimeout(sendHappyTimeInfoNotice, 30 * 1000); } } function enableHappyTime() { var tipMenuBot = botsData.bots.tipMenu, message = 'Happy time is enabled' + lineBreak + 'Tip ' + tipMenuBot.happyTimeTriggerTip + ' tokens to start it up for ' + tipMenuBot.happyTimeLength + ' seconds'; tipMenuBot.happyTimeTimeoutId = undefined; tipMenuBot.happyTimeTimeoutId = undefined; tipMenuBot.happyTimeEnd = 0; tipMenuBot.happyTimeTriggered = false; tipMenuBot.happyTimeEnabled = true; sendBoldNotice('', message , colors.white, tipMenuBot.foregroundColor); } function disableHappyTime() { var tipMenuBot = botsData.bots.tipMenu; tipMenuBot.happyTimeTimeoutId && (tipMenuBot.happyTimeTimeoutId = cb.cancelTimeout(tipMenuBot.happyTimeTimeoutId)); tipMenuBot.happyTimeElapsedTimeoutId && (tipMenuBot.happyTimeElapsedTimeoutId = cb.cancelTimeout(tipMenuBot.happyTimeElapsedTimeoutId)); tipMenuBot.happyTimeTriggered = false; tipMenuBot.happyTimeEnabled = false; sendBoldNotice('', 'Happy time has been turned off', tipMenuBot.foregroundColor, tipMenuBot.backgroundColor); } function enableFanClubDiscount() { var tipMenuBot = botsData.bots.tipMenu; tipMenuBot.fanClubDiscount = (tipMenuBot.fanClubDiscount > 0 && tipMenuBot.fanClubDiscount < 100)? tipMenuBot.fanClubDiscount : defaultSettings.fanClubDiscount ; sendBoldNotice('', 'Fan club discount is set to ' + tipMenuBot.fanClubDiscount + '%', tipMenuBot.foregroundColor, tipMenuBot.backgroundColor); } function disableFanClubDiscount() { var tipMenuBot = botsData.bots.tipMenu; tipMenuBot.fanClubDiscount = 0 ; sendBoldNotice('', 'Fan club discount has been turned off', tipMenuBot.foregroundColor, tipMenuBot.backgroundColor); } function triggerHappyTime() { var tipMenuBot = botsData.bots.tipMenu, now = Date.now(); tipMenuBot.happyTimeEnd = tipMenuBot.happyTimeEnd - now < 0 ? now + tipMenuBot.happyTimeLength * 1000 : tipMenuBot.happyTimeEnd + tipMenuBot.happyTimeLength * 1000; tipMenuBot.happyTimeTriggered = true; tipMenuBot.happyTimeTimeoutId && (tipMenuBot.happyTimeTimeoutId = cb.cancelTimeout(tipMenuBot.happyTimeTimeoutId)); tipMenuBot.happyTimeTimeoutId = cb.setTimeout(finishHappyTime, tipMenuBot.happyTimeEnd - now); sendHappyTimeTriggeredNotice(); if (tipMenuBot.happyTimeLength > 30) { tipMenuBot.happyTimeElapsedTimeoutId && (tipMenuBot.happyTimeElapsedTimeoutId = cb.cancelTimeout(tipMenuBot.happyTimeElapsedTimeoutId)); tipMenuBot.happyTimeElapsedTimeoutId = cb.setTimeout(sendHappyTimeInfoNotice, 30 * 1000); } } function finishHappyTime() { var tipMenuBot = botsData.bots.tipMenu; tipMenuBot.happyTimeTimeoutId && (tipMenuBot.happyTimeTimeoutId = cb.cancelTimeout(tipMenuBot.happyTimeTimeoutId)); tipMenuBot.happyTimeElapsedTimeoutId && (tipMenuBot.happyTimeElapsedTimeoutId = cb.cancelTimeout(tipMenuBot.happyTimeElapsedTimeoutId)); tipMenuBot.happyTimeTriggered = false; sendBoldNotice('', `Happy time is over! tip ${tipMenuBot.happyTimeTriggerTip} tokens to start for another ${tipMenuBot.happyTimeLength} seconds!!!`, tipMenuBot.foregroundColor, tipMenuBot.backgroundColor); } //////////////// // validators // //////////////// function isValidColor( color ) { var hexRegEx = /^#(([0-9a-fA-F]{3})|([0-9a-fA-F]{6}))$/, rgbaRegEx = /^rgba?\(((25[0-5]|2[0-4]\d|1\d{1,2}|\d\d?)\s*,\s*){2}(25[0-5]|2[0-4]\d|1\d{1,2}|\d\d?)\s*,?\s*([01]\.?\d*?)?\)$/; color = color.trim(); return !!(color.match(hexRegEx) || color.match(rgbaRegEx)); } function isValidEmote( emote ) { var emoteRegEx = /^:[a-zA-Z0-9\-_]+$/; emote = emote.trim(); return !!(emote.match(emoteRegEx)); } ////////////// // settings // ////////////// function sendWelcomeMessage(user) { sendBoldNotice(user.user, getWelcomeMessage(user), botsData.foregroundColor, botsData.backgroundColor); } ////////// // Init // ////////// function init() { botsData.foregroundColor = (cb.settings.foregroundColor && isValidColor(cb.settings.foreground)) ? cb.settings.foregroundColor : defaultSettings.foregroundColor; botsData.backgroundColor = (cb.settings.backgroundColor && isValidColor(cb.settings.backgroundColor)) ? cb.settings.backgroundColor : defaultSettings.backgroundColor; botsData.start = new Date().getTime(); initBots(); } function initBots() { initTipMenuBot(); } function initTipMenuBot() { var tipMenuBot = botsData.bots.tipMenu, defaults = defaultSettings.tipMenu; tipMenuBot.foregroundColor = defaults.foregroundColor || ''; tipMenuBot.backgroundColor = defaults.backgroundColor || ''; tipMenuBot.tipForegroundColor = defaults.tipForegroundColor || ''; tipMenuBot.tipbackgroundColor = defaults.tipBackgroundColor || ''; tipMenuBot.unicode = defaults.unicode; tipMenuBot.format = defaults.format; if (cb.settings.tipMenuEnabled == 'yes') { tipMenuBot.enabled = true; tipMenuBot.status = Status.RUNNING; } tipMenuBot.happyTimeEnabled = cb.settings.tipMenuBotHappyTimeEnabled == 'yes'? true : false; tipMenuBot.happyTimeTriggerTip = parseInt(cb.settings.happyTimeTriggerTip); tipMenuBot.happyTimeLength = parseInt(cb.settings.happyTimeLength); tipMenuBot.happyTimeDiscount = parseInt(cb.settings.happyTimeDiscount); tipMenuBot.happyTimeTriggered = false; tipMenuBot.fanClubDiscount = (cb.settings.fanClubDiscount && !isNaN(parseInt(cb.settings.fanClubDiscount))) ? parseInt(cb.settings.fanClubDiscount) : defaults.fanClubDiscount; for ( var i = 0; i < MAX_TIP_MENU_ITEMS; i++ ) { var tipDescription = cb.settings["tipMenuItemDescription" + i] ? cb.settings["tipMenuItemDescription" + i].trim() : '', tipAmount = cb.settings["tipMenuItemAmount" + i] ? parseInt(cb.settings["tipMenuItemAmount" + i]) : ''; if ( tipDescription.length > 0 && !isNaN(tipAmount) && tipAmount > 0 ) { tipMenuBot.items.push({amount: tipAmount , description: tipDescription, times: 0}); } } tipMenuBot.items = tipMenuBot.items.sort(function(a,b) { return (parseInt(a.amount) - parseInt(b.amount)); }); // set timeout and launch var timeout = parseInt(defaults.timeout); tipMenuBot.timeout = (isNaN(timeout) || timeout <= 0 )? 0 : timeout; broadcastTipMenuTimeout(); } init() ;
© Copyright Chaturbate 2011- 2025. All Rights Reserved.