Bots Home
|
Create an App
me
Author:
i_love_asian_women
Description
Source Code
Launch Bot
Current Users
Created by:
I_Love_Asian_Women
/* * Setup vars and arrays for use throughout the bot */ var avatarCatalogArray = new Array(); var categoryList = ""; var avatarUsersArray = new Array(); var tempStr = ""; var botVersion = "1.0"; var avatarModStatus = ""; var avatarFanStatus = ""; var avatarUseStatus = ""; var avatarTipAmount = ""; var avatarModSw = ""; var avatarFanSw = ""; var avatarUseSw = ""; var avatarUsersCount = 0; var modelName = cb.room_slug; /* * Define CB settings parameters and default values */ cb.settings_choices = [ { name: 'avatarUseSw', type: 'choice', label: 'Enable Avatar use?', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes' }, { name: 'avatarAllowModSw', type: 'choice', label: 'Let Mods get Avatars for Free?', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes' }, { name: 'avatarAllowFanSw', type: 'choice', label: 'Let Fans get Avatars for Free?', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes' }, { name: 'avatarTipAmount', label: 'Minimum tip required to unlock Avatars?', type: 'str', minLength: 0, maxLength: 4, required: true, defaultValue: '20' }, { name: 'avatarPermaUsers', label: 'These users always get Avatars, separated by space (their CB usernames exactly)', type: 'str', minLength: 0, maxLength: 10240, required: false, defaultValue: '' }, ]; /* * handle messages and commands from model and users * Req: message = message object passed from CB * Returns: user message, or modified version of message along * with directly output public or private chat notification with * result of the request. This is the main logic of the script. */ cb.onMessage(function(message) { // define public variables and flags name = message['user']; msg = message['m']; commandProcessed = false; modelName = cb.room_slug; userMessage = ""; denyMsg = "Sorry, only " + modelName + " can use that command!"; helpMsg = modelName + " may use the following commands:\n" + "/avatar userlist = list of avatar users\n" + "/avatar grant name = grant avatar rights to name\n" + "/avatar revoke name = revoke avatar rights from name\n" + "/avatar tip amount = change required tip amount\n" + "/avatar enable = enable avatar use\n" + "/avatar disable = disable avatar use\n" + "/avatar mods enable = give mods free avatars\n" + "/avatar mods disable = disable free avatars for mods\n" + "/avatar fan enable = give fans free avatars\n" + "/avatar fan disable = disable free avatars for fans\n" + "---------------------------------------------------\n" + "Avatar users may use the following commands:\n" + "/avatar categoryname id = set/change your avatar\n" + "/avatar clear = clear your avatar\n" + "---------------------------------------------------\n" + "All users may use the following commands:\n" + "/avatar help = this list of commands\n" + "/avatar = show categories\n" + "/avatar categoryname = show avatars for category\n" + "/avatar status = show bot status\n" + "---------------------------------------------------\n" + "*** NOTE: To make names stick add them in the bot config."; // define private variables and flags var msgParam1 = ""; var msgParam2 = ""; var msgNotify = ""; var msgText = ""; var divStr = ""; var isMod = message['is_mod']; var isFan = message['in_fanclub']; var isModel = (name == cb.room_slug); var hasTokens = message['has_tokens']; var hasTipped = message['tipped_recently']; var isGrey = !(hasTokens || isMod || isModel || isFan); var notifyFgColor = '#000000'; var notifyBgColor = '#FFFFFF'; var alertFgColor = '#FFFFFF'; var alertBgColor = '#FF0000'; var useFgColor = notifyFgColor; var useBgColor = notifyBgColor; var msgAlert = false; var msgPublic = false; /* * handle the /avatar commands. all commands start with the trigger /avatar * followed by one or more parameters. */ if (msg.indexOf('/avatar') > -1) { msgParam1 = getParam(msg,' ',1); msgParam2 = getParam(msg,' ',2); switch(msgParam1) { /* * Help Command * Access: All Users * Output: Public * Error: None * Displays the help message with command list */ case 'help': message['X-Spam'] = true; divStr = makeDiv('*', 50, 50); msgNotify = divStr + '\n :myavatarbot ver ' + botVersion +'\nCreated by tablesalt90\n' + divStr + '\n' + helpMsg + '\n' + divStr; break; /* * Userlist Command * Access: Model Only * Output: Private * Error: Private * Displays a list of users that have access to avatar commands. * This includes those with perma access and those granted access. */ case 'userlist': message['X-Spam'] = true; if (isModel) { msgNotify = ':myavatarusers \n' msgNotify += showUsers(avatarUsersArray,'_'); } else { msgNotify = denyMsg; msgAlert = true; } break; /* * Grant Command * Access: Model Only * Output: Public * Error: Private * Allows the model to grant avatar use to a user without that user * having to tip. */ case 'grant': message['X-Spam'] = true; if (isModel) { if (!msgParam2) { msgNotify = 'Missing username. To use grant type /avatar grant username'; msgAlert = true; } else { // check to see if user is already in list if (!isUser(avatarUsersArray,msgParam2)) { avatarUsersArray = putUser(avatarUsersArray,msgParam2); msgNotify = 'User ' + msgParam2 + ' granted Avatar permission!'; msgAlert = true; msgPublic = true; } else { msgNotify = 'User ' + msgParam2 + ' already has Avatar permission!'; msgAlert = true; } } } else { msgNotify = denyMsg; msgAlert = true; } break; /* * Revoke Command * Access: Model Only * Output: Public * Error: Private * Allows the model to revoke avatar user from a user. */ case 'revoke': message['X-Spam'] = true; if (isModel) { if (!msgParam2) { msgNotify = 'Missing username. To use revoke type /avatar revoke username'; msgAlert = true; } else { avatarUsersArray = pullUser(avatarUsersArray,msgParam2); msgNotify = 'User ' + msgParam2 + ' avatar permission revoked!'; msgAlert = true; msgPublic = true; } } else { msgNotify = denyMsg; msgAlert = true; } break; /* * Tip Command * Access: Model Only * Output: Public * Error: Private * Changes the minimum amount of tokens required in a single tip * required to use/select an avatar. This does not revoke any users * from using avatars if the amount is changed. Users must be manually * revoked if the model wishes to force users to tip again. */ case 'tip': message['X-Spam'] = true; if (isModel) { if (!msgParam2) { msgNotify = 'Missing tip amount. To use tip command type /avatar tip amount'; msgAlert = true; } else { avatarTipAmount = msgParam2; msgNotify = 'Avatar tip amount changed to ' + msgParam2 + ' tokens!'; msgAlert = true; msgPublic = true; } } else { msgNotify = denyMsg; msgAlert = true; } break; /* * Enable Command * Access: Model Only * Output: Public * Error: Private * Enable avatar use (Standard Mode) */ case 'enable': message['X-Spam'] = true; if (isModel) { avatarUseSw = 'Yes'; avatarUseStatus = 'Enabled'; msgNotify = 'Avatars are enabled!'; msgAlert = true; msgPublic = true; } else { msgNotify = denyMsg; msgAlert = true; } break; /* * Disable Command * Access: Model Only * Output: Public * Error: Private * Disable avatars use (Quiet Mode) */ case 'disable': message['X-Spam'] = true; if (isModel) { avatarUseSw = 'No'; avatarUseStatus = 'Disabled'; msgNotify = 'Avatars are disabled!'; msgAlert = true; msgPublic = true; } else { msgNotify = denyMsg; msgAlert = true; } break; /* * Mods Command * Access: Model Only * Output: Public * Error: Private * Change the status of flags that control whether Mods must * tip for avatar selection. */ case 'mods': message['X-Spam'] = true; if (isModel) { if (!msgParam2) { msgNotify = 'Missing option. To use Free Mod mode type /avatar mods enable or /avatar mods disable'; msgAlert = true; } else { switch (msgParam2) { case 'enable': avatarModSw = 'Yes'; avatarModStatus = 'Enabled'; msgNotify = "Free Mod mode has been enabled. Mods get Free Avatars!"; msgAlert = true; msgPublic = true; break; case 'disable': avatarModSw = 'No'; avatarModStatus = 'Disabled'; msgNotify = "Free Mod mode has been disabled. Mods have to tip like everyone else!"; msgAlert = true; msgPublic = true; break; default: msgNotify = 'Invalid option. To use Free Mod mode type /avatar mods enable or /avatar mods disable'; msgAlert = true; break; } } } else { msgNotify = denyMsg; msgAlert = true; } break; /* * Fans Command * Access: Model Only * Error: Private * Change the status flags that control whether Fan Club Members * must tip for avatar selection. */ case 'fans': message['X-Spam'] = true; if (isModel) { if (!msgParam2) { msgNotify = 'Missing option. To use Free Fan mode type /avatar fans enable or /avatar fans disable'; msgAlert = true; } else { switch (msgParam2) { case 'enable': avatarFanSw = 'Yes'; avatarFanStatus = 'Enabled'; msgNotify = "Free Fan mode has been enabled. Fan Club Members get Free Avatars!"; msgAlert = true; msgPublic = true; break; case 'disable': avatarFanSw = 'No'; avatarFanStatus = 'Disabled'; msgNotify = "Free Fan mode has been disabled. Fan Club Members have to tip like everyone else!"; msgAlert = true; msgPublic = true; break; default: msgNotify = 'Invalid option. To use Free Fan mode type /avatar fans enable or /avatar fans disable'; msgAlert = true; break; } } } else { msgNotify = denyMsg; msgAlert = true; } break; /* * Status Command * Access: All Users * Error: None * executes the showbotstatus function to display the current * status of bot variables and arrays */ case 'status': message['X-Spam'] = true; showBotStatus(); break; /* * Clear Command * Access: Avatar Users * Error: None * removes the avatar from a user */ case 'clear': message['X-Spam'] = true; if (isUser(avatarUsersArray,name)) { clearUserAvatar(avatarUsersArray,name); msgNotify = 'Your avatar has been cleared!'; msgAlert = true; } break; /* * default command * Access: Users with Avatar access * Error: Private * depending on parameters this command will select an avatar, * display category, display avatar swatch. If only the /avatar command * is issued with no parameters the category list is displayed. * If the /avatar command is issued with the first parameter (category) only * then display the avatar swatch for that category. If the /avatar command is * issued with category and second parameter (avatar id) then set the avatar * emote for that user. * msgParam1 = category name * msgParam1 = avatar id * */ default: message['X-Spam'] = true; if (!msgParam1) { // show the category list msgNotify = 'Select one of the categories below...\n'; msgNotify += showCategoryList('_'); } else { // category selected, check for avatar ID if (!msgParam2) { // no avatar ID show category swatch msgNotify = 'Select one of the avatars from this swatch...\n'; msgNotify += showCategorySwatch(avatarCatalogArray,msgParam1); } else { // avatar id selected, check for access if (isUser(avatarUsersArray,name) || (isMod && avatarModSw == 'Yes') || (isFan && avatarFanSw == 'Yes') ) { msgNotify = ''; // check to see if mod or fan is a user if (!isUser(avatarUsersArray,name)) { // not a user, add user avatarUsersArray = putUser(avatarUsersArray,name); msgNotify = 'User ' + name + ' granted Free Avatar permission!\n'; } // valid user set avatar userAvatar = setUserAvatar(avatarUsersArray,name,avatarCatalogArray,msgParam1,msgParam2); msgNotify += 'You have selected the ' + userAvatar + ' avatar!'; if (avatarUseSw == 'No') { msgNotify += '\n Avatars use is currently disabled...'; } msgAlert = true; } else { // not valid user show tip message msgNotify = mustTipMsg(); msgAlert = true; } } } break; } } // Output any messages or results from commands if (msgNotify.length > 0) { useFgColor = notifyFgColor; useBgColor = notifyBgColor; if (msgAlert) { useFgColor = alertFgColor; useBgColor = alertBgColor; } if (msgPublic) { sendMsgTo = ''; } else { sendMsgTo = name; } cb.chatNotice(msgNotify, sendMsgTo, useBgColor, useFgColor,'bold'); msgNotify = ""; // reset notify msgPublic = false; } // return message and avatar is user has avatar if (isUser(avatarUsersArray,name) && avatarUseSw == 'Yes') { avatar = getUserAvatar(avatarUsersArray,name) message['m'] = avatar + " " + message['m']; } //return message; }); /* * handle tips * if tip is equal to or greater than the avatar tip * amount then grant access to use and annouce */ var total_tipped = 0; cb.onTip(function (tip) { var msgNotify = ""; var msgText = ""; var divStr = ""; var tipAmount = parseInt(tip['amount']); var name = tip['from_user']; var notifyFgColor = '#000000'; var notifyBgColor = '#FFFFFF'; var alertFgColor = '#000000'; var alertBgColor = '#FFD700'; var useFgColor = notifyFgColor; var useBgColor = notifyBgColor; var msgAlert = false; var msgPublic = false; if (tipAmount >= avatarTipAmount) { // check to see if user is in user array already if (!isUser(avatarUsersArray,name)) { // not a user, add user avatarUsersArray = putUser(avatarUsersArray,name); msgNotify = 'User ' + name + ' granted Avatar permission!\n'; msgNotify += 'Thank you for your tip!'; msgAlert = true; msgPublic = true; } } // Output any messages or results from tip actions if (msgNotify.length > 0) { useFgColor = notifyFgColor; useBgColor = notifyBgColor; if (msgAlert) { useFgColor = alertFgColor; useBgColor = alertBgColor; } if (msgPublic) { sendMsgTo = ''; } else { sendMsgTo = name; } cb.chatNotice(msgNotify, sendMsgTo, useBgColor, useFgColor,'bold'); msgNotify = ""; // reset notify msgPublic = false; } }); /* * Whooo hoooo helper functions * *************************************************************************************/ /* * return a formated list of categories * Req: none * Return: categoryListOutput = formated list of categories */ function showCategoryList(divChr) { var categoryListOutput = ""; var divStr = ""; var maxDivLen = 50; // see if the category list has been populated // this is only needs to be populated once (first time called) if (!categoryList) { categoryList = getCategoryList(avatarCatalogArray); } divStr = makeDiv(divChr, categoryList.length, maxDivLen); categoryListOutput = divStr +'\n' + categoryList + '\n' + divStr; return categoryListOutput; } /* * return a string of categories * Req: categoryArray = an array of categories which contains category objects * Return: categoryList = string of categories, space dilimited */ function getCategoryList(categoryArray) { var numberCategories = categoryArray.length; for (xx = 0; xx < numberCategories; xx++) { categoryList += categoryArray[xx][0] + ' '; } return categoryList; } /* * return emote for the category swatch of a cateogry * Req: categoryArray = the array containing the categories * Req: categoryName = the name of the category * Return: categorySwatch = the emote for the category swatch */ function showCategorySwatch(categoryArray,categoryName) { var categoryIndex = getCategoryIndex(categoryArray,categoryName); var categorySwatch = categoryArray[categoryIndex][1]; return categorySwatch; } /* * return string with avatar emoticon * Req: userArray = array of users * Req: userName = username of user * Return: userAvatar = string with avatar emoticon */ function getUserAvatar(userArray,userName) { var userElement = getArrayElement(userArray,userName); var userAvatar = userArray[userElement][1]; return userAvatar; } /* * set an avatar for a user and return string with avatar emoticon * Req: userArray = array of users * Req: userName = username of user * Req: categoryArray = array of avatar categories * Req: categoryName = name of selected category * Req: avatarId = id number of the selected avatar * Return: avatarEmot = string with the avatar emoticon */ function setUserAvatar(userArray,userName,categoryArray,categoryName,avatarId) { var userElement = getArrayElement(userArray,userName); var categoryIndex = getCategoryIndex(categoryArray,categoryName); var avatarEmot = getAvatarEmot(categoryArray,categoryIndex,avatarId); userArray[userElement][1] = avatarEmot; avatarUsersArray = userArray; return avatarEmot; } /* * remove the set avatar for a user * Req: userArray = array of users * Req: userName = username of user * Return: none */ function clearUserAvatar(userArray,userName) { var userElement = getArrayElement(userArray,userName); userArray[userElement][1] = ''; avatarUsersArray = userArray; return; } /* * return avatar emoticon string for a specific avatar * Req: categoryArray = array of categories * Req: categoryIndex = index or element number of category * Req: avatarId = id number of avatar * Return: avatarEmot = string with avatar emoticon */ function getAvatarEmot(categoryArray,categoryIndex,avatarId) { var avatarEmot = categoryArray[categoryIndex][2] + avatarId; return avatarEmot; } /* * return category index from category name * Req: categoryArray = array of categories * Req: categoryName = name of category * Return: categoryIndex = index or element id of category */ function getCategoryIndex(categoryArray,categoryName) { var categoryIndex = 0; var isIndex = -1; /* for (xx=0; xx < categoryArray.length; xx++) { isIndex = getArrayElement(categoryArray[xx], categoryName); if (isIndex > -1) { categoryIndex = xx; } } */ categoryIndex = getArrayElement(categoryArray, categoryName); return categoryIndex; } /* * return a string with a message for the user informing them * they must tip N amount of tokens to select an avatar * Req: none * Return: tempMsg = message with required tip amount */ function mustTipMsg() { var tempMsg = ""; tempMsg = 'You must tip ' + avatarTipAmount + ' tokens to select an avatar!'; return tempMsg; } /* * return boolean if user is in user array * Req: userArray = array of users to parse * Req: userName = name of user to parse fr * Returns: userFound = true or false */ function isUser(userArray,userName) { var userFound = false; userName = userName.toLowerCase(); // make username lowercase if(userArray.length > 0) { for(i=0; i < userArray.length; i++) { if (userArray[i][0] == userName) userFound = true; } } return userFound; } /* * return username of user added to user array * Req: msgString = full message as a string * Return: newUsername = user name of newly added user */ function addUser(msgString) { var newUserName = ""; newUsername = getParam(msgString,' ',1); avatarUsersArray = putUser(avatarUsersArray,newUsername); return newUsername; } /* * return parameter value from a message string * Req: msgString = full message as string * Req: splitChr = character to split on (usually space) * Req: paramNumber = number of the parameter to return (first is 0) * Return: paramValue = value of the requested parameter */ function getParam(msgString,splitChr,paramNumber) { var tempArray = new Array(); tempArray = msgString.split(splitChr); paramValue = tempArray[paramNumber]; return paramValue; } /* return user array after adding (pushing) new user * Req: userArray = array of users to push on * Req: userName = name of user to add (push) * Return: userArray = updated array of users */ function putUser(userArray,userName) { var userArrayCount = userArray.length; userArray[userArrayCount] = new Array(userName,''); return userArray; } /* * return user array after removing (pulling) user * Req: userArray = array of users to pull from * Req: userName = name of user to remove (pull) * Return: newUserArray = updated array of users */ function pullUser(userArray,userName) { var userElement = 0; var newUserArray = new Array(); userElement = getArrayElement(userArray,userName); if (userElement > -1) { newUserArray = removeArrayElement(userArray,userElement); } return newUserArray; } /* * return an array with the indicated element removed * Req: arrayName = array to be modified * Req: element = element to be removed * Return: newArray = the modified array */ function removeArrayElement(arrayName,element) { arrayName.splice(element, 1); return arrayName; } /* * return the element or index number of an array value * Req: arrayName = two dimensional array to parse * Req: value = value to find * Return: index of the element */ function getArrayElement(arrayName, value) { var index = 0; for (xx = 0; xx < arrayName.length; xx++) { if (arrayName[xx][0] == value) { index = xx; } } return index; } /* * return output ready list of user array * used to show list of users in an array * Req: userArray = array of user names * Req: divChar = division character * Return: nameListOutput = formated list of users for output */ function showUsers(userArray,divChr) { var nameList = ""; var nameListOutput = ""; var divStr = ""; var maxDivLen = 50; nameList = getUserList(userArray); divStr = makeDiv(divChr, nameList.length, maxDivLen); nameListOutput = divStr +'\n' + nameList + '\n' + divStr; return nameListOutput; } /* * return a list of usernames from an array of users * Req: userArray = array of user names * Return: nameString = string containing user names */ function getUserList (userArray) { var nameString = ""; for (xx = 0; xx < userArray.length; xx++) { nameString += userArray[xx][0] + ' '; } return nameString; } /* * build a variable length divider from a character * Req: divChr = the character to use for the divier, ie: _ - * * Req: strLen = length of the data to be divided (lenth of a string, or fixed) * Req: maxDivLen = the max number of characters the div can grow to * Return: divStr = string of repeated character that make the divider */ function makeDiv(divChr, strLen, maxDivLen) { var divLen = 0; var divStr = ""; if (strLen > maxDivLen) { divLen = maxDivLen; } else { divLen = strLen; } while (divStr.length < divLen) { divStr = divChr + divStr; } return divStr; } /* * output the status of bot settings * Req: none * Return: directly outputs status as a chat notice */ function showBotStatus() { var divStr = ""; var statusMsg = ""; divStr = makeDiv('*', 45, 45); avatarUsersCount = avatarUsersArray.length; statusMsg = divStr + '\n :myavatarbot ver ' + botVersion + '\nCreated by tablesalt90\n' + 'Avatar Use: ' + avatarUseStatus + '\n' + 'Mod Avatars Free: ' + avatarModStatus + '\n' + 'Fan Avatars Free: ' + avatarFanStatus + '\n' + 'Avatar Users: ' + avatarUsersCount + '\n' + 'Tip required: ' + avatarTipAmount + ' tokens\n' + 'Use /avatar help for commands!\n' + divStr; cb.chatNotice(statusMsg,'','','#FF0000','bold'); } /* * Builds arrays and strings based on data provided by CB * settings * Req: none * Return: none */ function loadSettings() { // Set default avatar use // if enabled avatar use allowed, // disabled, avatar use not allowed if (cb.settings.avatarUseSw == 'Yes') { avatarUseSw = 'Yes'; avatarUseStatus = 'Enabled'; } else { avatarUseSw = 'No'; avatarUseStatus = 'Disabled'; } // Set default for mod mode based on config. // if enabled mods get free Avatars if (cb.settings.avatarAllowModSw == "Yes") { avatarModSw = 'Yes'; avatarModStatus = 'Enabled'; } else { avatarModSw = 'No'; avatarModStatus = 'Disabled'; } // Set default for fan mode based on config. // if enabled fans get free Avatars if (cb.settings.avatarAllowFanSw == "Yes") { avatarFanSw = 'Yes'; avatarFanStatus = 'Enabled'; } else { avatarFanSw = 'No'; avatarFanStatus = 'Disabled'; } // Set default tip amount based on config. avatarTipAmount = cb.settings.avatarTipAmount; // Load perma users into array. if (cb.settings.avatarPermaUsers) { tempStr = cb.settings.avatarPermaUsers.toLowerCase(); cb.settings.avatarPermaUsers = tempStr.trim(); tempUsersArray = cb.settings.avatarPermaUsers.split(' '); countTempUsers = tempUsersArray.length; for (xx = 0; xx < countTempUsers; xx++) { avatarUsersArray[xx] = new Array(tempUsersArray[xx],''); } //avatarUsersArray[xx] = new Array(modelName,''); } // make sure model is in user array if (!isUser(avatarUsersArray,modelName)) { avatarUsersArray = putUser(avatarUsersArray,modelName); } } /* * build a complex array used to display the avatar catalog * the catalog array has the following structure: * array avatarCatalog ( * array (categoryName,avatarSwatch, avatarPrefix, avatarCount), * array ('female',':avatar_female_swatch',':avatar_female_',8), * array ('male',':avatar_male_swatch',':avatar_male_',10) * ) * each category has its own array of values * */ function loadCategories() { avatarCatalogArray[0] = new Array('female',':avatar_female_swatch',':avatar_female_',10); avatarCatalogArray[1] = new Array('male',':avatar_male_swatch',':avatar_male_',10); avatarCatalogArray[2] = new Array('halloween',':avatar_halloween_swatch',':avatar_halloween_',10); avatarCatalogArray[3] = new Array('hero',':avatar_hero_swatch',':avatar_hero_',10); avatarCatalogArray[4] = new Array('alien',':avatar_alien_swatch',':avatar_alien_',9); avatarCatalogArray[5] = new Array('mask',':avatar_mask_swatch',':avatar_mask_',4); } /* * let's get this thing started... load them settings */ loadSettings(); loadCategories(); // show status of bot showBotStatus();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.