Bots Home
|
Create an App
Dorothy's Dice Game
Author:
dorothy
Description
Source Code
Launch Bot
Current Users
Created by:
Dorothy
/** Name: Dorothy's Dice Game Bot Author: chelsea2950 Current version 1.0 Created 01/22/2019 **/ //** Enable for ESLINT syntax check, Disable for CB compile //var cb = ''; //var cbjs = ''; var t01brightrainbow = 'linear-gradient(to right, #ff6767, #ffdb9a, #ffff9d, #5fd85f, #9f9fff, #ff9bff)'; var t02pastelrainbow = 'linear-gradient(to right, #ff9a9a, #ffe4b4, #ffffb4, #bfd9bf, #add8e6, #e0d6f4)'; var t03valentines = 'linear-gradient(to right bottom, #ff7373, #ffe1f1)'; var t04christmas = 'linear-gradient(to right bottom, #6bdb6b, #ff9a9a)'; var t05halloween = 'linear-gradient(to right bottom, #ffba67, #ffffb4)'; var t06blue = 'linear-gradient(to right bottom, #a9c4f5, #d4ebf2)'; var t07green = 'linear-gradient(to right bottom, #9fc69f, #cfe3cf)'; var t08pink = 'linear-gradient(to right bottom, #ffb6da, #ffe9ec)'; var t09purple = 'linear-gradient(to right bottom, #c1adea, #dfd5f5)'; var t10blackgray = 'linear-gradient(to right bottom, #c6c6c6, #ececec)'; var t11sunset = 'linear-gradient(to right, #9489c2, #c600fb, #ffa200, #c600fb, #9489c2)'; var t12abv = 'linear-gradient(to right bottom, #00e0ff, #c600fb, #9489c2)'; var t13rwb = 'linear-gradient(to right bottom, #ff0000, #ffffff, #0027c1)'; var t14stpat = 'linear-gradient(to right bottom, #0e7312, #c0e6c3, #0e7312)'; var themeArray = { name: ['Bright Rainbow', 'Pastel Rainbow', 'Valentines', 'Christmas', 'Halloween', 'Shades of Blue', 'Shades of Green', 'Shades of Pink', 'Shades of Purple', 'Black and Gray', 'Sunset', 'Aqua/Blue/Violet', 'Red/White/Blue', 'St Patrick\'s Day' ], shortcut: ['brightrainbow', 'pastelrainbow', 'valentines', 'christmas', 'halloween', 'shadesblue', 'shadesgreen', 'shadespink', 'shadespurple', 'blackgray', 'sunset', 'aquablue', 'redwhiteblue', 'stpat' ], colorID: [t01brightrainbow, t02pastelrainbow, t03valentines, t04christmas, t05halloween, t06blue, t07green, t08pink, t09purple, t10blackgray, t11sunset, t12abv, t13rwb, t14stpat ], textcolor: ['#00008b', '#00008b', '#c7006b', '#ffffff', '#000000', '#00008b', '#006400', '#d00068', '#663399', '#000000', '#000000', '#d4ebf2', '#000000', '#024604' ]}; // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 var textColorArray = { dispname: ['White/No Color', 'Black', 'Dark Grey', 'Dark Red', 'Dark Orange', 'Dark Green', 'Dark Aqua', 'Dark Blue', 'Dark Purple', 'Dark Pink', 'Custom', 'Dark Gold', 'Dark Teal', 'Dark Brown', 'Dark Bronze', 'Dark Periwinkle', 'Dark Fuschia', 'Dark Lime', 'Dark Plum' ], name: ['white', 'black', 'darkgrey', 'darkred', 'darkorange', 'darkgreen', 'darkaqua', 'darkblue', 'darkpurple', 'darkpink', 'custom', 'darkgold', 'darkteal', 'darkbrown', 'darkbronze', 'darkperiwinkle', 'darkfuschia', 'darklime', 'darkplum' ], colorID: ['#FFFFFF', '#000000', '#737373', '#cc0000', '#e77400', '#006600', '#006767', '#0629AC', '#3d003d', '#ff6680', '#ffffff', '#998100', '#003f1f', '#582c00', '#a56728', '#155bd7', '#d6155c', '#6b790c', '#7f13bf' ]}; // 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 var bgColorArray = { dispname: ['White/No Color', 'Light Yellow', 'Light Blue', 'Light Pink', 'Light Red', 'Light Green', 'Light Purple', 'Light Orange', 'Light Grey', 'Light Aqua', 'Custom', 'Light Teal', 'Cream', 'Light Bronze', 'Light Periwinkle', 'Light Fuschia', 'Light Lime', 'Light Plum'], name: ['white', 'lightyellow', 'lightblue', 'lightpink', 'lightred', 'lightgreen', 'lightpurple', 'lightorange', 'lightgrey', 'lightaqua', 'custom', 'lightteal', 'cream', 'lightbronze', 'lightperiwinkle', 'lightfuschia', 'lightlime', 'lightplum' ], colorID: ['#FFFFFF', '#ffff94', '#d1eaee', '#FFE6EA', '#ff9a9a', '#94e594', '#f2cdff', '#ffd9b3', '#e6e6e6', '#adeaea', '#000000', '#d7fbee', '#f9f6ed', '#ebccad', '#d7e4fb', '#fbd7e4', '#ecf6a7', '#e3c0f9' ]}; // 1 2 3 4 5 6 7 8 9 10 var diceIconArray = { dispname: ['White on Red', 'Green', 'Blue', 'Gray', 'Green on Blue', 'Blue on Pink', 'Yellow on Red', 'Rainbow', 'Halloween', 'Red White and Blue' ], shortcut: ['whitered', 'green', 'blue', 'gray', 'greenblue', 'bluepink', 'yellowred', 'rainbow', 'halloween', 'redwhiteblue' ], iconabb: ['redwh_', 'green_', 'blue_', 'gray_', 'bluegr_', 'pinkblue_', 'redyel_', 'rnbw_', 'hlwn_', 'redwhbl_' ]}; cb.settings_choices = [ {name: 'dummy0', label: '---------------------------------------------------------------------------------------------------- Latest Updt: Sept 25, 2021 (version 1.1) See Change Log ---------------------------------------------------------------------------------------------------- ', type: 'choice',required: false}, {name: 'dummy1', label: '*** Introduction *** This is a dice roll game with two standard six sided dice, with possible rolls of 2-12, and a rare roll of a third die that could yield a special prize roll of 13. The defaulted price and prizes are only suggestions, please update them with your own choices. Keep in mind that the rolls of 7 are the most common, 6 or 8 next most common, and so on, so put prizes that you do not mind doing frequently in those middle slots. If the prize list is not fully filled in, the prize "Try Again" will be used for any missing prizes, except the rare prize, which will be disabled if not filled in', type: 'choice',required: false}, {name: 'diceMultiRolls', label: 'Multiple rolls allowed? -- Set the maximum number of rolls from one tip or set to 1 to only allow rolls for the specific dice price. For example: If this is set to 3 and you charge 30 tokens per roll, a user could tip exactly 60 for 2 rolls or exactly 90 for 3 rolls. Any tip amount that is not a multiple of the single roll will be ignored',required: false,type: 'int',minValue: 1,maxValue: 10, defaultValue: '1'}, {name: 'diceMinSpecial', label: 'Minimum for Rare Roll -- Set a minimum number of rolls before the special roll of 13 is allowed, and after it is won before it can be won again. Note that even after the minimum, there is only a 20% chance of enabling the third die (getting a 7 on the first two), and normal odds of rolling a 6 with the third die, so the odds of hitting 13 are about 1 in 30 *after* the minimum is satisfied',required: false, type: 'choice', choice1: '5', choice2: '10', choice3: '15', choice4: '20',choice5: '25', choice6: '30',choice7: '40', choice8: '50',defaultValue: '15'}, {name: 'diceRollPrice', label: 'Dice Roll Price',type: 'int',minValue: 1,maxValue: 99999,defaultValue: 38}, {name: 'diceColor', label: 'Dice Color', type: 'choice', choice1: diceIconArray.dispname[0], choice2: diceIconArray.dispname[1], choice3: diceIconArray.dispname[2], choice4: diceIconArray.dispname[3], choice5: diceIconArray.dispname[4], choice6: diceIconArray.dispname[5], choice7: diceIconArray.dispname[6], choice8: diceIconArray.dispname[7], choice9: diceIconArray.dispname[8], choice10: diceIconArray.dispname[9], defaultValue: diceIconArray.dispname[0]}, {name: 'dicePrize_2', label: 'Prize for dice roll of 2',type: 'str',defaultValue: 'Boob Flash'}, {name: 'dicePrize_3', label: 'Prize for dice roll of 3',type: 'str',defaultValue: 'Booty Flash'}, {name: 'dicePrize_4', label: 'Prize for dice roll of 4',type: 'str',defaultValue: 'Naked Jumping Jacks'}, {name: 'dicePrize_5', label: 'Prize for dice roll of 5',type: 'str',defaultValue: '3 Spanks'}, {name: 'dicePrize_6', label: 'Prize for dice roll of 6',type: 'str',defaultValue: 'Sexy Strip Tease'}, {name: 'dicePrize_7', label: 'Prize for dice roll of 7',type: 'str',defaultValue: 'Lap Dance'}, {name: 'dicePrize_8', label: 'Prize for dice roll of 8',type: 'str', defaultValue: 'Naked Squats'}, {name: 'dicePrize_9', label: 'Prize for dice roll of 9',type: 'str', defaultValue: '5 Spanks'}, {name: 'dicePrize_10', label: 'Prize for dice roll of 10',type: 'str', defaultValue: 'Try again'}, {name: 'dicePrize_11', label: 'Prize for dice roll of 11',type: 'str', defaultValue: 'Pussy or Cock Flash'}, {name: 'dicePrize_12', label: 'Prize for dice roll of 12',type: 'str', defaultValue: 'Oil and Massage Boobs'}, {name: 'dicePrize_13', label: 'Prize for dice roll of 13 (Rare special prize)',type: 'str',required: false,defaultValue: '5 Min BJ or Masturbation'}, {name: 'dummy5', label: '---------------------------------------------------------------------------------------------------- Optional Game Notice Settings & Personalization ----------------------------------------------------------------------------------------------------', type: 'choice',required: false}, {name: 'dummy6', label: '*** Optional Settings *** All below seetings are optional, you can accept the default display or you can change the below to customize the display to your liking. The Theme can be selected to match the other "Dorothy" apps and bots (or if you just like the color patterns), or you can select a solid color', type: 'choice',required: false}, {name: 'diceNoticeInterval', label: '1. Notice Interval -- Defined in minutes. Decimals are ok as long as they are greater than 1 (such as 1.5 for 1 min 30 sec)',type: 'str',defaultValue: 5.3,required: false}, {name: 'colorTheme', label: '2. Notice Background Multi-Color Pattern / Theme -- Choose one of these, or choose "None" and select a solid color below. These can be used to match other "Dorothy" app themese if you are using them (Fembot, UltraApp, Gamebot). Note that if a specific theme is used, it will always show a diagonal gradient, and setting "7" below is ignored.', type: 'choice', choice1: 'None', choice2: themeArray.name[0], choice3: themeArray.name[1], choice4: themeArray.name[2], choice5: themeArray.name[3], choice6: themeArray.name[4], choice7: themeArray.name[5], choice8: themeArray.name[6], choice9: themeArray.name[7], choice10: themeArray.name[8], choice11: themeArray.name[9], choice12: themeArray.name[10], choice13: themeArray.name[11], choice14: themeArray.name[12], choice15: themeArray.name[13], defaultValue: themeArray.name[5]}, {name: 'diceNoticeBgColor', label: '3. Notice Background Solid Color -- If you selected "None" for the Multi-Color Pattern above, you can set a solid color here also select the direction of the color fade in setting "7" below',type: 'choice', choice1: bgColorArray.dispname[0],choice2: bgColorArray.dispname[1],choice3: bgColorArray.dispname[2],choice4: bgColorArray.dispname[3],choice5: bgColorArray.dispname[4],choice6: bgColorArray.dispname[5],choice7: bgColorArray.dispname[6],choice8: bgColorArray.dispname[7],choice9: bgColorArray.dispname[8],choice10: bgColorArray.dispname[9],choice11: bgColorArray.dispname[10],choice12: bgColorArray.dispname[11],choice13: bgColorArray.dispname[12],choice14: bgColorArray.dispname[13],choice15: bgColorArray.dispname[14],choice16: bgColorArray.dispname[15],choice17: bgColorArray.dispname[16],choice18: bgColorArray.dispname[17],defaultValue: bgColorArray.dispname[8]}, {name: 'diceNoticeBgCustColor', label: '4. If you picked "Custom" as the Notice background color in the previous setting, enter the hex color (6 character hex color codes plus the # prefix):',type: 'str',minLength: 1,maxLength: 7,required: false}, {name: 'diceRollBgColor', label: '5. Roll Results Background Color',type: 'choice', choice1: bgColorArray.dispname[0],choice2: bgColorArray.dispname[1],choice3: bgColorArray.dispname[2],choice4: bgColorArray.dispname[3],choice5: bgColorArray.dispname[4],choice6: bgColorArray.dispname[5],choice7: bgColorArray.dispname[6],choice8: bgColorArray.dispname[7],choice9: bgColorArray.dispname[8],choice10: bgColorArray.dispname[9],choice11: bgColorArray.dispname[10],choice12: bgColorArray.dispname[11],choice13: bgColorArray.dispname[12],choice14: bgColorArray.dispname[13],choice15: bgColorArray.dispname[14],choice16: bgColorArray.dispname[15],choice17: bgColorArray.dispname[16],choice18: bgColorArray.dispname[17],defaultValue: bgColorArray.dispname[4]}, {name: 'diceRollBgCustColor', label: '6. If you picked "Custom" as the Roll Results background color in the previous setting, enter the hex color (6 character hex color codes plus the # prefix):',type: 'str',minLength: 1,maxLength: 7,required: false}, {name: 'colorsGradientDirection', label: '7. Color gradient (gradual fade from one color to another) direction -- If enabled, this is used for both the Solid Color Notice and the Dice Roll Results', type: 'choice', choice1: 'No', choice2: 'Linear, left to right', choice3: 'Linear, top to bottom', choice4: 'Linear, diagonally', defaultValue: 'Linear, diagonally'}, {name: 'noticeSepStyle', label: '8. Notice Border Style -- This controls how the top and bottom border of the recurring notice is displayed. You can choose from the defined options here, or use the below setting "9" to define your own emoji or other character. Depending on the type you choose, the spacing of the border will be different, so be sure to select the matching type here for the emoji or character you set below.', type: 'choice', choice1: 'No Border', choice2: 'Light Dashed Line', choice3: 'Heavy Dashed Line', choice4: 'Custom Emoji Below', choice5: 'Custom Unicode Character Below', choice6: 'Custom Emoji Below - Extra Space', defaultValue: 'Light Dashed Line'}, {name: 'separatorEmoji', label: '9. Notice Border emoji or text/unicode character -- For an emoji or unicode character, paste the actual emoji/image here, not the code. Note that most unicode characters have the benefit of being the same color as your text. Do NOT use a CB icon/gif here, if you do, it will default to "Heavy Dashed Line".', type: 'str',minLength: 0,maxLength: 2,required: false}, {name: 'boldText', label: '10. Display the Recurring Game Notice in bold or plain text?', type: 'choice', choice1: 'Bold Text', choice2: 'Plain Text', defaultValue: 'Bold Text'} ]; // *********************************** Variables and Arrays ************************************** var initialize = 0; var appNoticeColor = '#a2dfac'; // Used for general messaging (green) var appWarningColor = '#f4d599'; // Used for general messaging (yellow) var appErrorColor = '#f4c1bc'; // Used for general messaging (red) var commandBgColor = 'linear-gradient(to left, #ffffff 20%, #cfcfcf 100%)'; var BC = cb.room_slug; var botName = 'Dorothy\'s Dice Game: '; var colorTheme = cb.settings.colorTheme; var boldTextLiteral = ''; var borderCharSpacing = ''; var borderChar = cb.settings.separatorEmoji; var borderDiceTop = ''; var borderDicePrizesTop = ''; var borderDiceHistTop = ''; var borderUniversalBottom = ''; var borderShortBottom = ''; var checkEmojiChar = /(\u00a9|\u00ae|[\u2190-\u3300]|\ud83c[\ud000-\udfff]|\ud83d[\ud000-\udfff]|\ud83e[\ud000-\udfff])/gi; var wrapMaxLength = 75; var diceMultiRolls = cb.settings.diceMultiRolls; var diceRollPrice = cb.settings.diceRollPrice; var diceRollCounter = 0; var diceRollCounterSpecial = 0; var dicePrizes = []; var diceMinSpecial = parseInt(cb.settings.diceMinSpecial); var diceGifPfx = ':dorothydice_'; var diceColorShortcut = 'redwh_'; var diceRarePct = 20; var diceInt = 5.3*60000; var rarePrize = false; var diceRolls = {name: [], amt: [], desc: []}; var diceRollsReqTime = []; var diceRollInquiries = {name: [], time: []}; var diceNoticeBgColor = ''; var diceNoticeTextColor = ''; var diceRollTextColor = ''; var diceRollBgColor = ''; // *********************************** Initialize ************************************** if (initialize == 0) { let intromessage = 'Dorothy\'s Dice Game'; intromessage += '\n \u2705 Version 1.1 was released on September 25, 2021'; intromessage += '\n \u2705 This bot was written by CB user butter_my_toast.'; intromessage += '\n \u2705 Reminder: You can type "/dicehelp" to display the full command list.'; cb.sendNotice(intromessage,BC,appNoticeColor); loadDiceInterval(); setDiceRollColors(BC); if (colorTheme == 'None') { setDiceNoticeColors(BC); } else { diceNoticeBgColor = setThemeBgColor(BC); diceNoticeTextColor = setThemeTextColor(BC); } setDiceIconColor(); if (cb.settings.boldText == 'Bold Text') { boldTextLiteral = 'bold'; } noticeBorderChar(); diceSetPrizes(); diceNoticeTimer(); initialize = 1; } // *********************************** Generic Functions across all Dorothy Apps ************************************** function setThemeTextColor(sttcsendto) { let selectedthemetextcolor = '#000000'; if (cbjs.arrayContains(themeArray.name,colorTheme)) { let themeidx = themeArray.name.indexOf(colorTheme); return themeArray.textcolor[themeidx]; } else { cb.sendNotice(botName + ' Warning! Invalid theme setting of "' + colorTheme + '". \nDefaulting to no theme used.', sttcsendto, appWarningColor); colorTheme = 'None'; } return selectedthemetextcolor; } function setThemeBgColor(setthemeby) { let selectedthemebgcolor = '#FFFFFF'; if (cbjs.arrayContains(themeArray.name,colorTheme)) { let themeidx = themeArray.name.indexOf(colorTheme); selectedthemebgcolor = themeArray.colorID[themeidx]; } else { cb.sendNotice(botName + ' Warning! Invalid theme setting of "' + colorTheme + '". \nDefaulting to no theme used.', setthemeby, appWarningColor); colorTheme = 'None'; } return selectedthemebgcolor; } function setTextColor(inputtextcolor,inputtextcolortype,inputtextcolorsendto) { let selectedtextcolor = '#FFFFFF'; if (cbjs.arrayContains(textColorArray.dispname,inputtextcolor)) { let txtclridx = textColorArray.dispname.indexOf(inputtextcolor); selectedtextcolor = textColorArray.colorID[txtclridx]; } else { if (/^#[0-9A-F]{6}$/i.test(inputtextcolor)) { selectedtextcolor = inputtextcolor; } else if (/^[0-9A-F]{6}$/i.test(inputtextcolor)) { selectedtextcolor = '#' + inputtextcolor; } else { cb.sendNotice(botName + ' ' + inputtextcolortype + ' - Error while setting the text color. It must be in a HEX code format. Using default value of black text.', inputtextcolorsendto, appWarningColor); } } return selectedtextcolor; } function setBgColor(inputbgcolor,inputbgcolortype,inputbgcolorsendto) { let selectedbgcolor = '#FFFFFF'; if (cbjs.arrayContains(bgColorArray.dispname,inputbgcolor)) { let clridx = bgColorArray.dispname.indexOf(inputbgcolor); selectedbgcolor = bgColorArray.colorID[clridx]; } else { if (/^#[0-9A-F]{6}$/i.test(inputbgcolor)) { selectedbgcolor = inputbgcolor; } else if (/^[0-9A-F]{6}$/i.test(inputbgcolor)) { selectedbgcolor = '#' + inputbgcolor; } else { cb.sendNotice(botName + ' ' + inputbgcolortype + ' - Error while setting the background color. It must be in a HEX code format. Using default value of white/no background.', inputbgcolorsendto, appWarningColor); } } if (selectedbgcolor != '#FFFFFF') { if (cb.settings.colorsGradientDirection == 'Linear, left to right') { selectedbgcolor = 'linear-gradient(to right, ' + selectedbgcolor + ', #FFFFFF)'; } else if (cb.settings.colorsGradientDirection == 'Linear, top to bottom') { selectedbgcolor = 'linear-gradient(to bottom, ' + selectedbgcolor + ', #FFFFFF)'; } else if (cb.settings.colorsGradientDirection == 'Linear, diagonally') { selectedbgcolor = 'linear-gradient(to right bottom, ' + selectedbgcolor + ', #FFFFFF)'; } } return selectedbgcolor; } function noticeBorderChar() { let emojispace = ''; if (cb.settings.noticeSepStyle == 'Custom Emoji Below' || cb.settings.noticeSepStyle == 'Custom Emoji Below - Extra Space') { borderCharSpacing = 'emoji'; if (borderChar) { if (borderChar.includes(':') || borderChar.includes('\\')) { cb.sendNotice(botName + ' You have configured configured the notice border style as "Custom Emoji" but the value contains ":" or "\\" (CB gifs are not allowed). Defaulting to an emoji of Heavy Dashed Line " \u2796 ".', BC, appWarningColor); borderChar = '\u2796'; } } else { borderChar = '\u2796'; cb.sendNotice(botName + ' You have configured configured the notice border style as "Custom Emoji" but an emoji is not defined. Defaulting to an emoji of Heavy Dashed Line " \u2796 ".', BC, appWarningColor); } if (cb.settings.noticeSepStyle == 'Custom Emoji Below - Extra Space') { emojispace = '\n'; } } else if (cb.settings.noticeSepStyle == 'Custom Unicode Character Below') { borderCharSpacing = 'unicode'; if (borderChar) { if (borderChar.includes(':')) { cb.sendNotice(botName + ' You have configured configured the notice border style as "Custom Unicode Character" but the value contains ":" (CB gifs are not allowed). Defaulting to a character of Heavy Dashed Line " \u268A ".', BC, appWarningColor); borderChar = '\u268A'; } } else { borderChar = '\u268A'; cb.sendNotice(botName + ' You have configured configured the notice border style as "Custom Unicode Character" but a character is not defined. Defaulting to a character of Heavy Dashed Line " \u268A ".', BC, appWarningColor); } } else if (cb.settings.noticeSepStyle == 'Heavy Dashed Line') { borderCharSpacing = 'unicode'; borderChar = '\u268A'; } else if (cb.settings.noticeSepStyle == 'Light Dashed Line') { borderCharSpacing = 'light'; borderChar = '-'; } else { borderCharSpacing = 'none'; } switch (borderCharSpacing) { case 'emoji': borderDiceTop = noticeBorder('top','DICE GAME',10,false,true) + emojispace; borderDicePrizesTop = noticeBorder('top','DICE PRIZES',5,false,true) + emojispace; borderDiceHistTop = noticeBorder('top','DICE ROLL HISTORY',9,false,true) + emojispace; borderUniversalBottom = '\n' + emojispace + noticeBorder('bottom','',12,false,true); borderShortBottom = '\n' + emojispace + noticeBorder('bottom','',7,false,true); break; case 'unicode': borderDiceTop = noticeBorder('top','DICE GAME',19,false,false); borderDicePrizesTop = noticeBorder('top','DICE PRIZES',9,false,false); borderDiceHistTop = noticeBorder('top','DICE ROLL HISTORY',17,false,false); borderUniversalBottom = '\n' + noticeBorder('bottom','',22,false,false); borderShortBottom = '\n' + noticeBorder('bottom','',11,true ,false); break; case 'light': borderDiceTop = noticeBorder('top','DICE GAME',42,false,false); borderDicePrizesTop = noticeBorder('top','DICE PRIZES',21,false,false); borderDiceHistTop = noticeBorder('top','DICE ROLL HISTORY',35,false,false); borderUniversalBottom = '\n' + noticeBorder('bottom','',48,false,false); borderShortBottom = '\n' + noticeBorder('bottom','',28,false,false); break; case 'none': borderDiceTop = noticeBorder('top','DICE GAME',0,false,false); borderDicePrizesTop = noticeBorder('top','DICE PRIZES',0,false,false); borderDiceHistTop = noticeBorder('top','DICE ROLL HISTORY',0,false,false); borderUniversalBottom = ''; borderUniversalBottom = ''; break; } } function noticeBorder(bordertopbtm,bordertext,bordernumchar,bordernumaddone,borderdispspace) { let outcharstring = ''; let halfcharstring = ''; let midchar = '\u25CF'; let dispnumber = 0; if (borderCharSpacing == 'none') { if (bordertopbtm == 'top') { outcharstring = bordertext; } } else { for (let charidx = 1; charidx <= bordernumchar; charidx++) { if (borderdispspace) { halfcharstring += borderChar + ' '; } else { halfcharstring += borderChar; } } if (bordertopbtm == 'top') { outcharstring += halfcharstring + ' ' + bordertext + ' ' + halfcharstring; if (bordernumaddone) { outcharstring += borderChar; } } else if (bordertopbtm == 'bottom') { if (borderdispspace) { outcharstring += halfcharstring + halfcharstring; } else { outcharstring += halfcharstring + ' ' + midchar + ' ' + halfcharstring; } } } return outcharstring; } function loadDiceInterval() { let diceintmin = parseFloat(cb.settings.diceNoticeInterval); if (isNaN(diceintmin)) { diceintmin = 5.3; cb.sendNotice(botName + 'The Dice Game Chat Notice Interval is configured, but is not numeric, it must be a numeric value of at least one (decimals allowed). Using default value of 5.3 minutes.',BC,appWarningColor); } else if (diceintmin < 1) { diceintmin = 5.3; cb.sendNotice(botName + 'The Dice Game Chat Notice Interval is configured, but is too short, it must be at least 1 minute. Using default value of 5.3 minutes.',BC,appWarningColor); } diceInt = diceintmin*60000; } function checkNextLine(nlmessage) { let nlmessagearray = nlmessage.split(' '); let nllinearray = []; let templinearray = []; let lineidx = 0; let currlineidx = 0; let nlreplace = false; let nlsubfound = true; while (nlsubfound) { if (cbjs.arrayContains(nlmessagearray,'{n}')) { let nlmsgindex = nlmessagearray.indexOf('{n}'); nlmessagearray[nlmsgindex] = '\n'; templinearray = nlmessagearray.slice(currlineidx,nlmsgindex); nllinearray[lineidx] = wordWrap(cbjs.arrayJoin(templinearray,' ')); templinearray = nlmessagearray.slice(nlmsgindex+1); nllinearray[lineidx+1] = wordWrap(cbjs.arrayJoin(templinearray,' ')); lineidx++; currlineidx = nlmsgindex+1; nlreplace = true; } else { nlsubfound = false; } } if (nlreplace) { return cbjs.arrayJoin(nllinearray,'\n'); } else { return wordWrap(nlmessage); } } function wordWrap(wrapstring) { if (wrapMaxLength > 0) { let newlinechar = '\n'; let splitstring = ''; while (wrapstring.length > wrapMaxLength) { let spacefound = false; for (let wwidx = wrapMaxLength - 1; wwidx >= 0; wwidx--) { if (testWhite(wrapstring.charAt(wwidx))) { splitstring = splitstring + [wrapstring.slice(0, wwidx), newlinechar].join(''); wrapstring = wrapstring.slice(wwidx + 1); spacefound = true; break; } } if (!spacefound) { splitstring += [wrapstring.slice(0, wrapMaxLength), newlinechar].join(''); wrapstring = wrapstring.slice(wrapMaxLength); } } return splitstring + wrapstring; } else { return wrapstring; } } function testWhite(whitestring) { let white = new RegExp(/^\s$/); return white.test(whitestring.charAt(0)); } function howLongAgoCalc(inputtime) { let currenttimecalc = new Date(); let howlongago = (currenttimecalc.getTime() - inputtime); let howlongagoMS = howlongago % 1000; let howlongagoSec = Math.floor(((howlongago - howlongagoMS) % 60000)/1000); let howlongagoMin = Math.floor(((howlongago - howlongagoSec - howlongagoMS) % 3600000)/ 60000); let howlongagoHr = Math.floor(((howlongago - howlongagoMin - howlongagoSec - howlongagoMS) % 216000000)/ 3600000); let timeliteral = ''; if (howlongagoHr < 1 && howlongagoMin < 1) { timeliteral = howlongagoSec + ' sec ago'; } else if (howlongagoHr < 1) { if (howlongagoSec < 1) { timeliteral = howlongagoMin + ' min ago'; } else { timeliteral = howlongagoMin + ' min ' + howlongagoSec + ' sec ago'; } } else { if (howlongagoMin < 1) { timeliteral = howlongagoHr + ' hr ago'; } else { timeliteral = howlongagoHr + ' hr ' + howlongagoMin + ' min ago'; } } return timeliteral; } // *********************************** Dice Game Functions ************************************** function setDiceNoticeColors(sdncby) { diceNoticeTextColor = setTextColor('#000000','Dice Notice',sdncby); if (cb.settings.diceNoticeBgColor == 'Custom') { diceNoticeBgColor = setBgColor(cb.settings.diceNoticeBgCustColor,'Dice Notice',sdncby); } else { diceNoticeBgColor = setBgColor(cb.settings.diceNoticeBgColor,'Dice Notice',sdncby); } } function setDiceRollColors(sdcby) { diceRollTextColor = setTextColor('#000000','Dice Game',sdcby); if (cb.settings.diceRollBgColor == 'Custom') { diceRollBgColor = setBgColor(cb.settings.diceRollBgCustColor,'Dice Roll',sdcby); } else { diceRollBgColor = setBgColor(cb.settings.diceRollBgColor,'Dice Roll',sdcby); } } function setDiceIconColor() { if (cbjs.arrayContains(diceIconArray.dispname,cb.settings.diceColor)) { let diceiconidx = diceIconArray.dispname.indexOf(cb.settings.diceColor); diceColorShortcut = diceIconArray.iconabb[diceiconidx]; } else { cb.sendNotice(botName + 'Error loading the dice color name, "' + cb.settings.diceColor + '" does not exist in the program array. Defaulting to Red and White.',BC,appWarningColor); diceColorShortcut = 'redwh_'; } } function diceSetPrizes() { for (let dicesetidx = 2; dicesetidx <= 13; dicesetidx++) { if (dicesetidx == 13) { if (cb.settings['dicePrize_' + dicesetidx]) { dicePrizes.push(cb.settings['dicePrize_' + dicesetidx] + ' (RARE)'); rarePrize = true; } else { rarePrize = false; cb.sendNotice(botName + 'Special Rare Prize was not set, dice roll of "13" is disabled.',BC,appWarningColor); } } else { if (cb.settings['dicePrize_' + dicesetidx]) { dicePrizes.push(cb.settings['dicePrize_' + dicesetidx]); } else { dicePrizes.push('Try Again!'); } } } } function diceNoticeTimer() { diceShowNotice(''); cb.setTimeout(diceNoticeTimer,diceInt); } function diceShowNotice(sendto) { let dicegamemsg = borderDiceTop + '\n :diceroll1 '; if (diceMultiRolls <= 1) { dicegamemsg += '\nTip ' + diceRollPrice + ' token' + (diceRollPrice == 1 ? '' : 's') + ' to roll the dice!'; } else { dicegamemsg += '\nTip ' + diceRollPrice + ' token' + (diceRollPrice == 1 ? '' : 's') + ' (or multiples up to ' + diceMultiRolls + 'x) to roll the dice!'; } dicegamemsg += '\nTo see the Prize list, type: /diceprizes'; dicegamemsg += borderUniversalBottom; cb.sendNotice(dicegamemsg, sendto, diceNoticeBgColor, diceNoticeTextColor, boldTextLiteral); } function diceRoll(rolledby,numberrolls) { for (let rollidx = 0; rollidx < numberrolls; rollidx++) { diceRollCounter++; diceRollCounterSpecial++; let firstdie = Math.floor(Math.random() * 6) + 1; let seconddie = Math.floor(Math.random() * 6) + 1; if (diceRollCounterSpecial > diceMinSpecial && rarePrize) { if (Math.random() <= (diceRarePct / 100)) { firstdie = 7; diceRollCounterSpecial = 0; } } let dicetotal = firstdie + seconddie; let dicewinner = false; let diceprize = ''; if (dicetotal >= 2 && dicetotal <= 13) { dicewinner = true; diceprize = dicePrizes[dicetotal-2]; } else { dicewinner = false; diceprize = 'A Thank You!'; } let dicerollmsg = 'Roll #' + diceRollCounter + '...'; if (firstdie == 7) { dicerollmsg += '\n' + diceGifPfx + diceColorShortcut + '6 ' + diceGifPfx + diceColorShortcut + '1 ' + diceGifPfx + diceColorShortcut + seconddie; } else { dicerollmsg += '\n' + diceGifPfx + diceColorShortcut + firstdie + ' ' + diceGifPfx + diceColorShortcut + seconddie; } dicerollmsg += '\n' + rolledby + ' rolled a ' + dicetotal + '!'; if (dicetotal == 13) { dicerollmsg += ' \nPrize: :siren1 \uD83C\uDFB2 ' + diceprize + ' \uD83C\uDFB2 :siren1'; cb.sendNotice(dicerollmsg,'',diceRollBgColor,diceRollTextColor,'bold'); } else { dicerollmsg += ' \nPrize: \uD83C\uDFB2 ' + diceprize + ' \uD83C\uDFB2'; cb.sendNotice(dicerollmsg,'',diceRollBgColor,diceRollTextColor,'bold'); } diceRolls.name.push(rolledby); diceRolls.desc.push('prize "' + diceprize + '"'); diceRolls.amt.push(diceRollPrice); let currenttimedr = new Date(); diceRollsReqTime.push(currenttimedr.getTime()); } } function diceShowPrizes(diceprizessendto) { let diceprizelist = borderDicePrizesTop; let maxlengthchk = 13; if (!rarePrize) { maxlengthchk = 12; } if (dicePrizes.length > 0) { for (let diceprzidx = 2; diceprzidx <= maxlengthchk; diceprzidx++) { diceprizelist += '\nRoll of ' + diceprzidx + ' - ' + dicePrizes[diceprzidx-2]; } } else { diceprizelist = '\nThere are no prizes in the list.'; } diceprizelist += borderShortBottom; cb.sendNotice(diceprizelist,diceprizessendto,diceNoticeBgColor,diceRollTextColor,boldTextLiteral); } // *********************************** Help Function ************************************** function helpCommon(helpsendto) { let helptxtmsg = '\u23E9 Dice Game Commands:'; helptxtmsg += '\n \u2022 ' + wordWrap('/diceprizes: Display the list of prizes in the dice game. Available to any user, only shown to the user that requests it, unless requested by moderator or broadcaster - then it is sent to everyone.'); helptxtmsg += '\n \u2022 ' + wordWrap('/dicerolls: Display the last (up to) 10 rolls of the dice, especially helpful if several rolls have been made in a short period of time. Note that this has been merged together with the /posmenurequests and regular /tmr (/tipmenurequests) functions to show all 3 types of requests in one list.'); cb.sendNotice(helptxtmsg,helpsendto,appNoticeColor); } function helpModBC(helpsendto) { let helptxtmsg = '\u23E9 Dice Game Commands:'; helptxtmsg += '\n \u2022 ' + wordWrap('/diceprizes: Display the list of prizes in the dice game. Available to any user, only shown to the user that requests it, unless requested by moderator or broadcaster - then it is sent to everyone.'); helptxtmsg += '\n \u2022 ' + wordWrap('/diceprice [amt]: Change the dice roll price to a new amount [amt]. Available only to broadcasters and moderators.'); helptxtmsg += '\n \u2022 ' + wordWrap('/dicerolls: Display the last (up to) 10 rolls of the dice, especially helpful if several rolls have been made in a short period of time.'); helptxtmsg += '\n \u2022 ' + wordWrap('/freeroll: Broadcasters can perform a free roll of the dice - no tips required.'); cb.sendNotice(helptxtmsg,helpsendto,appNoticeColor); } // ******************************* Upon user entry of a Message ************************************** cb.onMessage(function (msg) { let trimmedmsg = msg.m.trim(); let msgarray = trimmedmsg.split(' '); let msgcommand = msgarray[0].toLowerCase(); let msguser = msg.user; let msgismod = msg.is_mod; let msgisbc = (msguser == BC); let msgishidden = false; if (msgcommand.charAt(0) == '/') { msg['X-Spam'] = true; msgishidden = true; //********* Dice Game commands switch (msgcommand) { case '/diceprizes': { let sendprizesto = msguser; if (msgismod || msgisbc) { sendprizesto = ''; } diceShowPrizes(sendprizesto); break; } case '/dicerolls': case '/dicerollsb': { let drsendto = msguser; if (msgcommand == '/dicerollsb') { if (msgismod) { drsendto = BC; cb.sendNotice(botName + ' You have sent the list of Dice Rolls to the broadcaster.',msguser,appWarningColor); } else { cb.sendNotice(botName + ' Only moderators can send the Dice Roll history to the broadcaster.',msguser,appWarningColor); } } let drreqlines = diceRolls.name.length; let drlinestoshow = 0; if (drreqlines <= 0) { cb.sendNotice(botName + ' There have been no Dice Rolls.', msguser, appWarningColor); } else if (msgarray[1] && msgarray[1] != 'all' && msgarray[1] != 'All' && msgarray[1] != 'ALL' && (isNaN(msgarray[1]) || msgarray[1] <= 0)) { cb.sendNotice(botName + ' Invalid parameter for number of dice rolls to display, must be a number greater than zero, "all", or blanks (blanks defaults to last 10).',msguser,appNoticeColor); } else { let noticeMsg = borderDiceHistTop; let drstartidx = 0; if (msgarray[1] == 'all' || msgarray[1] == 'All' || msgarray[1] == 'ALL') { drlinestoshow = drreqlines; } else if (msgarray[1]) { drlinestoshow = parseInt(msgarray[1]); } else { drlinestoshow = 10; } if (drlinestoshow > drreqlines) { if (msgarray[1]) { cb.sendNotice(botName + ' Requested more entries than available, showing entire list.', msguser,appWarningColor); } drlinestoshow = drreqlines; } else if (drlinestoshow > 100) { cb.sendNotice(botName + ' Maximum list size is 100 entries, defaulting to 100.', msguser,appWarningColor); drlinestoshow = 100; } noticeMsg += '\n \uD83C\uDFB2 \uD83C\uDFB2 \uD83C\uDFB2 Here ' + (drlinestoshow == 1 ? 'is the last' : 'are the last ' + drlinestoshow) + ' roll' + (drlinestoshow == 1 ? '' : 's') + ' from the Dice Game \uD83C\uDFB2 \uD83C\uDFB2 \uD83C\uDFB2'; drstartidx = drreqlines - drlinestoshow; for (let dridx = drstartidx; dridx < drreqlines; dridx++) { let howlongagodsp = howLongAgoCalc(diceRollsReqTime[dridx]); noticeMsg += '\nSeq #' + (dridx+1) + ': ' + diceRolls.name[dridx] + ' won ' + diceRolls.desc[dridx] + ' (' + howlongagodsp + ')'; if (cbjs.arrayContains(diceRollInquiries.name,drsendto)) { let drlastidx = diceRollInquiries.name.indexOf(drsendto); if (diceRollInquiries.time[drlastidx] > diceRollsReqTime[dridx] && (diceRollInquiries.time[drlastidx] < diceRollsReqTime[dridx+1] || dridx == (drreqlines - 1))) { let howlongagoinq = howLongAgoCalc(diceRollInquiries.time[drlastidx]); if (drsendto == BC) { noticeMsg += '\n>>> You were last sent or last viewed the dice roll summary (' + howlongagoinq + ') <<<'; } else { noticeMsg += '\n>>> You last viewed the dice roll summary (' + howlongagoinq + ') <<<'; } } } } noticeMsg += borderUniversalBottom; let currenttimereq = new Date(); if (cbjs.arrayContains(diceRollInquiries.name,drsendto)) { let drlastidx = diceRollInquiries.name.indexOf(drsendto); diceRollInquiries.time[drlastidx] = currenttimereq.getTime(); } else { diceRollInquiries.name.push(drsendto); diceRollInquiries.time.push(currenttimereq.getTime()); } cb.sendNotice(noticeMsg,drsendto,appNoticeColor); } break; } case '/diceprice': { if (msgismod || msgisbc) { let numprice = parseInt(msgarray[1]); if (isNaN(numprice)) { cb.sendNotice('The value entered for the new Dice Roll price is not numeric, please try again.', msguser, appWarningColor); } else if (numprice < 1 || numprice > 99999) { cb.sendNotice('The value entered for the new Dice Roll price is outside allowable values from 1 to 99999, please try again.', msguser, appWarningColor); } else { diceRollPrice = numprice; cb.sendNotice('The Dice Roll Price has been updated to ' + diceRollPrice + ' tokens.', '', diceNoticeBgColor, diceNoticeTextColor, 'bold'); } } else { cb.sendNotice('Only moderators and broadcasters are able to use that command.', msguser, appWarningColor); } break; } case '/freeroll': { if (msgisbc) { cb.sendNotice(botName + msguser + ' has triggered a free roll for the dice game.','', diceNoticeBgColor, diceNoticeTextColor, 'bold'); diceRoll(msguser,1); } else { cb.sendNotice('Only broadcasters are allowed to use that command.', msguser, appWarningColor); } break; } case '/dicehelp': { if (msgismod || msgisbc) { helpModBC(msguser); } else { helpCommon(msguser); } break; } } } if (msgishidden) { msg.background = commandBgColor; } return msg; }); // *********************************** Actions on user entering ************************************** cb.onEnter(function(user) { let enteruser = user.user; let enterhastokens = user.has_tokens; if (enterhastokens) { diceShowNotice(enteruser); } }); // *********************************** Actions upon leaving ************************************** cb.onLeave(function(user) { }); // *********************************** Actions upon tipping ************************************** cb.onTip(function (tip) { let tipamount = Number.parseInt(tip.amount, 10); let tipuser = tip.from_user if (tipamount >= diceRollPrice && (tipamount / diceRollPrice <= diceMultiRolls) && (tipamount % diceRollPrice == 0)) { let numrolls = Math.floor(parseInt(tipamount/diceRollPrice)); diceRoll(tipuser,numrolls); } });
© Copyright Chaturbate 2011- 2024. All Rights Reserved.