Bots Home
|
Create an App
Password Distribution Bot
Author:
dorothy
Description
Source Code
Launch Bot
Current Users
Created by:
Dorothy
/** Name: Password Distributor Author: butter_my_toast Created: 11/18/2020 See Change Log on bot description page for revision history **/ {cb.settings_choices = [ {name: 'dummy0', label: '********************** Introduction *********************** Latest Updt: 11/17/2020 (version 1.0) See Change Log. ********************************************************** Welcome to the Password Distribution Bot. This is used for different purposes, such as passing out passwords to a group of users for a game or private show. If doing multiple cycles, you can restart the bot each time you want to distribute a new password, or you can use the /newpass command to reset between each one to clear the list and set the new password. You can also choose your mode of distribution (what people have to do to get the password), and whether only the preferred users (mods, fans, defined list) get the password, or everyone can, or preferred list until a time period is up', type: 'choice', required: false}, {name: 'passwordValue', label: '1. Password - The value for the Password that will be sent out. It can also be updated during show with /newpass command if you do not set it now', type: 'str', required: false, minLength: 1, maxLength: 50}, {name: 'passwordRewardMode', label: '2. Password Request Mode - How do you want the bot to hand out the password? If choosing "Tip X tokens", set the token amount below in setting "3"',type: 'choice', choice1: 'Type the word "pass"', choice2: 'Type the number "1"', choice3: 'Tip X tokens', defaultValue: 'Type the word "pass"'}, {name: 'passwordRewardPrice', label: '3. If setting "2" above is "Tip X tokens", specify the tip amount here',type: 'int', minValue: 1, maxValue: 99999, defaultValue: 2}, {name: 'passwordMaxUsers', label: '4. Max Users to send -- How many users are allowed to receive the password through the automated request? Additional users can be shown the password after the "time limit" or "max users" are reached, depending on setting "6" below', type: 'int', minValue: 1, maxValue: 99999, defaultValue: 8}, {name: 'passwordMessageText', label: '5. Request Response Message (optional) -- What additional message would you like to send to each person who is given the password? (link to game, etc)',type: 'str', required: false, minLength: 1, maxLength: 500}, {name: 'passwordAllPlayFlag', label: '6. When to allow requests/access for all users? --- If you choose "Everyone can request", passwords are distributed to any requesting user on a first come, first serve basis. Ideally use this setting if anyone can tip to request --- If you choose "Only preferred list", then only moderators, CB fan members, and any users from the preferred list in setting "8" below will be able to request the password, and it is given out on a first come first serve basis. No other users are shown the password --- If you choose "After time limit", define the time in setting "7" below. Passwords can be requested immediately by the preferred list, and it will be shown to the rest of the room once time runs out --- If you choose "max users", passwords can be requested immediately by the preferred list and once the max slots are filled, the password is shown to the rest of the room after 30 seconds.', type: 'choice', choice1: 'Everyone can request', choice2: 'Only "preferred" list', choice3: 'After time limit', choice4: 'After max user limit', defaultValue: 'After max user limit'}, {name: 'passwordAllPlayTime', label: '7. When setting "6" is "After time limit", how long until non-Preferred users are shown the password, in minutes', type: 'int', required: false, minValue: 1, maxValue: 15, defaultValue: 2}, {name: 'passwordList', label: '8. Preferred User List (optional) -- Provide the list of preferred users that will be able to reqeust the password. You do not need to add moderators and CB Fanclub, they are in the preferred list automatically (but they still must perform the action in setting "2" to get the password). List should be usernames separated by commas', type: 'str', required: false, minLength: 0, maxLength: 5000}, {name: 'passwordReminderText', label: '9. Reminder Text (optional) -- Message to display to the room periodically to remind them to join. You can embed the text "{pass}" (no quotes) in your message to display the password from setting "1" as part of the message, just make sure the interval in setting "10" below is longer than the time for preferred members to join in setting "7" if doing so', type: 'str', required: false, minLength: 1, maxLength: 500}, {name: 'passwordReminderInt', label: '10. Display Interval -- Interval used for displaying the reminder message, in minutes', type: 'int', required: false, minValue: 1, maxValue: 15, defaultValue: 3} ]; } { // *********************************** Variables and Arrays ************************************** var initialize = 0; var caps = /[A-Z][A-Z]+/; var appNoticeColor = '#a2dfac'; // Used for general messaging from fembot (green) var appWarningColor = '#f4d599'; // Used for general messaging from fembot (yellow) var appAlertColor = '#f4c1bc'; // Used for general messaging from fembot (red) var backgroundColor = '#cdf2ff'; // Light sky blue var textColor = '#00008b'; // Dark midnight blue var dashLine60 = new Array(60).join('-'); var dashLine70 = new Array(70).join('-'); var dashLine80 = new Array(80).join('-'); var dashLine90 = new Array(90).join('-'); var allPlay = false; var passwordProvided = false; var preferredList = []; var checkMessageArray = []; var passwordHolders = []; } { // *********************************** Functions ************************************** { function startPasswordDistro(calledby,passwordval) { if (cb.settings.passwordAllPlayFlag == 'Everyone can request') { allPlay = true; } else { allPlay = false; if (cb.settings.passwordAllPlayFlag == 'After time limit') { startAllPlayTimer(); } } currentPassword = passwordval; numberRequested = 0; passwordHolders.length = 0; if (cb.settings.passwordRewardMode == 'Tip X tokens') { rewardMode = 'Tip ' + cb.settings.passwordRewardPrice + ' token' + (cb.settings.passwordRewardPrice == 1 ? '' : 's'); } else { rewardMode = cb.settings.passwordRewardMode; } if (cb.settings.passwordAllPlayFlag == 'After time limit') { cb.sendNotice(calledby + ' has enabled the Password Distribution. \nOnly Fans and Moderators will be able to request until the timer expires after ' + cb.settings.passwordAllPlayTime + ' minute' + (cb.settings.passwordAllPlayTime == 1 ? '' : 's') + '\nIn order to request a password, you can: ' + rewardMode, '', backgroundColor, textColor, 'bold'); } else if (cb.settings.passwordAllPlayFlag == 'Everyone can request') { cb.sendNotice(calledby + ' has enabled the Password Distribution. \nIn order to request a password, you can: ' + rewardMode, '', backgroundColor, textColor, 'bold'); } else if (cb.settings.passwordAllPlayFlag == 'Only "preferred" list') { cb.sendNotice(calledby + ' has enabled the Password Distribution. \nOnly Fans and Moderators will be able to request the password.\nIn order to request a password, you can: ' + rewardMode, '', backgroundColor, textColor, 'bold'); } else if (cb.settings.passwordAllPlayFlag == 'After max user limit') { cb.sendNotice(calledby + ' has enabled the Password Distribution. \nOnly Fans and Moderators will be able to request until the user threshold is reached: ' + cb.settings.passwordMaxUsers + ' user' + (cb.settings.passwordMaxUsers == 1 ? '' : 's') + '\nIn order to request a password, you can: ' + rewardMode, '', backgroundColor, textColor, 'bold'); } } function startAllPlayTimer() { if (isNaN(parseInt(cb.settings.passwordAllPlayTime))) { cb.sendNotice('Timer setting for when non-preferred users can request password is not valid, feature is disabled.', cb.room_slug, appWarningColor); allplayTimer = 0; } else { allplayTimer = parseInt(cb.settings.passwordAllPlayTime); } if (allplayTimer > 0) { apInt = parseInt(allplayTimer * 60000); cb.setTimeout(displayAllPlayNotice,apInt); } } function displayAllPlayNotice() { allPlay = true; cb.sendNotice(' :siren1 The password is now available to all users: ' + currentPassword + ' :siren1 ', '', backgroundColor, textColor, 'bold'); } function initReminderTimer() { if (isNaN(parseInt(cb.settings.passwordReminderInt))) { cb.sendNotice('Reminder notice interval is not valid, reminder is disabled.', cb.room_slug, appWarningColor); reminderTimer = 0; } else { reminderTimer = parseInt(cb.settings.passwordReminderInt); } if (reminderTimer > 0) { remInt = parseInt(reminderTimer * 60000); cb.setTimeout(displayReminder,remInt); } } function displayReminder() { if (passwordProvided) { cb.sendNotice(checkMessage(cb.settings.passwordReminderText), '', backgroundColor, textColor, 'bold'); } cb.setTimeout(displayReminder, remInt); } function requestPassword(requestuser,dispuser,reqaction) { if (passwordProvided) { cb.sendNotice('Audit message 4: ', 'butter_my_toast', appNoticeColor); if (cbjs.arrayContains(passwordHolders,requestuser)) { if (reqaction == 'tipping') { cb.sendNotice('Resending password: ' + currentPassword + '\nNote you can use the command /mypass to display it rather than tipping again.', requestuser, appNoticeColor); } else { cb.sendNotice('Resending password: ' + currentPassword, requestuser, backgroundColor, textColor, 'bold'); } } else { cb.sendNotice('Audit message 5: ' + numberRequested + ' ' + maxRequests, 'butter_my_toast', appNoticeColor); if (numberRequested < maxRequests) { numberRequested++; passwordHolders.push(requestuser); cb.sendNotice('Audit message 6: ' + currentPassword, 'butter_my_toast', appNoticeColor); cb.sendNotice('The current password is: ' + currentPassword + '\n' + cb.settings.passwordMessageText, requestuser, backgroundColor, textColor, 'bold'); cb.sendNotice('Password sent to ' + dispuser + ' (' + numberRequested + ')', '', backgroundColor, textColor, 'bold'); if (numberRequested >= maxRequests) { if (cb.settings.passwordAllPlayFlag == 'After max user limit') { cb.sendNotice(' :siren1 All available password requests have been filled! :siren1 \nPassword will be displayed to everyone in 30 seconds.', '', backgroundColor, textColor, 'bold'); cb.setTimeout(displayAllPlayNotice,30000); } else { cb.sendNotice(' :siren1 All available password requests have been filled! :siren1', '', backgroundColor, textColor, 'bold'); } } } else { cb.sendNotice('Sorry the maximum number of password requests has been met.', requestuser, appNoticeColor); } } } else { cb.sendNotice('Sorry the password has not yet been set.', requestuser, appNoticeColor); } } function checkMessage(checktext) { checkMessageArray = checktext.split(' '); replace = false; subfound = true; while (subfound) { if (cbjs.arrayContains(checkMessageArray,'{pass}')) { msgindex = checkMessageArray.indexOf('{pass}'); checkMessageArray[msgindex] = currentPassword; replace = true; } else if (cbjs.arrayContains(checkMessageArray,'{pass},')) { msgindex = checkMessageArray.indexOf('{pass},'); checkMessageArray[msgindex] = currentPassword + ','; replace = true; } else { subfound = false; } } if (replace) { return cbjs.arrayJoin(checkMessageArray,' '); } else { return checktext; } } // *********************************** Help Function ************************************** function helpModBC(from) { cb.sendNotice('Password Distributor help commands:',from,appNoticeColor); cb.sendNotice( '/newpass [password]: (mods/bc only) Clear the current user list and set a new password. The new password is the parameter, such as "/newpass pass123" (no quotes).' + '\n/pwsettings: (mods/bc only) See the current settings from the launch page.' + '\n/seepass: (mods/bc only) Display the current password only to the user entering the command.' + '\n/passlist: (mods/bc only) Display the list of current password holders.' + '\n/passto username: (mods/bc only) Send the password to a specific user ID not in the preferred list.' + '\n/passnow: (mods/bc only) Show the password to everyone immediately, don\'t wait for the timer or max users to be reached.' + '\n/mypass: (all users) A user who has already requested the password can have it displayed again.' ,from); cb.sendNotice('',from,appNoticeColor); } function helpCommon(from) { cb.sendNotice('Password Distributor help commands:',from,appNoticeColor); cb.sendNotice( '/mypass: (all users) A user who has already requested the password can have it displayed again.' ,from); cb.sendNotice('',from,appNoticeColor); } } } // ******************************* Upon user entry of a Message ************************************** { cb.onMessage(function (msg) { var message = msg['m'].split(' '); var cmd = 0; var listRegExp = /[,\s]+/; var listRegExpSpc = /[,]+/; var m = msg.m; var msgUser = msg.user; var msgDispUser = msg.user; var msgIsMod = msg.is_mod; var msgIsFan = msg.in_fanclub; var msgIsPreferred = cbjs.arrayContains(preferredList,msgUser); var msgIsBC = (msgUser === cb.room_slug); var BC = cb.room_slug; var command = message[0] var commandVar1 = parseInt(message[1]); var commandVar2 = parseInt(message[2]); if (message[0].charAt(0) == '/') { msg['X-Spam'] = true; //******** Chat Control Commands *********** switch(command) { case '/passhelp': { if (msgIsMod || msgIsBC) { helpModBC(msgUser); } else { helpCommon(msgUser); } break; } case '/newpass': { if (msgIsMod || msgIsBC) { if (message[1]) { passwordProvided = true; startPasswordDistro(msgUser,message[1]); } else { cb.sendNotice('A parameter was not specified, the new password must be provided as part of the command, such as "/newpass sjkd123" (no quotes).',msgUser,appNoticeColor); } } else { cb.sendNotice('Only moderators and broadcasters are able to use that command.', msgUser, appNoticeColor); } break; } case '/seepass': { if (msgIsMod || msgIsBC) { if (currentPassword) { cb.sendNotice('The current password is: ' + currentPassword, msgUser, backgroundColor, textColor, 'bold'); } else { cb.sendNotice('No password has been set, use the /newpass command to define the password and enable distribution.', msgUser, appNoticeColor); } } else { cb.sendNotice('Only moderators and broadcasters are able to use that command.', msgUser, appNoticeColor); } break; } case '/mypass': { if (cbjs.arrayContains(passwordHolders,msgUser)) { cb.sendNotice('The current password is: ' + currentPassword, msgUser, backgroundColor, textColor, 'bold'); } else { cb.sendNotice('You have not yet been provided a password.', msgUser, appNoticeColor); } break; } case '/passlist': { if (msgIsMod || msgIsBC) { cb.sendNotice('Users who have received the password: ' + passwordHolders.length + '\n' + (passwordHolders.length > 0 == true ? cbjs.arrayJoin(passwordHolders, ',') : 'No users.') + '\nEnd of List', msgUser, backgroundColor, textColor, 'bold'); } else { cb.sendNotice('Only moderators and broadcasters are able to use that command.', msgUser, appNoticeColor); } break; } case '/passto': { if (msgIsMod || msgIsBC) { if (passwordProvided) { if (message[1]) { requestPassword(message[1],message[1],'text'); } else { cb.sendNotice('A parameter was not specified, the new password must be provided as part of the command, such as "/newpass sjkd123" (no quotes).',msgUser,appNoticeColor); } } else { cb.sendNotice('Password has not been set yet.', msgUser, appNoticeColor); } } else { cb.sendNotice('Only moderators and broadcasters are able to use that command.', msgUser, appNoticeColor); } break; } case '/passnow': { if (msgIsMod || msgIsBC) { displayAllPlayNotice(); } else { cb.sendNotice('Only moderators and broadcasters are able to use that command.', msgUser, appNoticeColor); } break; } case '/pwsettings': { if (msgIsMod || msgIsBC) { cb.sendNotice( 'Dump of all current settings for Password Distributor:' + '\n*******************************************' + '\npasswordValue : ' + cb.settings.passwordValue + '\npasswordRewardMode : ' + cb.settings.passwordRewardMode + '\npasswordRewardPrice : ' + cb.settings.passwordRewardPrice + '\npasswordMaxUsers : ' + cb.settings.passwordMaxUsers + '\npasswordMessageText : ' + cb.settings.passwordMessageText + '\npasswordAllPlayFlag : ' + cb.settings.passwordAllPlayFlag + '\npasswordAllPlayTime : ' + cb.settings.passwordAllPlayTime + '\npasswordList : ' + cb.settings.passwordList + '\npasswordReminderText : ' + cb.settings.passwordReminderText + '\npasswordReminderInt : ' + cb.settings.passwordReminderInt + '\n*******************************************' ,msgUser); } else { cb.sendNotice('Only moderators and broadcasters are able to use that command.', msgUser, appNoticeColor); } break; } } } else { cb.sendNotice('Audit message 1: ' + cb.settings.passwordRewardMode + ' ' + message[0].charAt(0), 'butter_my_toast', appNoticeColor); if ((cb.settings.passwordRewardMode == 'Type the word "pass"' && message[0].toLowerCase() == 'pass') || (cb.settings.passwordRewardMode == 'Type the number "1"' && message[0].charAt(0) == '1')) { cb.sendNotice('Audit message 2: ', 'butter_my_toast', appNoticeColor); if (msgIsMod || msgIsFan || msgIsPreferred) { cb.sendNotice('Audit message 3: ', 'butter_my_toast', appNoticeColor); requestPassword(msgUser,msgDispUser,'text'); } else { if (allPlay) { requestPassword(msgUser,msgDispUser,'text'); } else { cb.sendNotice('Sorry the password is currently only available to the preferred user list.', msgUser, appNoticeColor); } } } } return msg; }); } // *********************************** Actions on user entering ************************************** { cb.onEnter(function(user) { }); } // *********************************** Actions upon leaving ************************************** { cb.onLeave(function(user) { }); } // *********************************** Actions upon tipping ************************************** { cb.onTip(function (tip) { var tipAmount = Number.parseInt(tip.amount, 10); var tipUser = tip.from_user; var isAnon = tip.is_anon_tip; var tipIsMod = tip.from_user_is_mod; var tipIsFan = tip.from_user_in_fanclub; var tipIsPreferred = cbjs.arrayContains(preferredList,tipUser); if (isAnon) { tipDisplayUser = 'Anonymous'; } else { tipDisplayUser = tipUser; } if (cb.settings.passwordRewardMode == 'Tip X tokens' && cb.settings.passwordRewardPrice == tipAmount) { if (tipIsMod || tipIsFan || tipIsPreferred) { requestPassword(tipUser,tipDisplayUser,'tipping'); } else { if (allPlay) { requestPassword(tipUser,tipDisplayUser,'tipping'); } else { cb.sendNotice('Sorry the password is currently only available to the preferred user list.', tipUser, appNoticeColor); } } } }); } // *********************************** Initialize ************************************** { if (initialize == 0) { intromessage = '** Password Distributor Bot Version 1.0 was released on 11/17/2020.'; intromessage += '\nYou can type "/passhelp" to display the command list summary.'; cb.sendNotice(intromessage, cb.room_slug, appAlertColor); if (cb.settings.passwordList) { var n = cb.settings.passwordList.toLowerCase(); preferredList = n.split(','); for (var i = 0; i < preferredList.length; i++) { preferredList[i] = preferredList[i].trim(); } } numberRequested = 0; if (cb.settings.passwordMaxUsers) { maxRequests = parseInt(cb.settings.passwordMaxUsers); } else { maxRequests = 99999; } if (cb.settings.passwordValue) { currentPassword = cb.settings.passwordValue; passwordProvided = true; } else { passwordProvided = false; cb.sendNotice('A password was not specified when launching the bot, the password can be set using the command /newpass, with the password as a paramater, such as "/newpass sjkd123" (no quotes).', cb.room_slug, appWarningColor, '', 'bold'); } if (passwordProvided) { startPasswordDistro(cb.room_slug,currentPassword); } initReminderTimer(); initialize = 1; } }
© Copyright Chaturbate 2011- 2024. All Rights Reserved.