Bots Home
|
Create an App
wetbot2.1
Author:
onesinmiedo1
Description
Source Code
Launch Bot
Current Users
Created by:
Onesinmiedo1
const MAX_GROUPS = 3; const MAX_TIP_MENU_ITEMS = 23; const MAX_LOTTERY_PRIZES = 5; var lineBreak = '\n'; var everyone = ''; var tippersList = {}; // colors var groupColors = { broadcaster : 'orange', mods : 'red', fans : 'green', tip1000 : 'darkpurple', tip250 : 'lightpurple', tip50 : 'darkblue', tokens : 'lightblue', notokens : 'gray' }; var colors = { orange : '#dc5500', red : '#ff0000', green : '#009900', darkpurple : '#5f497a' , lightpurple : '#be6aff', darkblue : '#1f497d', lightblue : '#6699aa', gray : '494949', }; // unicodes var unicodeChars = { space : '\u0020', dot : '\u22c5', // dot heart : '\u2665', // heart star : '\u2605', // filled star whiteStar : '\u2606', // white star square : '\u25fc', triangleRight : '\u25b6', dashChar : '\u2500', whiteHeart : '\u2661', arrow : '\u2192', triangleDown : '\u25bc' }; var botsUnicodes = { tippersBot : unicodeChars.square, fansBot : unicodeChars.star, clubsBot : unicodeChars.whiteHeart, tipMenuBot : unicodeChars.heart, lotteryBot : unicodeChars.whiteStar }; var wetBotData = { bots : { // default colors colors : { foreground : '', background : '', }, // tippers bot data tippersBot : { name : 'Tippers bot', bombTip : 0, minBombTip : 0, bombTipper : '', kingTipperSum : 0, kingTipper : '', tippers : {}, tipCount : 0, tipSum : 0, emotes : { kingTipper : '', bombTipper : '', }, unicode : '', colors : { kingTipper : { foreground : '', background : '', }, bombTipper : { foreground : '', background : '', }, foreground : '', background : '', } }, // fans bot data fansBot : { name : 'Fans bot', tippers : {}, tipCount : 0, tipSum : 0, emotes : { fanClub : '', }, unicode : '', colors : { foreground : '', background : '', }, }, // clubs bot data clubsBot : { name : 'Clubs bot', clubs : {}, timeout : '', timeoutId : '', colors : { foreground : '', background : '', }, unicode : '', }, // tip menu bot data tipMenuBot : { name : 'Tip menu bot', enabled : true, history : [], items : [], timeout : '', timeoutId : '', unicode : '', happyTimeEnabled : false, happyTimeEnd : 0, happyTimeTimeoutId : undefined, happyTimeElapsedTimeoutId : undefined, happyTimeTriggered : false, happyTimeTip : 0, happyTimeDuration : 0, happyTimeSale : 1, colors : { foreground : '', background : '', } }, // lottery bot data lotteryBot : { name : 'Lottery bot', enabled : true, min : 0, max : 0, prizes : {}, guesses : [], timeout : '', timeoutId : '', unicode : '', colors : { foreground : '', background : '', } } }, colors : { foreground : '', background : '' }, start : 0, commandsConfig : { "/wet": { cmd: "help" }, "/tipper": { cmd: "tippers" }, "/clubb": { cmd: "clubs all" }, "/club": { cmd: "clubs" }, "/fan": { cmd: "fans" }, "/tmb": { cmd: "tipmenu all" }, "/tm": { cmd: "tipmenu" }, "/tipmenu":{ cmd: "tipmenu" }, "/lotb": { cmd: "lottery all" }, "/lot": { cmd: "lottery" } }, helpMessages : { tippers : [ ['bmr', repeat(botsUnicodes.tippersBot,5) + ' COMMANDS FOR THE TIP BOT ' + repeat(botsUnicodes.tippersBot,5) ], ['bmr', botsUnicodes.tippersBot + ' /tipper help : shows this help text' ], ['bmr', botsUnicodes.tippersBot + ' /tipper : shows the ordered list of tippers' ], ['bmr', botsUnicodes.tippersBot + ' /tipper bomb : shows the tipper who gave the higgest tip' ], // ['bmr', botsUnicodes.tippersBot + ' /tipper prefix off : stop showing user tip counter' ], // ['bmr', botsUnicodes.tippersBot + ' /tipper prefix on : start showing user tip counter' ], ['bmr', botsUnicodes.tippersBot + ' /tipper king : shows the tipper who gave most tokens since the bot started' ] ], clubs : [ ['bmr', repeat(botsUnicodes.clubsBot,5) + ' COMMANDS FOR THE CLUBS BOT' + repeat(botsUnicodes.clubsBot,5) ], ['bmr', botsUnicodes.clubsBot + ' "/club help" : shows this help text'], ['bm', botsUnicodes.clubsBot + ' "/club " : shows the list of clubs and their members'], ['bm', botsUnicodes.clubsBot + ' "/club info" : shows the list of clubs available for joining and their joining fee'], ['r', botsUnicodes.clubsBot + ' "/club" : shows the list of clubs available for joining and their joining fee'], // ['bm', botsUnicodes.clubsBot + ' /club list <club>: shows the list of members in <club>'], ['bm', botsUnicodes.clubsBot + ' "/club user <username>" : shows the list of clubs that <username> is a member of'], ['bm', botsUnicodes.clubsBot + ' "/clubb" : shows the clubs info to everyone'], ['bm', botsUnicodes.clubsBot + ' "/clubb off" : stops the clubs info periodic notice'], ['bm', botsUnicodes.clubsBot + ' "/clubb on <minutes>" : shows the clubs info to everyone every <minutes> minutes'] ], fans : [ ['bm', repeat(botsUnicodes.fansBot,5) + ' COMMANDS FOR THE FANS BOT' + repeat(botsUnicodes.fansBot,5) ], ['bm', botsUnicodes.fansBot + ' "/fans help" : shows this help text'], ['bm', botsUnicodes.fansBot + ' "/fans" : shows the list of fans and their tips'] ], 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 count" : 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 + ' "/tm happy on" : enable happy time feature'], ['bm', botsUnicodes.tipMenuBot + ' "/tm happy off" : disable happy time feature'], // broadcast messages ['bm', botsUnicodes.tipMenuBot + ' "/tmb" : shows the tip menu to everyone'], ['bm', botsUnicodes.tipMenuBot + ' "/tmb off" : stops the tip menu periodic notice'], ['bm', botsUnicodes.tipMenuBot + ' "/tmb on <minutes>" : shows the tip menu to everyone every <minutes> minutes'] ], lottery : [ ['bmr', repeat(botsUnicodes.lotteryBot,5) + ' COMMANDS FOR THE LOTTERY BOT' + repeat(botsUnicodes.lotteryBot,5) ], ['bmr', botsUnicodes.lotteryBot + ' "/lot help" : shows this help text'], ['bmr', botsUnicodes.lotteryBot + ' "/lot" : shows the lottery info'], ['b' , botsUnicodes.lotteryBot + ' "/lot prizes" : shows where the lottery prizes are'], ['bmr', botsUnicodes.lotteryBot + ' "/lot numbers": shows the lottery numbers'], ['bm' , botsUnicodes.lotteryBot + ' "/lot restart": restarts the lottery'], ['bm', botsUnicodes.lotteryBot + ' "/lot off" : stops the lottery bot'], ['bm', botsUnicodes.lotteryBot + ' "/lot on" : starts the lottery bot if it is not running'], // broadcast messages ['bm' , botsUnicodes.lotteryBot + ' "/lotb" : shows the lottery info (available prizes) to everyone'], ['bm' , botsUnicodes.lotteryBot + ' "/lotb off" : stops the lottery periodic notice'], ['bm' , botsUnicodes.lotteryBot + ' "/lotb on <minutes>": shows the lottery to everyone every <minutes> minutes'] ] }, welcomeMessages : [ ['', ' Welcome to my room $user ! :mclap'], ['', ' > type /lot for the lottery info'], ['', ' > type /tm or /tipmenu for my tip menu'], ['', ' > type /club for clubs info'], ['', ' > type /tipper for the tippers list'], ['m', ' > type /wet for a full list of available commands'], ], }; 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}; } cb["settings_choices"] = [ { name : "fanClubEmote", label : "1) FAN CLUB BOT SETTINGS ......................................... Fan club member's emote (optional) ", type : "str", minLength : 3, maxLength : 255, default : ":wbfan", required : false }, { name : "fanClubMessageGreen", label : "Show fan club member's message in green ", type : "choice", choice1 : "yes", choice2 : "no", default : "no" }, { name : "fansBotMessageForeground", label : "Fan club bot foreground (optional) ", type : "str", minLength : 4, maxLength : 30, default : "#0c0", required : false }, { name : "fansBotMessageBackground", label : "Fan club bot background (optional) ", type : "str", minLength : 4, maxLength : 30, default : "", required : false }, { name : "kingTipperEmote", label : "2) TIP BOT SETTINGS .................................. King tipper emote (optional) ", type : "str", minLength : 3, maxLength : 255, default : ":wbking", required : false }, { name : "bombTipperEmote", label : "Bomb tipper emote (optional) ", type : "str", minLength : 3, maxLength : 255, default : ":wbbomb", required : false }, { name : "bombTipperMinValue", label : "minimum value for a tip to be considered a bomb (optional) ", type : "str", minLength : 0, maxLength : 25, default : "1000", required : false }, { name : "tippersBotMessageForeground", label : "Tip bot text color (optional) ", type : "str", minLength : 4, maxLength : 30, default : "#00c", required : false }, { name : "tippersBotMessageBackground", label : "Tip bot background color (optional) ", type : "str", minLength : 4, maxLength : 30, default : "", required : false }, { name : "tippersBotPrependTipCount", label : "Prepend tip count to user messages ", type : "choice", choice1 : "yes", choice2 : "no", default : "no" }, { name : "clubsBotMessageForeground", label : "3) CLUBS BOT SETTINGS (Only clubs with a name and a fee will be considered) ............. Clubs bot text color (optional) ", type : "str", minLength : 4, maxLength : 30, default : "#f60", required : false }, { name : "clubsBotMessageBackground", label : "Clubs bot background color (optional) ", type : "str", minLength : 4, maxLength : 30, default : "", required : false }, { name : "clubsBotNoticeTimeout", label : "Minutes between notifications from 0 (no notifications) to 10 ", type : "int", minValue : 0, maxValue : 10, default : 5, required : false }, { name : "clubsBotAutoStart", label : "Start club notices automaticaly ", type : "choice", choice1 : "yes", choice2 : "no", default : "yes" } ]; for(var i = 0; i < MAX_GROUPS; i++) { cb.settings_choices.push({ name : "clubName" + i, label : "----------------- club " + (i+1) + " name --------------> ", type : "str", minLength : 4, maxLength : 30, default : "", required : false }); cb.settings_choices.push({ name : "clubMemebers" + i, label : "club members separated by commas (optional) " , type : "str", minLength : 4, maxLength : 255, default : "", required : false }); cb.settings_choices.push({ name : "clubFee" + i, label : "club fee ", type : "str", minLength : 2, maxLength : 250, default : "", required : false }); // cb.settings_choices.push({ // name : "clubForeground" + i, // label : "club text color:" , // type : "str", // minLength : 4, // maxLength : 30, // default : "", // required: false // }); // cb.settings_choices.push({ // name : "clubBackground" + i, // label : "club background color:", // type : "str", // minLength : 4, // maxLength : 30, // default : "", // required: false // }); cb.settings_choices.push({ name : "clubEmote" + i, label : "club emote (optional) ", type : "str", minLength : 3, maxLength : 255, default : "", required : false }); } cb.settings_choices.push({ name : "tipMenuBotEnabled", label : "4) TIP MENU BOT SETTINGS (Only items with a description and price will be considered) ............................................. Tip menu enabled ", type : "choice", choice1 : 'yes', choice2 : 'no', default : "yes", required : true }, { name : "tipMenuBotMessageForeground", label : "Tip menu bot text color (optional) ", type : "str", minLength : 4, maxLength : 30, default : "#f6c", required : false }, { name : "tipMenuBotMessageBackground", label : "Tip menu bot background color (optional) ", type : "str", minLength : 4, maxLength : 30, default : "#fcf", required : false }, { name : "tipMenuTimeout", label : "Minutes between notices from 0 (no notifications) to 10 ", type : "int", minValue : 0, maxValue : 10, default : 10, required : false }, { name : "tipMenuBotAutoStart", label : "Start tip menu notices automaticaly ", type : "choice", choice1 : "yes", choice2 : "no", default : "yes" }, { name : "tipMenuBotHappyTimeEnabled", label : "Enable happy time feature on startup ", type : "choice", choice1 : "yes", choice2 : "no", default : "no" }, { name : "tipMenuBotHappyTimeDuration", label : "Happy time duration in seconds (30 - 300)", type : "int", minValue : 30, maxValue : 300, default : 60, required : false }, { name : "tipMenuBotHappyTimeTriggerTip", label : "Tip amount that triggers the happy time ", type :"int", minValue : 0, maxValue : 10000, default : 1000, required : false }, { name : "tipMenuBotHappyTimeSale", label : "Sale % to apply to price (0 - 100)", type :"int", minValue : 0, maxValue : 100, default : 50, 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 : "menu item " + (i+1) + " price ", type : "str", minLength : 1, maxLength : 255, default : "", required : false }); } cb.settings_choices.push({ name : "lotteryBotEnabled", label : "5) LOTTERY BOT SETTINGS (Only items with a description and amount will be considered) ............................................. Lottery enabled ", type : "choice", choice1 : 'yes', choice2 : 'no', default : "yes", required : true }, { name : "lotteryBotMessageForeground", label : "Lottery bot text color (optional) ", type : "str", minLength : 4, maxLength : 30, default : "#fff", required : false }, { name : "lotteryBotMessageBackground", label : "Lottery bot background color (optional) ", type : "str", minLength : 4, maxLength : 30, default : "#666", required : false }, { name : "lotteryBottom", label : "Lottery bottom number ", type : "str", minLength : 1, maxLength : 3, default : '1', required : false }, { name : "lotteryTop", label : "Lottery top number ", type : "str", minLength : 1, maxLength : 3, default : '100', required : false }, { name : "lotteryTimeout", label : "Minutes between notices from 0 (no notifications) to 10 ", type : "int", minValue : 0, maxValue : 10, default : 9, required : false }, { name : "lotteryBotAutoStart", label : "Start lottery notices automaticaly ", type : "choice", choice1 : "yes", choice2 : "no", default : "yes" }); for(var i = 0; i < MAX_LOTTERY_PRIZES; i++) { cb.settings_choices.push({ name : "lotteryPrizeDescription" + i, label : "--------------- lottery prize " + (i+1) + " description ----------------> ", type : "str", minLength : 3, maxLength : 255, default : "", required : false }, { name : "lotteryPrizeAmount" + i, label : "amount of prizes " + (i+1) + " ", type : "str", minLength : 1, maxLength : 255, default : "", required : false }); } ////////////////////////////////////// // welcome and help message methods // ////////////////////////////////////// function getWelcomeMessage(user) { var resultString = lineBreak; wetBotData.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 getTippersHelp(message) + getClubsHelp(message) + getFansHelp(message) + getTipMenuHelp(message) + getLotteryHelp(message); } function getTippersHelp(message) { var resultString = lineBreak, isOwner = (message.user == cb.room_slug), isMod = (message.is_mod); wetBotData.helpMessages.tippers.forEach(function(item){ if(item[0].length == 0 || item[0].indexOf("m") >= 1 && isMod || item[0].indexOf("b") >= 0 && isOwner || item[0].indexOf("r") >= 0 && (!isOwner && !isMod)) resultString += item[1] + lineBreak ; }); return resultString.trim().length == 0? "" : resultString; } function getClubsHelp(message) { var resultString = lineBreak, isOwner = (message.user == cb.room_slug), isMod = (message.is_mod); wetBotData.helpMessages.clubs.forEach(function(item){ if(item[0].length == 0 || item[0].indexOf("m") >= 1 && isMod || item[0].indexOf("b") >= 0 && isOwner || item[0].indexOf("r") >= 0 && (!isOwner && !isMod)) resultString += item[1] + lineBreak ; }); return resultString.trim().length == 0? "" : resultString; } function getFansHelp(message) { var resultString = lineBreak, isOwner = (message.user == cb.room_slug), isMod = (message.is_mod); wetBotData.helpMessages.fans.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; } function getTipMenuHelp(message) { var resultString = lineBreak, isOwner = (message.user == cb.room_slug), isMod = (message.is_mod); wetBotData.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; } function getLotteryHelp(message) { var resultString = lineBreak, isOwner = (message.user == cb.room_slug), isMod = (message.is_mod); wetBotData.helpMessages.lottery.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){ var fgColor = wetBotData.colors.foreground; // clubs = getClubsOf(user.user); (user.user == 'wetuser') && (user.in_fanclub = true);// TODO remove sendNotice(user.user, getWelcomeMessage(user), fgColor); user.in_fanclub && sendFanMemberNotice(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 ){ (tipData.from_user == 'wetuser') && (tipData.from_user_in_fanclub = true);// TODO remove 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 prefix = "", tippersBot = wetBotData.bots.tippersBot, prependTipCount = tippersBot.prependTipCount, isFan = ((message.user == 'wetuser') && (message.in_fanclub = true), message.in_fanclub),// TODO remove 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; } // it's not a command, so show it prefix += isFan ? wetBotData.bots.fansBot.emotes.fanClub + " " : ""; // add fan emote prefix += prependTipCount ? message.user in tippersBot.tippers? '[' + tippersBot.tippers[message.user].sum + '] ':'':''; // add tip counter prefix += isKingTipper(message.user) ? tippersBot.emotes.kingTipper + " " : ""; // add king tip emote prefix += isBombTipper(message.user) ? tippersBot.emotes.bombTipper + " " : ""; // add rich tipper emote prefix += getClubEmotesList(message.user).join(" ") + " "; message.m = prefix + message.m; // if it's a fan club member, color it var fanForeground = wetBotData.bots.fansBot.colors.foreground, fanBackground = wetBotData.bots.fansBot.colors.background; isFan && (message.c = fanForeground, message.background = fanBackground ); return message; }); ///////////////// // Send notice // ///////////////// function sendNotice(user, message, foreground, background, group) { var fg = foreground || wetBotData.colors.foreground; var bg = background || wetBotData.colors.background; var grp = group || ""; cb.sendNotice(message, user, bg, fg, 'normal', grp); } function sendBoldNotice(user, message, foreground, background, group) { var fg = foreground || wetBotData.colors.foreground; var bg = background || wetBotData.colors.background; var grp = group || ""; cb.sendNotice(message, user, bg, fg, 'bold', grp); } function sendErrorNotice(username, message, commandString) { sendBoldNotice(username, lineBreak + ' Error command : /' + commandString + lineBreak + unicodeChars.square + message + lineBreak); } /////////// // Utils // /////////// function padRight(char, value) { return value + char; } function padLeft(char, value) { return char + value; } function repeat(char, length) { var result = ""; while(length--) result += char; return result; } function bracket(string, unicode, length=3, verticalPadding = 1) { var lines = string.trim().split(lineBreak), resultString = ''; lines.forEach( function( line, index ){ lines[index] = unicode + ' ' + line; }); resultString += (unicode != '' && length > 0 ? repeat(unicode, length) + lineBreak :''); resultString += (unicode != '' ? repeat(unicode + lineBreak, verticalPadding): repeat(lineBreak, verticalPadding)) + lines.join('\n') + lineBreak + (unicode != '' ? repeat(unicode + lineBreak, verticalPadding): repeat(lineBreak, verticalPadding)); resultString += (unicode != '' && length > 0 ? repeat(unicode, length) : ''); return resultString; } function stopBot(username, botId ) { var bot = wetBotData.bots[botId], resultString = `${bot.name} is no longer enabled`; if (bot.enabled) { bot.enabled = false; bot.timeoutId = cb.cancelTimeout(bot.timeoutId); if (botId == 'tipMenuBot') { bot.happyTimeTimeoutId && (bot.happyTimeTimeoutId = cb.cancelTimeout(bot.happyTimeTimeoutId)); bot.happyTimeElapsedTimeoutId && (bot.happyTimeElapsedTimeoutId = cb.cancelTimeout(bot.happyTimeElapsedTimeoutId)); bot.happyTimeTriggered = false; } // if (botId == 'lotteryBot') { // } sendBoldNotice('', resultString, bot.colors.foreground, bot.colors.background); return; } sendBoldNotice( username, `${bot.name} is already stopped`, bot.colors.foreground, bot.colors.background); } function runBot(username, botId ) { var bot = wetBotData.bots[botId], resultString = `${bot.name} is enabled`; if (bot) { bot['enabled'] = true; if (botId == 'tipMenuBot') { broadcastTipMenuTimeout(); } sendBoldNotice('', resultString, bot.colors.foreground, bot.colors.background); return; } sendBoldNotice( username, `${bot.name} is already running`, bot.colors.foreground, bot.colors.background); } ///////// // tip // ///////// function updateTippersList(user, amount) { var tippersBot = wetBotData.bots.tippersBot, currentKingTipper = tippersBot.kingTipper, currentBombTipper = tippersBot.bombTipper; if ( user.user in tippersBot.tippers ) { tippersBot.tippers[user.user].sum += amount; } else { tippersBot.tippers[user.user] = { sum : amount, data: user }; } // update bomb tip data if (amount >= tippersBot.minBombTip && amount > tippersBot.bombTip ) { tippersBot.bombTip = amount; tippersBot.bombTipper = user.user; } // update king tipper data if (tippersBot.tippers[user.user].sum > tippersBot.kingTipperSum) { tippersBot.kingTipperSum = tippersBot.tippers[user.user].sum; tippersBot.kingTipper = user.user; } var message = []; // if there's a new king, compose message if ( tippersBot.kingTipper != currentKingTipper) { message.push(tippersBot.emotes.kingTipper + " " + user.user + " is our new KING. All glory to " + user.user + "! " + tippersBot.emotes.kingTipper); } // if there's a new bomb, compose message if ( tippersBot.bombTipper != currentBombTipper) { message.push(tippersBot.emotes.bombTipper + " " + user.user + " is our new BOMB tipper!!. Thank you, " + user.user + "! " + tippersBot.emotes.bombTipper); } // if there's something to be shown, show it message.length && sendBoldNotice(everyone, message.join(lineBreak), tippersBot.colors.foreground, tippersBot.colors.background); } function updateFansList(user, amount) { var fansBot = wetBotData.bots.fansBot; if (user.in_fanclub){ if ( user.user in fansBot.tippers ) { fansBot.tippers[user.user].sum += amount; } else { fansBot.tippers[user.user] = { sum : amount, data: user }; } } } function updateClubsList ( user, amount ) { var clubsAvailableMap = wetBotData.bots.clubsBot.clubs; for ( var club in clubsAvailableMap ) { if ( clubsAvailableMap[club].fee == amount && !clubsAvailableMap[club].members.includes(user.user) ) { clubsAvailableMap[club].members.push(user.user); sendNewMemberNotice( user.user, club); } } } function checkTipMenu(user, amount) { var tipMenuBot = wetBotData.bots.tipMenuBot, happyTimeTriggered = tipMenuBot.happyTimeTriggered, tipMenuList = tipMenuBot.items; tipMenuBot.enabled && tipMenuList.forEach(function(item, index) { if ( (happyTimeTriggered && happyTimePrice(item.amount, tipMenuBot.happyTimeSale) == amount) || item.amount == 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 checkLotteryPrize(user, amount) { var lotteryBot = wetBotData.bots.lotteryBot, lotteryPrizesMap = lotteryBot.prizes; if (lotteryBot.enabled && amount <= lotteryBot.max && amount >= lotteryBot.min && objectSize(lotteryPrizesMap) > 0) { if ( amount in lotteryPrizesMap) { sendLotteryResultNotice(user.user, amount, lotteryPrizesMap[amount]); return; } sendLotteryResultNotice(user.user, amount); } } function checkHappyTime(amount) { var tipMenuBot = wetBotData.bots.tipMenuBot; if (tipMenuBot.happyTimeEnabled && amount == tipMenuBot.happyTimeTip) { 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, 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 = wetBotData.bots.tippersBot.kingTipper, // currentBombTipper = wetBotData.bots.tippersBot.bombTipper, // message = []; updateTippersList(user, amount); updateFansList(user, amount); updateClubsList(user, amount); checkHappyTime(amount); checkTipMenu(user, amount); checkLotteryPrize(user, amount); // update global tip counter wetBotData.bots.tippersBot.tipSum += amount; wetBotData.bots.tippersBot.tipCount += 1; } //////////////////////// // Commands procesing // //////////////////////// function stripCommandFromMessage(originalMessage) { // cycle through the commands list for (var command in wetBotData.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], wetBotData.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 == 'help') { return processHelpCommand(message, commandArray, commandString); } if ( command == 'tippers') { return processTippersCommand(message, commandArray, commandString); } if ( command == 'fans') { return processFansCommand(message, commandArray, commandString); } if ( command == 'clubs') { return processClubsCommand(message, commandArray, commandString); } if ( command == 'tipmenu') { return processTipMenuCommand(message, commandArray, commandString); } if ( command == 'lottery') { return processLotteryCommand(message, commandArray, commandString); } return void 0; } function processHelpCommand(message, commandArray) { // if (message.user !== cb.room_slug && !message.is_mod) // return false; if (commandArray.length == 1) { sendNotice(message.user, getFullHelp(message) ); return; } } function processTippersCommand(message, commandArray, commandString) { // if (message.user !== cb.room_slug && !message.is_mod) // return false; if ( commandArray.length == 1 ) { sendTippersList(message); return; } if (commandArray.length == 2 && commandArray[1] == "help" ) { sendTippersHelp(message); return; } if ( commandArray.length == 2 && commandArray[1] == "king" ) { sendKing(message); return; } if ( commandArray.length == 2 && commandArray[1] == "bomb" ) { sendBomb(message); return; } return "ERROR: /" + commandString + " is not a valid command"; } function processFansCommand(message, commandArray) { if (message.user !== cb.room_slug && !message.is_mod) return false if (commandArray.length == 2 && commandArray[1] == "help" ) { sendFansHelp(message); return; } if ( commandArray.length == 1 ) { sendFansList(message); return; } } function processClubsCommand(message, commandArray) { if (message.user !== cb.room_slug && !message.is_mod) { if (commandArray.length == 1) { sendClubsInfo(message.user); return; } return false; } if (commandArray.length == 1) { sendClubsList(message, null, null); return; } if ( commandArray.length == 2 && commandArray[1] == "help" ) { sendClubsHelp(message); return; } if ( commandArray.length == 2 && commandArray[1] == "info" ) { sendClubsInfo(message.user); return; } // if ( commandArray.length == 3 && commandArray[1] == "list" ) { // var membersList = getMembersOf(commandArray[2]); // if (membersList.length) // sendMembersList(message, membersList, commandArray[2]); // else { // var resultString = lineBreak + "THERE'S NO MEMBER IN CLUB " + commandArray[2].toUpperCase() + lineBreak; // sendBoldNotice(message.user, resultString, wetBotData.bots.clubsBot.colors.foreground, wetBotData.bots.clubsBot.colors.background); // } // return; // } if ( commandArray.length == 3 && commandArray[1] == "user" ) { var clubsList = getClubsOf(commandArray[2]); if (clubsList.length) sendClubsList(message, clubsList, commandArray[2]); else { var resultString = lineBreak + commandArray[2].toUpperCase() +" IS NOT A MEMBER OF ANY CLUB" + lineBreak; sendBoldNotice(message.user, resultString, wetBotData.bots.clubsBot.colors.foreground, wetBotData.bots.clubsBot.colors.background); } return; } if (commandArray.length == 2 && commandArray[1] == 'all') { broadcastClubsNotice(); return; } if (commandArray.length == 3 && commandArray[2] == 'off') { wetBotData.bots.clubsBot.timeoutId = cb.cancelTimeout(wetBotData.bots.clubsBot.timeoutId); sendClubInfoBroadcastOff(message.user); return; } if (commandArray.length == 4 && commandArray[2] == 'on' && !isNaN(parseInt(commandArray[3])) && parseInt(commandArray[3]) > 0) { wetBotData.bots.clubsBot.timeoutId = cb.cancelTimeout(wetBotData.bots.clubsBot.timeoutId); wetBotData.bots.clubsBot.timeout = parseInt(commandArray[3]); cb.setTimeout(broadcastClubsBotNoticeTimeout, 2000); sendClubInfoBroadcastOn(message.user, parseInt(wetBotData.bots.clubsBot.timeout)); return; } else return false; } function processTipMenuCommand(message, commandArray) { if (commandArray.length == 2 && commandArray[1] == 'help') { sendTipMenuHelp(message); return; } if (commandArray.length == 1) { sendTipMenu(message.user, message.is_mod); return; } if (message.user !== cb.room_slug && !message.is_mod) { return false; } 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; } if (commandArray.length == 3 && commandArray[1] == 'rm' && !isNaN(parseInt(commandArray[2]))) { removeFromTipMenu(parseInt(commandArray[2])); sendRemoveTipMenuResult(message.user, commandArray[2]); return; } if (commandArray.length == 2 && commandArray[1] == 'history') { sendTipMenuHistory(); return; } if (commandArray.length == 2 && commandArray[1] == 'counter') { sendTipMenuCounter(); return; } if (commandArray.length == 2 && commandArray[1] == 'off') { stopBot(message.user, 'tipMenuBot'); return; } if (commandArray.length == 2 && commandArray[1] == 'on') { runBot(message.user,'tipMenuBot'); return; } if (commandArray.length == 3 && commandArray[1] == 'happy' && commandArray[2] == 'off') { disableHappyTime(); return; } if (commandArray.length == 3 && commandArray[1] == 'happy' && commandArray[2] == 'on') { enableHappyTime(); return; } if (commandArray.length == 2 && commandArray[1] == 'all') { broadcastTipMenu(); return; } if (commandArray.length == 3 && commandArray[1] == 'all' && commandArray[2] == 'off') { wetBotData.bots.tipMenuBot.timeoutId = cb.cancelTimeout(wetBotData.bots.tipMenuBot.timeoutId); sendTipMenuBroadcastOff(message.user); return; } if (commandArray.length == 4 && commandArray[1] == 'all' && commandArray[2] == 'on' && !isNaN(parseInt(commandArray[3])) && parseInt(commandArray[3]) > 0) { wetBotData.bots.tipMenuBot.timeoutId = cb.cancelTimeout(wetBotData.bots.tipMenuBot.timeoutId); wetBotData.bots.tipMenuBot.timeout = parseInt(commandArray[3]); broadcastTipMenuTimeout(); // feedback to user sendTipMenuBroadcastOn(message.user, parseInt(wetBotData.bots.tipMenuBot.timeout)); return; } else return false; } function processLotteryCommand(message, commandArray) { var lotteryBot = wetBotData.bots.lotteryBot; if (commandArray.length == 1) { sendLotteryInfoNotice(message.user); return; } if (commandArray.length == 2 && commandArray[1] == 'help') { sendLotteryHelp(message); return; } if (commandArray.length == 2 && commandArray[1] == 'numbers') { sendLotteryNumbersNotice(message.user); return; } if (message.user !== cb.room_slug && !message.is_mod) { return false; } if (commandArray.length == 2 && commandArray[1] == 'prizes') { sendLotteryPrizesNotice(message.user); return; } if (commandArray.length == 2 && commandArray[1] == 'restart') { lotteryRestart(message.user); return; } if (commandArray.length == 2 && commandArray[1] == 'off') { stopBot(message.user, 'lotteryBot'); return; } if (commandArray.length == 2 && commandArray[1] == 'on') { runBot(message.user,'lotteryBot'); return; } if (commandArray.length == 2 && commandArray[1] == 'all') { broadcastLotteryInfo(); return; } if (commandArray.length == 3 && commandArray[1] == 'all' && commandArray[2] == 'off') { if (!lotteryBot.enabled) { sendBoldNotice(message.user, 'LOTTERY BOT IS NOT ENABLED', lotteryBot.colors.foreground, lotteryBot.colors.background); return; } lotteryBot.timeoutId = cb.cancelTimeout(lotteryBot.timeoutId); sendLotteryBroadcastOffNotice(message.user); return; } if (commandArray.length == 4 && commandArray[1] == 'all' && commandArray[2] == 'on' && !isNaN(parseInt(commandArray[3])) && parseInt(commandArray[3]) > 0) { if (!lotteryBot.enabled) { sendBoldNotice(message.user, 'LOTTERY BOT IS NOT ENABLED', lotteryBot.colors.foreground, lotteryBot.colors.background); return; } lotteryBot.timeoutId = cb.cancelTimeout(lotteryBot.timeoutId); lotteryBot.timeout = parseInt(commandArray[3]); cb.setTimeout(broadcastLotteryInfoTimeout, 2000); sendLotteryBroadcastOnNotice(message.user, parseInt(commandArray[3])); return; } return false; } function splitBySpaces(string) { return string.trim().replace(/\s+/g, ' ').split(' '); } ///////////////////// // tippers // ///////////////////// function sendTippersHelp(message) { sendNotice(message.user, getTippersHelp(message) ); } function sendTippersList(message) { var tippersBot = wetBotData.bots.tippersBot, sorted = sortTippers(tippersBot.tippers), unicode = wetBotData.bots.tippersBot.unicode, resultString = ''; if (sorted.length == 0 ){ resultString = 'NOBODY TIPPED SINCE THE APP STARTED'; sendBoldNotice(message.user, resultString, tippersBot.colors.foreground, tippersBot.colors.background); return; } else { resultString += ' THIS IS THE LIST OF TIPPERS SINCE THIS APP STARTED' + lineBreak + ' Total tips: ' + tippersBot.tipCount + lineBreak + ' Total tokens: ' + tippersBot.tipSum + lineBreak + ' Total tippers: ' + objectSize(tippersBot.tippers) + lineBreak; sorted.forEach(function(username, index){ var isFan = tippersBot.tippers[username].data.in_fanclub; resultString += (index+1) + ". " + tippersBot.tippers[username]['sum'] + " | " + username + " " + (isKingTipper(username) ? tippersBot.emotes.kingTipper + " ": "") + (isBombTipper(username) ? tippersBot.emotes.bombTipper + " ": "") + (isFan ? wetBotData.bots.fansBot.emotes.fanClub + " " : "") + getClubEmotesList(username).join(' ') + lineBreak; }); resultString = bracket(resultString, unicode, 3, 0); } sendBoldNotice(message.user, resultString, tippersBot.colors.foreground, tippersBot.colors.background); } function sendKing(message) { if (tippersList.length == 0) { sendBoldNotice(message.user, bracket('NOBODY TIPPED SINCE THE APP STARTED', '', 0, 0), wetBotData.bots.tippersBot.colors.foreground, wetBotData.bots.tippersBot.colors.background) return; } var emote = wetBotData.bots.tippersBot.emotes.kingTipper, king = wetBotData.bots.tippersBot.kingTipper, amount = wetBotData.bots.tippersBot.kingTipperSum, fanEmote = ((tippersList[king] != undefined && tippersList[king].data.in_fanclub) ? " " + wetBotData.bots.fansBot.emotes.fanClub + " " : ""), clubsEmote = (king == "") ? clubsEmote = getClubEmotesList(king).join(" ") : '', resultString = ((king == "") ? "NOBODY TIPPED SINCE THE APP STARTED" : emote + " The KING tipper is " + king + fanEmote + clubsEmote + " with a total of " + amount + " tokens!! " + emote); sendBoldNotice(message.user, bracket(resultString, '', 0, 0), wetBotData.bots.tippersBot.colors.foreground, wetBotData.bots.tippersBot.colors.background); } function sendBomb(message) { if (tippersList.length == 0) { sendBoldNotice(message.user, bracket('NOBODY TIPPED SINCE THE APP STARTED', '', 0, 0), wetBotData.bots.tippersBot.colors.foreground, wetBotData.bots.tippersBot.colors.background) return; } var emote = wetBotData.bots.tippersBot.emotes.bombTipper, bomb = wetBotData.bots.tippersBot.bombTipper, amount = wetBotData.bots.tippersBot.bombTip, fanEmote = ((tippersList[bomb] != undefined && tippersList[bomb].data.in_fanclub) ? " " + wetBotData.bots.fansBot.emotes.fanClub + " " : ""), clubsEmote = (bomb == "") ? clubsEmote = getClubEmotesList(bomb).join(" ") : '', resultString = ((bomb == "") ? "NOBODY TIPPED SINCE THE APP STARTED" : emote + " The BOMB tipper is " + bomb + fanEmote + clubsEmote + " with a tip of " + amount + " tokens!! " + emote); sendBoldNotice(message.user, bracket(resultString, '', 0, 0), wetBotData.bots.tippersBot.colors.foreground, wetBotData.bots.tippersBot.colors.background) } function isKingTipper(username) { return username === wetBotData.bots.tippersBot.kingTipper; } function isBombTipper(username) { return username === wetBotData.bots.tippersBot.bombTipper; } ////////////////// // fans // ////////////////// function sendFanMemberNotice ( user ) { var fansBot = wetBotData.bots.fansBot, verb = 'has', subject; if ( user.gender == 'm' ) subject = 'he is a member'; else if ( user.gender == 'f' ) subject = 'she is a member'; else if ( user.gender == 'c' ) verb = 'have', subject = 'they are members'; else subject = 'is a member'; var resultString = user.user + ' ' + verb + ' entered the room and ' + subject + ' of your fanclub ' + fansBot.emotes.fanClub; sendBoldNotice(cb.room_slug, bracket(resultString, fansBot.unicode, 0, 0), fansBot.colors.foreground, fansBot.colors.background); } function sendFansHelp( message ) { sendNotice(message.user, getFansHelp(message) ); } function sendFansList( message ) { var fansBot = wetBotData.bots.fansBot, tippersBot = wetBotData.bots.tippersBot, sorted = sortTippers(fansBot.tippers), unicode = fansBot.unicode, resultString = ''; if (sorted.length == 0 ){ resultString = "NO FAN TIPPED SINCE THE APP STARTED"; sendBoldNotice(message.user, resultString, fansBot.colors.foreground, fansBot.colors.background); return; } resultString += 'THIS IS THE LIST OF FANS WHO TIPPED SINCE THIS APP STARTED' + lineBreak; sorted.forEach(function(user, index){ resultString += (index+1) + ". " + fansBot.tippers[user]['sum'] + " | " + user + " " + (user == tippersBot.kingTipper ? tippersBot.emotes.kingTipper : "") + " " + (user == tippersBot.bombTipper ? tippersBot.emotes.bombTipper : "") + " " + getClubEmotesList(user).join(" ") + lineBreak; }); resultString = bracket(resultString, unicode, 3, 0); sendBoldNotice(message.user, resultString, fansBot.colors.foreground, fansBot.colors.background); } function sortTippers( tippersList ) { return keysSorted = Object.keys(tippersList).sort(function(a,b){ return tippersList[b]['sum']-tippersList[a]['sum']; }); } /////////////////// // clubs // /////////////////// function sendClubsHelp( message ) { sendNotice(message.user, getClubsHelp(message) ); } function sendClubsInfo( username ) { var resultString = '', clubsAvailableMap = wetBotData.bots.clubsBot.clubs; for ( var club in clubsAvailableMap ) { resultString += ' - ' + club + " " + clubsAvailableMap[club].emote + ' : ' + clubsAvailableMap[club].fee + ' tokens' + lineBreak; } resultString = (resultString.length == 0 ? "THE CLUBS LIST IS EMPTY!!" : "THESE ARE THE CLUBS AVAILABLE FOR JOINING" + lineBreak + resultString); sendBoldNotice( username, bracket(resultString, wetBotData.bots.clubsBot.unicode, 3, 0), wetBotData.bots.clubsBot.colors.foreground, wetBotData.bots.clubsBot.colors.background); } function sendClubsList( message, clubsList, username ) { var resultString = '', clubsBot = wetBotData.bots.clubsBot, clubsAvailableMap = clubsBot.clubs; if (clubsList == null || clubsList == undefined ) { // send full list for ( var club in clubsAvailableMap ) { resultString += lineBreak + 'MEMBERS OF ' + club.toUpperCase() + ' CLUB: ' + clubsAvailableMap[club].emote + lineBreak; clubsAvailableMap[club].members.forEach(function(username, index, array){ resultString += (' - ' + username + lineBreak); // TODO add more emotes here }); } resultString = (resultString.length == 0 ? "THE CLUBS ARE EMPTY!!" : "THIS IS THE CLUBS FULL LIST" + lineBreak + resultString); } else { // send club list resultString += username.toUpperCase() + ' IS A MEMBER OF: ' + lineBreak; clubsList.forEach(function(club, index, array){ resultString += (' - ' + club + ' ' +clubsAvailableMap[club].emote + lineBreak); // TODO add more emotes here }); } sendBoldNotice(message.user, bracket(resultString, wetBotData.bots.clubsBot.unicode, 3, 0 ), clubsBot.colors.foreground, clubsBot.colors.background); } function sendMembersList( message, membersList, club ) { var clubsBot = wetBotData.bots.clubsBot, clubsAvailableMap = clubsBot.clubs, resultString = 'THIS IS THE LIST OF MEMBERS OF ' + club.toUpperCase() + clubsAvailableMap[club].emote + lineBreak; membersList.forEach(function(username, index, array){ resultString += ' - ' + username + lineBreak; // TODO add more emotes here }); sendBoldNotice(message.user, bracket(resultString, wetBotData.bots.clubsBot.unicode, 3, 0), clubsBot.colors.foreground, clubsBot.colors.background); } function sendNewMemberNotice( username, club ) { var clubsBot = wetBotData.bots.clubsBot, emote = clubsBot.clubs[club].emote, resultString = lineBreak + username.toUpperCase() + ' IS A NEW MEMBER OF THE ' + club.toUpperCase() + 'CLUB!! ' + emote + lineBreak; sendBoldNotice(everyone, resultString, clubsBot.colors.foreground, clubsBot.colors.background); } function broadcastClubsNotice() { sendClubsInfo ( everyone ); } function sendClubInfoBroadcastOff( user ) { var clubsBot = wetBotData.bots.clubsBot, resultString = 'The club info will not be shown to the users'; sendBoldNotice(user, resultString, clubsBot.colors.foreground, clubsBot.colors.background); } function sendClubInfoBroadcastOn( user, minutes ) { var clubsBot = wetBotData.bots.clubsBot, resultString = 'The club info will be shown to the users every ' + minutes + ' minutes' ; sendBoldNotice(user, resultString, clubsBot.colors.foreground, clubsBot.colors.background); } function broadcastClubsBotNoticeTimeout() { var clubsBot = wetBotData.bots.clubsBot; broadcastClubsNotice (); clubsBot.timeout > 0 && (clubsBot.timeoutId = cb.setTimeout(broadcastClubsBotNoticeTimeout, clubsBot.timeout * 60 * 1000)); } function getMembersOf( club ) { var clubsBot = wetBotData.bots.clubsBot, clubsAvailableMap = clubsBot.clubs; return (clubsAvailableMap.hasOwnProperty(club.toLowerCase())) ? clubsAvailableMap[club].members : []; } function getClubsOf( username ) { var clubsBot = wetBotData.bots.clubsBot, clubsAvailableMap = clubsBot.clubs, clubsList = []; for (var club in clubsAvailableMap) { if (clubsAvailableMap[club].members.includes(username)) clubsList.push(club); } return clubsList; } function getClubEmotesList( username ) { var clubsList = wetBotData.bots.clubsBot.clubs, emotes = []; for (var clubName in clubsList) { clubsList[clubName].members.includes(username) && emotes.push(clubsList[clubName].emote); } return emotes; } ////////////////////// // tip menu // ////////////////////// function sendTipMenuHelp( message ) { sendNotice(message.user, getTipMenuHelp(message) ); } function insertInTipMenu( amount, description ) { var tipMenuList = wetBotData.bots.tipMenuBot.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 = wetBotData.bots.tipMenuBot.items; tipMenuList.splice(index, 1); } function sendAddTipMenuResult( username, item, price, index ) { var tipMenuBot = wetBotData.bots.tipMenuBot, resultString = '"' + item + '" (' + price + ') has been added to the tip menu in position ' + index; sendBoldNotice(username, resultString, tipMenuBot.colors.foreground, tipMenuBot.colors.background); } function sendRemoveTipMenuResult( username, index ) { var tipMenuBot = wetBotData.bots.tipMenuBot, resultString = 'menu item #' + index + ' has been removed from the tip menu'; sendBoldNotice(username, resultString, tipMenuBot.colors.foreground, tipMenuBot.colors.background); } function sendTipMenu( username, isMod ) { var resultString = '', tipMenuBot = wetBotData.bots.tipMenuBot, unicode = tipMenuBot.unicode, tipMenuList = tipMenuBot.items, happyTimeMsg = `Happy Time is enabled. Tip ${tipMenuBot.happyTimeTip} tokens and every item in the tip menu will be ${tipMenuBot.happyTimeSale}% cheaper for ${tipMenuBot.happyTimeDuration} seconds.`; if (!tipMenuBot.enabled) { resultString = "THE TIP MENU IS NOT ENABLED"; sendBoldNotice(username, resultString, tipMenuBot.colors.foreground, tipMenuBot.colors.background); return; } tipMenuList.forEach(function(item, index){ var indexPrefix = (username == cb.room_slug || isMod) ? '( ' + index +' )' :'', amount = tipMenuBot.happyTimeTriggered ? happyTimePrice(item.amount, tipMenuBot.happyTimeSale) + ' SALE!!' : item.amount ; resultString += ( unicode + ' --' + indexPrefix + '-- ' + amount + ' | ' + item.description + lineBreak); // TODO add more unicodes here }); if (resultString.length == 0) { resultString = "THE TIP MENU IS EMPTY!!"; sendBoldNotice(username, resultString, tipMenuBot.colors.foreground, tipMenuBot.colors.background); return; } resultString = lineBreak + repeat(unicode, 5) + " HERE'S MY TIP MENU " + repeat(unicode, 5) + lineBreak + resultString; sendBoldNotice(username, resultString, tipMenuBot.colors.foreground, tipMenuBot.colors.background); tipMenuBot.happyTimeEnabled && sendBoldNotice(username, unicode + ' ' + happyTimeMsg.toUpperCase(), tipMenuBot.colors.background, tipMenuBot.colors.foreground); } function sendTipMenuHistory( username ) { var resultString = '', tipMenuBot = wetBotData.bots.tipMenuBot, 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.colors.foreground, tipMenuBot.colors.background); } function sendTipMenuCounter( username ) { var resultString = '', tipMenuBot = wetBotData.bots.tipMenuBot, 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.colors.foreground, tipMenuBot.colors.background); } function sendTipMenuNotice( username, description) { var unicode = wetBotData.bots.tipMenuBot.unicode, resultString = lineBreak + repeat(unicode,20) + lineBreak + unicode + lineBreak + unicode + repeat(' ', 3) + username.toUpperCase() + ' HAS JUST TIPPED FOR THE MENU ITEM ' + lineBreak + unicode + repeat(' ', 3) + description.toUpperCase() + lineBreak + unicode + lineBreak + repeat(unicode,20) + lineBreak; sendBoldNotice(everyone, resultString, wetBotData.bots.tipMenuBot.colors.foreground, wetBotData.bots.tipMenuBot.colors.background); } function sendTipMenuBroadcastOff( user ) { var tipMenuBot = wetBotData.bots.tipMenuBot, resultString = 'The tip menu will not be shown to the users'; sendBoldNotice(user, resultString, tipMenuBot.colors.foreground, tipMenuBot.colors.background); } function sendTipMenuBroadcastOn( user, minutes ) { var tipMenuBot = wetBotData.bots.tipMenuBot, resultString = 'The tip menu will be shown to the users every ' + minutes + ' minutes' ; sendBoldNotice(user, resultString, tipMenuBot.colors.foreground, tipMenuBot.colors.background); } function broadcastTipMenu() { sendTipMenu ( everyone ); } function broadcastTipMenuTimeout() { var tipMenuBot = wetBotData.bots.tipMenuBot; broadcastTipMenu (); tipMenuBot.timeout > 0 && (tipMenuBot.timeoutId = cb.setTimeout(broadcastTipMenuTimeout, tipMenuBot.timeout * 60 * 1000)); } //-- Happy time --// function happyTimePrice( amount, sale ) { var tipMenuBot = wetBotData.bots.tipMenuBot; return Math.floor(amount * (1 - sale/100)); } function sendHappyTimeTriggeredNotice() { var tipMenuBot = wetBotData.bots.tipMenuBot, 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.happyTimeSale}% !!!`; sendBoldNotice('', msg, tipMenuBot.colors.foreground, tipMenuBot.colors.background); } function sendHappyTimeInfoNotice() { var tipMenuBot = wetBotData.bots.tipMenuBot, 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.happyTimeSale}% !!!`; sendBoldNotice('', msg, tipMenuBot.colors.foreground, tipMenuBot.colors.background); tipMenuBot.happyTimeElapsedTimeoutId = cb.cancelTimeout(tipMenuBot.happyTimeElapsedTimeoutId); if (timeLeft > 30) { tipMenuBot.happyTimeElapsedTimeoutId = cb.setTimeout(sendHappyTimeInfoNotice, 30 * 1000); } } function enableHappyTime() { var tipMenuBot = wetBotData.bots.tipMenuBot; tipMenuBot.happyTimeTimeoutId = undefined; tipMenuBot.happyTimeTimeoutId = undefined; tipMenuBot.happyTimeEnd = 0; tipMenuBot.happyTimeTriggered = false; tipMenuBot.happyTimeEnabled = true; sendBoldNotice('', 'HAPPY TIME IS ENABLED', tipMenuBot.colors.foreground, tipMenuBot.colors.background); } function disableHappyTime() { var tipMenuBot = wetBotData.bots.tipMenuBot; 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 IS NOT ENABLED', tipMenuBot.colors.foreground, tipMenuBot.colors.background); } function triggerHappyTime() { var tipMenuBot = wetBotData.bots.tipMenuBot, now = Date.now(); tipMenuBot.happyTimeEnd = tipMenuBot.happyTimeEnd - now < 0 ? now + tipMenuBot.happyTimeDuration * 1000 : tipMenuBot.happyTimeEnd + tipMenuBot.happyTimeDuration * 1000; tipMenuBot.happyTimeTriggered = true; tipMenuBot.happyTimeTimeoutId && (tipMenuBot.happyTimeTimeoutId = cb.cancelTimeout(tipMenuBot.happyTimeTimeoutId)); tipMenuBot.happyTimeTimeoutId = cb.setTimeout(finishHappyTime, tipMenuBot.happyTimeEnd - now); sendHappyTimeTriggeredNotice(); if (tipMenuBot.happyTimeDuration > 30) { tipMenuBot.happyTimeElapsedTimeoutId && (tipMenuBot.happyTimeElapsedTimeoutId = cb.cancelTimeout(tipMenuBot.happyTimeElapsedTimeoutId)); tipMenuBot.happyTimeElapsedTimeoutId = cb.setTimeout(sendHappyTimeInfoNotice, 30 * 1000); } } function finishHappyTime() { var tipMenuBot = wetBotData.bots.tipMenuBot; 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.happyTimeTip} tokens to start for another ${tipMenuBot.happyTimeDuration} seconds!!!`, tipMenuBot.colors.foreground, tipMenuBot.colors.background); } ///////////////// // lottery // ///////////////// function sendLotteryHelp(message) { sendNotice(message.user, getLotteryHelp(message) ); } function endOfLotteryMessage() { var lotteryBot = wetBotData.bots.lotteryBot, resultString = 'There are no prizes left to tip for. ' + lineBreak + '-- :clap Thanks for playing, everyone!! :clap --' + lineBreak; return resultString; } function guessedFormat(value, char) { var lotteryBot = wetBotData.bots.lotteryBot, maxLen = String(lotteryBot.max).length, resultString = ''; while(maxLen--) { resultString += char; } return '[' + resultString + '] '; } function availableFormat(value) { var lotteryBot = wetBotData.bots.lotteryBot, padding = String(lotteryBot.max).length - String(value).length, resultString = String(value); while(padding--) { resultString = (padding % 2 ? padRight(' ', resultString): padLeft(' ', resultString)); } return '[' + resultString + '] '; } function availableNumbers() { var lotteryBot = wetBotData.bots.lotteryBot, resultString = '', i; for (i=lotteryBot.min; i <= lotteryBot.max; i++) { resultString += (lotteryBot.guesses.includes(i) ? guessedFormat(i,'x') : availableFormat(i)) + ((i%10)?'':lineBreak); } return resultString; } function sendLotteryResultNotice(username, amount, prize) { var lotteryBot = wetBotData.bots.lotteryBot, lotteryGuessesList = lotteryBot.guesses, lotteryPrizesMap = lotteryBot.prizes, resultString = '', destination = '', resultMessageList = []; // if number has been already guessed if (lotteryGuessesList.includes(amount)) resultMessageList.push('Somebody else has already tipped this number, so obviously '); else lotteryGuessesList.push(amount); if ( prize == undefined) { resultMessageList.push(amount + ' is not a winning number :sad_ , sorry!'); // send only to the uer who tipped destination = username; } else { delete lotteryPrizesMap[amount]; var availablePrizes = getAvailablePrizes(); resultMessageList.push('We have a winner!! ' + username + ' has guessed number ' + amount + lineBreak + 'PRIZE: ' + prize.toUpperCase() + lineBreak); if (objectSize(lotteryPrizesMap) == 0) resultMessageList.push(lineBreak + endOfLotteryMessage()); else{ for (prize in availablePrizes) { resultMessageList.push(' - ' + prize + ' (' + availablePrizes[prize].sum + ' left)'); } resultMessageList.push(lineBreak + 'Use "/lot numbers" to see the list of available numbers'); } // send to everyone destination = ''; } resultString = (destination == '' ? bracket(resultMessageList.join(lineBreak), lotteryBot.unicode, 3, 0) : resultMessageList.join(lineBreak)); sendBoldNotice(destination, resultString, lotteryBot.colors.foreground, lotteryBot.colors.background); } function lotteryRestart(username) { initLotteryBot(); // TODO MAKE THIS AN IF ELSE STATEMENT sendLotteryRestartNotice(username); } function sendLotteryRestartNotice(username) { var lotteryBot = wetBotData.bots.lotteryBot, resultString = 'The lottery prizes have been restarted' ; sendBoldNotice(username, resultString, lotteryBot.colors.foreground, lotteryBot.colors.background); } function sendLotteryBroadcastOffNotice(username) { var lotteryBot = wetBotData.bots.lotteryBot, resultString = 'The lottery notice will not be shown to the users' ; sendBoldNotice(username, resultString, lotteryBot.colors.foreground, lotteryBot.colors.background); } function sendLotteryBroadcastOnNotice(username, minutes) { var lotteryBot = wetBotData.bots.lotteryBot, resultString = 'The lottery notice will be shown to the users every ' + minutes + ' minutes' ; sendBoldNotice(username, resultString, lotteryBot.colors.foreground, lotteryBot.colors.background); } function sendLotteryInfoNotice(username) { var lotteryBot = wetBotData.bots.lotteryBot, availablePrizes = getAvailablePrizes(), resultString = 'THERE ARE NO LOTTERY PRIZES AVAILABLE AT THE MOMENT'; if (!lotteryBot.enabled) { sendBoldNotice(username, 'LOTTERY BOT IS NOT ENABLED', lotteryBot.colors.foreground, lotteryBot.colors.background); return; } else if (objectSize(availablePrizes) > 0) { resultString = 'ARE YOU FEELING LUCKY?? TIP AN AMOUNT FROM ' + lotteryBot.min + ' TO ' + lotteryBot.max + ' (included)' + lineBreak + 'Available prizes: ' + lineBreak ; for (var prize in availablePrizes) { resultString += (' - ' + prize + ' (' + availablePrizes[prize].sum + ' left)' + lineBreak); } resultString += 'Use "/lot numbers" to see the list of available numbers'; } sendBoldNotice(username, bracket(resultString, lotteryBot.unicode, 3, 0), lotteryBot.colors.foreground, lotteryBot.colors.background); } function sendLotteryNumbersNotice(username) { var lotteryBot = wetBotData.bots.lotteryBot, availablePrizes = getAvailablePrizes(), resultString = 'THERE ARE NO LOTTERY PRIZES AVAILABLE AT THE MOMENT'; if (!lotteryBot.enabled) { sendBoldNotice(username, 'LOTTERY BOT IS NOT ENABLED', lotteryBot.colors.foreground, lotteryBot.colors.background); return; } else if (objectSize(availablePrizes) > 0) { resultString = 'These are the available numbers: ' + lineBreak + availableNumbers(); } sendBoldNotice(username, bracket(resultString, lotteryBot.unicode, 3, 0), lotteryBot.colors.foreground, lotteryBot.colors.background); } function sendLotteryPrizesNotice(username) { var lotteryBot = wetBotData.bots.lotteryBot, availablePrizes = getAvailablePrizes(), resultString = 'THERE ARE NO LOTTERY PRIZES AVAILABLE AT THE MOMENT'; if (objectSize(availablePrizes) > 0) { resultString = 'Available prizes: ' + lineBreak ; for (var prize in availablePrizes) { var numbers = (availablePrizes[prize].sum > 1 ? availablePrizes[prize].numbers.slice(0,-1).join(', ') + ' and ' + availablePrizes[prize].numbers.slice(-1) : availablePrizes[prize].number); resultString += (' - ' + prize + ' (' + availablePrizes[prize].sum + ' left) in ' + numbers + lineBreak); } } sendBoldNotice(username, bracket(resultString, lotteryBot.unicode, 0, 0), lotteryBot.colors.foreground, lotteryBot.colors.background); } function broadcastLotteryInfo() { wetBotData.bots.lotteryBot.enabled && sendLotteryInfoNotice(everyone); } function getAvailablePrizes() { var lotteryBot = wetBotData.bots.lotteryBot, result = {}; for (var number in lotteryBot.prizes) { if (result[lotteryBot.prizes[number]] == undefined ) { result[lotteryBot.prizes[number]] = {sum:1, numbers:[number]}; } else { result[lotteryBot.prizes[number]].sum += 1; result[lotteryBot.prizes[number]].numbers.push(number); } } return result; } function broadcastLotteryInfoTimeout() { broadcastLotteryInfo(); wetBotData.bots.lotteryBot.timeout > 0 && (wetBotData.bots.lotteryBot.timeoutId = cb.setTimeout(broadcastLotteryInfoTimeout, wetBotData.bots.lotteryBot.timeout * 60 * 1000)); } //////////////// // 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 sendWelcomeMessages() { sendBoldNotice(everyone, getWelcomeMessage(), wetBotData.colors.foreground, wetBotData.colors.background); } ////////// // Init // ////////// function init() { wetBotData.colors.foreground = cb.settings.foreground && isValidColor(cb.settings.foreground) ? cb.settings.foreground : "#ffaa22"; wetBotData.colors.background = cb.settings.background && isValidColor(cb.settings.background) ? cb.settings.background : "#eee"; wetBotData.start = new Date().getTime(); initBots(); } function initBots() { initTippersBot(); initFansBot(); initClubsBot(); initTipMenuBot(); initLotteryBot(); } function initTippersBot() { wetBotData.bots.tippersBot.colors.foreground = cb.settings.tippersBotMessageForeground && isValidColor(cb.settings.tippersBotMessageForeground) ? cb.settings.tippersBotMessageForeground : wetBotData.colors.foreground; wetBotData.bots.tippersBot.colors.background = cb.settings.tippersBotMessageBackground && isValidColor(cb.settings.tippersBotMessageBackground) ? cb.settings.tippersBotMessageBackground : wetBotData.colors.background; wetBotData.bots.tippersBot.unicode = botsUnicodes.tippersBot; wetBotData.bots.tippersBot.emotes.kingTipper = cb.settings.kingTipperEmote && isValidEmote(cb.settings.kingTipperEmote) ? cb.settings.kingTipperEmote : ""; wetBotData.bots.tippersBot.emotes.bombTipper = cb.settings.bombTipperEmote && isValidEmote(cb.settings.bombTipperEmote) ? cb.settings.bombTipperEmote : ""; wetBotData.bots.tippersBot.minBombTip = (cb.settings.bombTipperMinValue && !isNaN(parseInt(cb.settings.bombTipperMinValue))) ? parseInt(cb.settings.bombTipperMinValue) : 0; wetBotData.bots.tippersBot.prependTipCount = cb.settings.tippersBotPrependTipCount == 'yes'? true : false; } function initFansBot() { wetBotData.bots.fansBot.colors.foreground = cb.settings.fanClubMessageGreen === "yes" ? colors.green : wetBotData.colors.foreground; wetBotData.bots.fansBot.colors.background = cb.settings.fansBotMessageBackground && isValidColor(cb.settings.fansBotMessageBackground) ? cb.settings.fansBotMessageBackground : wetBotData.colors.background; wetBotData.bots.fansBot.unicode = botsUnicodes.fansBot; wetBotData.bots.fansBot.emotes.fanClub = cb.settings.fanClubEmote && isValidEmote(cb.settings.fanClubEmote) ? cb.settings.fanClubEmote : ""; } function initClubsBot() { var clubsBot = wetBotData.bots.clubsBot; clubsBot.colors.foreground = cb.settings.clubsBotMessageForeground && isValidColor(cb.settings.clubsBotMessageForeground) ? cb.settings.clubsBotMessageForeground : wetBotData.colors.foreground; clubsBot.colors.background = cb.settings.clubsBotMessageBackground && isValidColor(cb.settings.clubsBotMessageBackground) ? cb.settings.clubsBotMessageBackground : wetBotData.colors.background; clubsBot.unicode = botsUnicodes.clubsBot; for (var i = 0; i < MAX_GROUPS; i++) { var clubName = cb.settings["clubName" + i] ? cb.settings["clubName" + i].trim() : '', clubEmote = cb.settings["clubEmote" + i] ? cb.settings["clubEmote" + i].trim() : '', clubFee = parseInt(cb.settings["clubFee" + i]); if (clubName.length > 0 && !isNaN(clubFee) && (clubEmote == '' || isValidEmote(clubEmote))) { clubsBot.clubs[clubName] = {}; clubsBot.clubs[clubName]['emote'] = clubEmote; clubsBot.clubs[clubName]['members'] = cb.settings["clubMemebers" + i].trim().split(/\s*,\s*/); // clubsBot.clubs[clubName]['foreground'] = cb.settings["clubForeground" + i].trim(); // clubsBot.clubs[clubName]['background'] = cb.settings["clubBackground" + i].trim(); clubsBot.clubs[clubName]['fee'] = cb.settings["clubFee" + i].trim(); } } // set timeout and launch var timeout = parseInt(cb.settings.clubsBotNoticeTimeout ); clubsBot.timeout = (isNaN(timeout) || timeout <= 0 )? 0 : timeout; if (cb.settings.clubsBotAutoStart == 'yes' && clubsBot.timeout > 0) broadcastClubsBotNoticeTimeout(); } function initTipMenuBot() { var tipMenuBot = wetBotData.bots.tipMenuBot; tipMenuBot.colors.foreground = cb.settings.tipMenuBotMessageForeground && isValidColor(cb.settings.tipMenuBotMessageForeground) ? cb.settings.tipMenuBotMessageForeground : wetBotData.colors.foreground; tipMenuBot.colors.background = cb.settings.tipMenuBotMessageBackground && isValidColor(cb.settings.tipMenuBotMessageBackground) ? cb.settings.tipMenuBotMessageBackground : wetBotData.colors.background; tipMenuBot.unicode = botsUnicodes.tipMenuBot; tipMenuBot.enabled = cb.settings.tipMenuBotEnabled == 'yes'? true : false; tipMenuBot.happyTimeEnabled = cb.settings.tipMenuBotHappyTimeEnabled == 'yes'? true : false; tipMenuBot.happyTimeTriggered = false; tipMenuBot.happyTimeTip = parseInt(cb.settings.tipMenuBotHappyTimeTriggerTip); tipMenuBot.happyTimeDuration = parseInt(cb.settings.tipMenuBotHappyTimeDuration); tipMenuBot.happyTimeSale = parseInt(cb.settings.tipMenuBotHappyTimeSale); 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(cb.settings.tipMenuTimeout); tipMenuBot.timeout = (isNaN(timeout) || timeout <= 0 )? 0 : timeout; if (tipMenuBot.enabled && cb.settings.tipMenuBotAutoStart == 'yes' && tipMenuBot.timeout > 0) { broadcastTipMenuTimeout(); } } function initLotteryBot() { var lotteryBot = wetBotData.bots.lotteryBot; lotteryBot.enabled = cb.settings.lotteryBotEnabled == 'yes'? true : false; lotteryBot.colors.foreground = cb.settings.lotteryBotMessageForeground && isValidColor(cb.settings.lotteryBotMessageForeground) ? cb.settings.lotteryBotMessageForeground : wetBotData.colors.foreground; lotteryBot.colors.background = cb.settings.lotteryBotMessageBackground && isValidColor(cb.settings.lotteryBotMessageBackground) ? cb.settings.lotteryBotMessageBackground : wetBotData.colors.background; lotteryBot.min = parseInt(cb.settings.lotteryBottom); lotteryBot.max = parseInt(cb.settings.lotteryTop); lotteryBot.prizes = {}; lotteryBot.guessed = []; lotteryBot.unicode = botsUnicodes.lotteryBot; var min = Math.ceil(parseInt(cb.settings['lotteryBottom'])), max = Math.floor(parseInt(cb.settings['lotteryTop']) + 1), value; for(var i = 0; i < MAX_LOTTERY_PRIZES; i++){ var description = cb.settings['lotteryPrizeDescription' + i] || '', amount = cb.settings['lotteryPrizeAmount' + i] && parseInt(cb.settings['lotteryPrizeAmount' + i]) ? parseInt(cb.settings['lotteryPrizeAmount' + i]) : 0 ; while(description.trim().length && amount > 0) { value = Math.floor(Math.random() * (max - min) + min); if ( !(value in lotteryBot.prizes) ) { lotteryBot.prizes[value] = cb.settings['lotteryPrizeDescription' + i]; amount -= 1; } } } // set timeout and launch var timeout = parseInt(cb.settings.tipMenuTimeout); lotteryBot.timeout = (isNaN(timeout) || timeout <= 0 )? 0 : timeout; if (lotteryBot.enabled && cb.settings.lotteryBotAutoStart == 'yes' && lotteryBot.timeout > 0) { broadcastLotteryInfoTimeout(); } } init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.