Bots Home
|
Create an App
Dorothy's Raffle Bot
Author:
dorothy
Description
Source Code
Launch Bot
Current Users
Created by:
Dorothy
/** Name: Dorothy's Raffle Bot Author: chelsea2950 Created: 12/1/2019 See Change Log on bot description page for revision history **/ {cb.settings_choices = [ {name: 'dummy', label: '********************** Introduction *********************** Latest Updt: 12/20/2019 (version 1.1) See Change Log ******************************************************** This raffle bot lets you sell tickets for just one or multiple levels of prizes, and even multiple prizes within each level. You can have the drawing executed automatically at the end of a timed interval or when a certain number of tickets are sold, or you can do the drawing manually when you choose. There can be a single drawing or multiple drawings (a drawing every hour, etc). Each drawing can clear the ticket list or it can remain intact (cleared list is moved to a backup list each time). When performing the drawing, you can do all levels at once, or draw individual levels by setting a level value on the /raffledrawing command (see help for details). IMPORTANT!: If you would like to conduct the raffle over multiple shows, you will need to display the results at the end of each show (using /entries) and save that displayed string and paste it into the "Previous Show Results" field below when starting the next show to keep track of the tickets, as CB does not allow values captured by a bot during the show to be saved back to the launch page or between restarts of the bot. Once you deactivate the bot, your ticket sales for the current are erased and will not be there for the next show if you have not saved them.', type: 'choice',required: false}, {name: 'enableRaffle',required: false,label: 'Enable the Raffle when the bot is started? Alternatively you can start the bot, but not actually start the display of notices and selling of tickets until you are ready later. You can turn the raffle sales on and off during the show with the commands "/raffle on" and "/raffle off". Even when the raffle sales are turned off, the ticket list is still saved and available to display.', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'No'}, {name: 'raffleWhenDrawing', label: 'Which mode is used for when the drawing will take place? This setting works in combination with the next one to define what will trigger the end of the raffle, and who performs the drawing at the end (Broadcaster Command or Automated Drawing)', type: 'choice', choice1: 'Drawing at Broadcaster Discretion', choice2: 'Drawing after a Time Period', choice3: 'Drawing after a Ticket Goal', choice4: 'Drawing after a Token Goal', defaultValue: 'Drawing at Broadcaster Discretion'}, {name: 'raffleAutoDrawing', label: 'At the end of the raffle, if using a timer or goal, does the Broadcaster perform the drawing manually with the /raffledrawing command, or does the drawing occur automatically when time runs out or goal is reached?', type: 'choice', choice1: 'Broadcaster Performs Drawing', choice2: 'Automated Drawing', defaultValue: 'Broadcaster Performs Drawing'}, {name: 'raffleDrawingInterval',required: false,type: 'int',minValue: 1,maxValue: 120,defaultValue: 60,label: 'Time interval between drawings or until main drawing if there is only one. You can have the bot perform the drawing automatically at the end of the time period, or just have the timer run and perform the drawing manually using the command "/raffledrawing"'}, {name: 'raffleDrawingGoal',required: false,type: 'int',minValue: 1,maxValue: 10000,defaultValue: 500,label: 'Raffle goal in tickets or tokens per the above defined mode. As with the timer, you can have the bot perform the drawing automatically when goal is reached, or just track against the goal and perform the drawing manually using the command "/raffledrawing"'}, {name: 'raffleModDrawing', label: 'Allow a moderator to perform the ticket drawing for the broadcaster when in manual drawing mode?', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'No'}, {name: 'raffleTipMultiple', label: 'Allow a viewer to buy multiple raffle tickets with a single tip? Note that if this is turned on, and you use multiple levels of prizes, you should make sure that the prices for each level are not multiples of each other. The bot will use the first level it comes to that the tip is a multiple of. Also the tip multiples are not validated against the duplicate price checker', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'No'}, {name: 'raffleNoticeInterval',required: false,type: 'int',minValue: 1,maxValue: 20,defaultValue: 2,label: 'Time interval between postings of the notice that a raffle is going on. The text below will be shown in each notice, followed by a listing of the raffle levels and prizes.'}, {name: 'raffleNoticeText',type: 'str',minLength: 1,maxLength: 255,label: 'Enter the Text you would like to display in the Raffle Notice',required: false, defaultValue: 'A raffle is running today! You can buy tickets for a chance to win the prizes shown below.'}, {name: 'raffleContinuous',required: false,label: 'Will you perform multiple drawings and continuously renew the timer or goal? Or will you do a single drawing?', type: 'choice', choice1: 'Continuous', choice2: 'Single Drawing', defaultValue: 'Single Drawing'}, {name: 'raffleResetCycle',required: false,label: 'If performing multiple drawings, should all entries be cleared with each drawing? It is expected this would normally be "No", and tickets are retained until the end of the raffle or the ticket is drawn as a winner.', type: 'choice', choice1: 'No', choice2: 'Yes', defaultValue: 'No'}, {name: 'raffleTicketList',type: 'str',minLength: 1,maxLength: 2000,required: false,label: 'If running a show over multiple days or multiple sessions, paste the results from the previous session here. The formatting must be kept intact, where a user name and their ticket count is separated by a colon (:), and each pair is separated by a comma (,). For example, a string of user1:1:5,user2:1:1,user2:3:1 indicates user 1 has already bought 5 tickets at level 1, and user 2 has bought 1 ticket at level 1 and 1 ticket at level 3. The command "/entries" will display this list in the chat so you can copy and paste it into an external document to be saved for the next show'}, {name: 'dummyL1', label: '*********************** Level 1 ************************ Configure a price and up to 5 separate prizes that can be rewarded in the level 1 drawings (Price and at least 1 Prize Required - Level 1 must always be used). Each Prize can be a list of several prizes if you are awarding a bundle, but there will be a single drawing for each of the up to 5 Prizes defined below. If you put a list of prizes in one entry, they will all be awarded together at one time.', type: 'choice',required: false}, {name: 'rafflePrice1',type: 'int', minValue: 1, maxValue: 99999, label:'Raffle Level 1 Ticket Price (Required - at least one Level and Price must be defined)'}, {name: 'raffleLevel1Prize1',type: 'str',minLength: 1,maxLength: 100, label: 'Level 1 Prize 1 (Required - at least one Prize must be defined)'}, {name: 'raffleLevel1Prize2',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 1 Prize 2'}, {name: 'raffleLevel1Prize3',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 1 Prize 3'}, {name: 'raffleLevel1Prize4',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 1 Prize 4'}, {name: 'raffleLevel1Prize5',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 1 Prize 5'}, {name: 'dummyL2', label: '*********************** Level 2 ************************ Configure a price and up to 5 separate prizes that can be rewarded in the level 2 drawings. Each Prize can be a list of several prizes if you are awarding a bundle, but there will be a single drawing for each of the up to 5 Prizes defined below. If you put a list of prizes in one entry, they will all be awarded together at one time.', type: 'choice',required: false}, {name: 'rafflePrice2',type: 'int',minValue: 1,maxValue: 99999,required: false, label:'Raffle Level 2 Ticket Price. Leave blank if not using this level'}, {name: 'raffleLevel2Prize1',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 2 Prize 1'}, {name: 'raffleLevel2Prize2',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 2 Prize 2'}, {name: 'raffleLevel2Prize3',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 2 Prize 3'}, {name: 'raffleLevel2Prize4',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 2 Prize 4'}, {name: 'raffleLevel2Prize5',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 2 Prize 5'}, {name: 'dummyL3', label: '*********************** Level 3 ************************ Configure a price and up to 5 separate prizes that can be rewarded in the level 3 drawings. Each Prize can be a list of several prizes if you are awarding a bundle, but there will be a single drawing for each of the up to 5 Prizes defined below. If you put a list of prizes in one entry, they will all be awarded together at one time.', type: 'choice',required: false}, {name: 'rafflePrice3',type: 'int',minValue: 1,maxValue: 99999,required: false, label:'Raffle Level 3 Ticket Price. Leave blank if not using this level'}, {name: 'raffleLevel3Prize1',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 3 Prize 1'}, {name: 'raffleLevel3Prize2',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 3 Prize 2'}, {name: 'raffleLevel3Prize3',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 3 Prize 3'}, {name: 'raffleLevel3Prize4',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 3 Prize 4'}, {name: 'raffleLevel3Prize5',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 3 Prize 5'}, {name: 'dummyL4', label: '*********************** Level 4 ************************ Configure a price and up to 5 separate prizes that can be rewarded in the level 4 drawings. Each Prize can be a list of several prizes if you are awarding a bundle, but there will be a single drawing for each of the up to 5 Prizes defined below. If you put a list of prizes in one entry, they will all be awarded together at one time.', type: 'choice',required: false}, {name: 'rafflePrice4',type: 'int',minValue: 1,maxValue: 99999,required: false, label:'Raffle Level 4 Ticket Price. Leave blank if not using this level'}, {name: 'raffleLevel4Prize1',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 4 Prize 1'}, {name: 'raffleLevel4Prize2',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 4 Prize 2'}, {name: 'raffleLevel4Prize3',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 4 Prize 3'}, {name: 'raffleLevel4Prize4',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 4 Prize 4'}, {name: 'raffleLevel4Prize5',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 4 Prize 5'}, {name: 'dummyL5', label: '*********************** Level 5 ************************ Configure a price and up to 5 separate prizes that can be rewarded in the level 5 drawings. Each Prize can be a list of several prizes if you are awarding a bundle, but there will be a single drawing for each of the up to 5 Prizes defined below. If you put a list of prizes in one entry, they will all be awarded together at one time.', type: 'choice',required: false}, {name: 'rafflePrice5',type: 'int',minValue: 1,maxValue: 99999,required: false, label:'Raffle Level 5 Ticket Price. Leave blank if not using this level'}, {name: 'raffleLevel5Prize1',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 5 Prize 1'}, {name: 'raffleLevel5Prize2',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 5 Prize 2'}, {name: 'raffleLevel5Prize3',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 5 Prize 3'}, {name: 'raffleLevel5Prize4',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 5 Prize 4'}, {name: 'raffleLevel5Prize5',type: 'str',minLength: 1,maxLength: 100,required: false,label: 'Level 5 Prize 5'} ]; } { // *********************************** Variables and Arrays ************************************** var initialize = 0; var raffleToggle = 0; var raffleWhenDrawing = cb.settings.raffleWhenDrawing; var raffleAutoDrawing = cb.settings.raffleAutoDrawing; var raffleGoalTicketsSold = 0; var raffleTotalTicketsSold = 0; var raffleTotalTokens = 0; var raffleGoalTokens = 0; var raffleEndMode = ''; var newRaffleEndMode = ''; var raffleDrawingMode = ''; var newRaffleDrawingMode = ''; var raffleStartTime = 0; var raffleStopTime = 0; var raffleTimeAdded = 0; var raffleMinsRemain = 0; var raffleSecsRemain = 0; var previousRaffleLoaded = false; var raffleSkipMin = false; var raffleSkipSec = false; var raffleSkipNotice = false; var raffleTicketGoalAmt = cb.settings.raffleDrawingGoal; var raffleTipGoalAmt = cb.settings.raffleDrawingGoal; var raffleLevel1Active = false; var raffleLevel2Active = false; var raffleLevel3Active = false; var raffleLevel4Active = false; var raffleLevel5Active = false; var BC = cb.room_slug; var appNoticeColor = '#a2dfac'; // Used for general messaging from Raffle (green) var appWarningColor = '#f4d599'; // Used for general messaging from Raffle (yellow) var appAlertColor = '#f4c1bc'; // Used for general messaging from Raffle (red) var purple = '#e2a2ea'; var yellow = '#f4d599'; // Used for clock countdown var red = '#f4c1bc'; // Used for last 2 minutes of clock countdown var blue = '#0099ff'; var ticketStatsBgColor = '#e0e0e0'; // Light gray for ticket show stats background var dashLine80 = new Array(80).join('-'); var raffleLevel1Prize1 = cb.settings.raffleLevel1Prize1; var raffleLevel1Prize2 = cb.settings.raffleLevel1Prize2; var raffleLevel1Prize3 = cb.settings.raffleLevel1Prize3; var raffleLevel1Prize4 = cb.settings.raffleLevel1Prize4; var raffleLevel1Prize5 = cb.settings.raffleLevel1Prize5; var raffleLevel2Prize1 = cb.settings.raffleLevel2Prize1; var raffleLevel2Prize2 = cb.settings.raffleLevel2Prize2; var raffleLevel2Prize3 = cb.settings.raffleLevel2Prize3; var raffleLevel2Prize4 = cb.settings.raffleLevel2Prize4; var raffleLevel2Prize5 = cb.settings.raffleLevel2Prize5; var raffleLevel3Prize1 = cb.settings.raffleLevel3Prize1; var raffleLevel3Prize2 = cb.settings.raffleLevel3Prize2; var raffleLevel3Prize3 = cb.settings.raffleLevel3Prize3; var raffleLevel3Prize4 = cb.settings.raffleLevel3Prize4; var raffleLevel3Prize5 = cb.settings.raffleLevel3Prize5; var raffleLevel4Prize1 = cb.settings.raffleLevel4Prize1; var raffleLevel4Prize2 = cb.settings.raffleLevel4Prize2; var raffleLevel4Prize3 = cb.settings.raffleLevel4Prize3; var raffleLevel4Prize4 = cb.settings.raffleLevel4Prize4; var raffleLevel4Prize5 = cb.settings.raffleLevel4Prize5; var raffleLevel5Prize1 = cb.settings.raffleLevel5Prize1; var raffleLevel5Prize2 = cb.settings.raffleLevel5Prize2; var raffleLevel5Prize3 = cb.settings.raffleLevel5Prize3; var raffleLevel5Prize4 = cb.settings.raffleLevel5Prize4; var raffleLevel5Prize5 = cb.settings.raffleLevel5Prize5; // Arrays */ var rafflePrizeList1 = []; var rafflePrizeList2 = []; var rafflePrizeList3 = []; var rafflePrizeList4 = []; var rafflePrizeList5 = []; var raffleDrawingArray = []; var rafflePrevTicketsArray = {name: [], level: []}; var raffleCurrentTicketsArray = {name: [], level: []}; var raffleTicketsSoldLvl = []; var rafflePrice = []; } { // *********************************** Functions ************************************** { // Generic functions to set the color or separator characters function checkTextColor(color) { switch (color) { case 'White/No Color': return '#FFFFFF'; case 'Black': return '#000000'; case 'Dark Blue': return '#0629AC'; case 'Dark Pink': return '#FF6680'; case 'Dark Green': return '#006600'; case 'Dark Red': return '#cc0000'; case 'Dark Purple': return '#3d003d'; case 'Dark Grey': return '#737373'; case 'Dark Orange': return '#e77400'; case 'Dark Aqua': return '#006767'; default: if (/^#[0-9A-F]{6}$/i.test(color)) { return color; } else if (/^[0-9A-F]{6}$/i.test(color)) { return ('#' + color); } else { return ('default'); } } } function checkBgColor(color) { switch (color) { case 'White/No Color': return '#FFFFFF'; case 'Light Aqua': return '#adeaea'; case 'Light Pink': return '#FFE6EA'; case 'Light Green': return '#94e594'; case 'Light Red': return '#ff9a9a'; case 'Light Purple': return '#f2cdff'; case 'Light Orange': return '#ffd9b3'; case 'Light Grey': return '#e6e6e6'; case 'Light Blue': return '#d1eaee'; case 'Light Yellow': return '#ffff94' case 'Cream': return '#f9f6ed' default: if (/^#[0-9A-F]{6}$/i.test(color)) { return color; } else if (/^[0-9A-F]{6}$/i.test(color)) { return ('#' + color); } else { return ('default'); } } } function addRmvVIP(user, mode) { if (mode == 'a') { if (cbjs.arrayContains(VIPListArray,user)) { return; } else { VIPListArray.push(user); } } else if (mode == 'r') { if (cbjs.arrayContains(VIPListArray,user)) { cbjs.arrayRemove(VIPListArray,user); } else { return; } } } function addRmvExtFan(user, mode) { if (mode == 'a') { if (cbjs.arrayContains(extFanListArray,user)) { return; } else { extFanListArray.push(user); } } else if (mode == 'r') { if (cbjs.arrayContains(extFanListArray,user)) { cbjs.arrayRemove(extFanListArray,user); } else { return; } } } function populateVIPListArray(user) { if (!cbjs.arrayContains(VIPListArray, user)) VIPListArray.push(user); else return; } function populateExtFanListArray(user) { if (!cbjs.arrayContains(extFanListArray, user)) extFanListArray.push(user); else return; } // *********************************** Raffle Functions ************************************** function setRaffleToggle(option, mod) { if (option == 'on') { if (raffleToggle == 1) { cb.sendNotice('Raffle Sales are already enabled.', mod, appNoticeColor); } else { if (validateSetup()) { initRaffle(mod); cb.sendNotice('You have enabled Raffle Sales with a End Mode of ' + raffleWhenDrawing + ' and it will be ended by ' + raffleAutoDrawing + '. Available raffle help and commands can be seen by typing "/rhelp".', mod, appNoticeColor); } } } else if (option == 'off') { if (raffleToggle == 0) { cb.sendNotice('Raffle Sales are already disabled.', mod, appNoticeColor); } else { raffleToggle = 0; raffleSkipNotice = true; cb.sendNotice('You have disabled Raffle Sales.', mod, appNoticeColor); cb.sendNotice(' ' + mod + ' has disabled Raffle Sales. You can no longer tip to buy Raffle Tickets.', '', appNoticeColor,'','bold'); } } } function validateSetup() { if (rafflePrice[1] > 0) { if (rafflePrizeList1.length > 0) { raffleLevel1Active = true; } else { cb.sendNotice('Warning! Raffle Level 1 has a price defined, but no prizes! Level 1 will not be active!', cb.room_slug, appWarningColor, '', 'bold'); } } else if (rafflePrizeList1.length > 0) { cb.sendNotice('Warning! Raffle Level 1 has prizes defined, but no price! Level 1 will not be active!', cb.room_slug, appWarningColor, '', 'bold'); } if (rafflePrice[2] > 0) { if (rafflePrizeList2.length > 0) { if (rafflePrice.indexOf(rafflePrice[2]) !== rafflePrice.lastIndexOf(rafflePrice[2])) { cb.sendNotice('Warning! Raffle Level 2 has a duplicate Price Value! Level 2 will not be used!', cb.room_slug, appWarningColor, '', 'bold'); } else { raffleLevel2Active = true; } } else { cb.sendNotice('Warning! Raffle Level 2 has a price defined, but no prizes! Level 2 will not be active!', cb.room_slug, appWarningColor, '', 'bold'); } } else if (rafflePrizeList2.length > 0) { cb.sendNotice('Warning! Raffle Level 2 has prizes defined, but no price! Level 2 will not be active!', cb.room_slug, appWarningColor, '', 'bold'); } if (rafflePrice[3] > 0) { if (rafflePrizeList3.length > 0) { if (rafflePrice.indexOf(rafflePrice[3]) !== rafflePrice.lastIndexOf(rafflePrice[3])) { cb.sendNotice('Warning! Raffle Level 3 has a duplicate Price Value! Level 3 will not be used!', cb.room_slug, appWarningColor, '', 'bold'); } else { raffleLevel3Active = true; } } else { cb.sendNotice('Warning! Raffle Level 3 has a price defined, but no prizes! Level 3 will not be active!', cb.room_slug, appWarningColor, '', 'bold'); } } else if (rafflePrizeList3.length > 0) { cb.sendNotice('Warning! Raffle Level 3 has prizes defined, but no price! Level 3 will not be active!', cb.room_slug, appWarningColor, '', 'bold'); } if (rafflePrice[4] > 0) { if (rafflePrizeList4.length > 0) { if (rafflePrice.indexOf(rafflePrice[4]) !== rafflePrice.lastIndexOf(rafflePrice[4])) { cb.sendNotice('Warning! Raffle Level 4 has a duplicate Price Value! Level 4 will not be used!', cb.room_slug, appWarningColor, '', 'bold'); } else { raffleLevel4Active = true; } } else { cb.sendNotice('Warning! Raffle Level 4 has a price defined, but no prizes! Level 4 will not be active!', cb.room_slug, appWarningColor, '', 'bold'); } } else if (rafflePrizeList4.length > 0) { cb.sendNotice('Warning! Raffle Level 4 has prizes defined, but no price! Level 4 will not be active!', cb.room_slug, appWarningColor, '', 'bold'); } if (rafflePrice[5] > 0) { if (rafflePrizeList5.length > 0) { if (rafflePrice.indexOf(rafflePrice[5]) !== rafflePrice.lastIndexOf(rafflePrice[5])) { cb.sendNotice('Warning! Raffle Level 5 has a duplicate Price Value! Level 5 will not be used!', cb.room_slug, appWarningColor, '', 'bold'); } else { raffleLevel5Active = true; } } else { cb.sendNotice('Warning! Raffle Level 5 has a price defined, but no prizes! Level 5 will not be active!', cb.room_slug, appWarningColor, '', 'bold'); } } else if (rafflePrizeList5.length > 0) { cb.sendNotice('Warning! Raffle Level 5 has prizes defined, but no price! Level 5 will not be active!', cb.room_slug, appWarningColor, '', 'bold'); } if (!raffleLevel1Active && !raffleLevel2Active && !raffleLevel3Active && !raffleLevel4Active && !raffleLevel5Active) { cb.sendNotice('Error! There are no valid Prize levels defined!', cb.room_slug, appWarningColor, '', 'bold'); return false; } else { return true; } } function initRaffle(sendto) { raffleToggle = 1; raffleTextColor = checkTextColor('Dark Green'); raffleBgColor = checkBgColor('Cream'); raffleWinnerBgColor = checkBgColor('Light Yellow'); setRaffleMode('init',sendto); raffleSkipMin = false; raffleSkipSec = false; raffleSkipNotice = false; raffleNoticeTimer(); } function setRaffleMode(endmode,drawingmode,sendto) { if (endmode === 'init') { if (cb.settings.raffleWhenDrawing === 'Drawing at Broadcaster Discretion') { newRaffleEndMode = 'manual'; } else if (cb.settings.raffleWhenDrawing === 'Drawing after a Time Period') { newRaffleEndMode = 'timer'; } else if (cb.settings.raffleWhenDrawing === 'Drawing after a Ticket Goal') { newRaffleEndMode = 'ticketgoal'; } else if (cb.settings.raffleWhenDrawing === 'Drawing after a Token Goal') { newRaffleEndMode = 'tokengoal'; } if (cb.settings.raffleAutoDrawing === 'Broadcaster Performs Drawing') { newRaffleDrawingMode = 'bc'; } else if (cb.settings.raffleAutoDrawing === 'Automated Drawing') { newRaffleDrawingMode = 'auto'; } } else { if(endmode != '' && endmode != null) { newRaffleEndMode = endmode; } else { newRaffleEndMode = raffleEndMode; } if(drawingmode != '' && drawingmode != null) { newRaffleDrawingMode = drawingmode; } else { newRaffleDrawingMode = raffleDrawingMode; } } if (raffleEndMode === 'timer' && newRaffleEndMode != 'timer') { stopRaffleTimer(sendto); } if (newRaffleEndMode === 'manual') { raffleEndMode = 'manual'; raffleDrawingMode = 'bc'; cb.sendNotice('Raffle drawing mode is set to "Broadcaster Discretion", the raffle drawing will occur when the Broadcaster chooses.','', raffleBgColor, raffleTextColor, 'bold'); } else if (newRaffleEndMode === 'timer') { if (cb.settings.raffleDrawingInterval >= 1) { raffleEndMode = 'timer'; raffleTimeAmt = cb.settings.raffleDrawingInterval; if (newRaffleDrawingMode === 'auto') { raffleAutoTimer(raffleTimeAmt); raffleDrawingMode = 'auto'; cb.sendNotice('Raffle drawing mode is set to "Automatic timer" with a duration of ' + raffleTimeAmt + ' minutes. The drawing will be performed automatically when the timer runs out.','', raffleBgColor, raffleTextColor, 'bold'); } else { raffleDrawingMode = 'bc'; cb.sendNotice('Raffle drawing mode is set to "Broadcaster managed timer". The Broadcaster will set a timer and perform the drawing when the timer runs out.','', raffleBgColor, raffleTextColor, 'bold'); } } else { raffleEndMode = 'manual'; raffleDrawingMode = 'bc'; cb.sendNotice('Raffle drawing is set to manual mode/broadcaster discretion. Mode was requested for automatic timer, but the timer length was not set on the start page. You can restart the bot and update the missing time, or continue and start a manual timer. You can use the command /raffledrawing at the end of the timer, see help details on the how to use the command.', sendto, appNoticeColor); } } else if (newRaffleEndMode === 'ticketgoal') { if (cb.settings.raffleDrawingGoal >= 1) { raffleEndMode = 'ticketgoal'; raffleTicketGoalAmt = cb.settings.raffleDrawingGoal; if (newRaffleDrawingMode === 'auto') { raffleDrawingMode = 'auto'; cb.sendNotice('Raffle drawing mode is set to "Automatic at ticket goal". There will be a short 2 minute countdown started once the goal is met for number of tickets sold (' + raffleTicketGoalAmt + ' tickets), and then the drawing will be performed automatically.','', raffleBgColor, raffleTextColor, 'bold'); } else { raffleDrawingMode = 'bc'; cb.sendNotice('Raffle drawing mode is set to "Broadcaster managed ticket goal". The Broadcaster will perform the drawing once the goal is met for number of tickets sold (' + raffleTicketGoalAmt + ' tickets).','', raffleBgColor, raffleTextColor, 'bold'); } } else { raffleEndMode = 'manual'; raffleDrawingMode = 'bc'; cb.sendNotice('Raffle drawing is set to manual mode. Mode was requested for automatic goal start, but the goal was not set on the start page. You can restart the bot and update the missing goal, update the ticket goal using the command "/chgrafflegoal [amt]" and then change the mode using "/chgrafflemode ticketgoal", or continue and start the show manually at the end of a timer or at a time of your choosing.', sendto, appNoticeColor); } } else if (newRaffleEndMode === 'tokengoal') { if (cb.settings.raffleDrawingGoal >= 1) { raffleEndMode = 'tokengoal'; raffleTipGoalAmt = cb.settings.raffleDrawingGoal; if (newRaffleDrawingMode === 'auto') { raffleDrawingMode = 'auto'; cb.sendNotice('Raffle drawing mode is set to "Automatic at token goal". There will be a short 2 minute countdown started once the goal is met for total tip amount (' + raffleTipGoalAmt + ' tokens), and then the drawing will be performed automatically.','', raffleBgColor, raffleTextColor, 'bold'); } else { raffleDrawingMode = 'bc'; cb.sendNotice('Raffle drawing mode is set to "Broadcaster managed token goal". The Broadcaster will perform the drawing once the goal is met for total tip amount (' + raffleTipGoalAmt + ' tokens).','', raffleBgColor, raffleTextColor, 'bold'); } } else { raffleEndMode = 'manual'; raffleDrawingMode = 'bc'; cb.sendNotice('Raffle drawing is set to manual mode. Mode was requested for automatic goal start, but the goal was not set on the start page. You can restart the bot and update the missing goal, update the ticket goal using the command "/chgrafflegoal [amt]" and then change the mode using "/chgrafflemode tokengoal", or continue and start the show manually at the end of a timer or at a time of your choosing.', sendto, appNoticeColor); } } } function loadPrevRaffleResults(sendto) { if (cb.settings.raffleTicketList != '' && cb.settings.raffleTicketList != null) { var n = cb.settings.raffleTicketList; temprafflearray = n.split(','); if (temprafflearray.length > 0) { entriesloaded = false; for (var i = 0; i < temprafflearray.length; i++) { raffleentries = temprafflearray[i].split(':'); if (raffleentries[0] == '' || raffleentries[0] == null || raffleentries[1] == '' || raffleentries[1] == null) { cb.sendNotice('Cannot load previous raffle ticket list entry "' + temprafflearray[i] + '", invalid formatting within entry.', sendto, appNoticeColor); } else { rafflePrevTicketsArray.name.push(raffleentries[0]); rafflePrevTicketsArray.level.push(raffleentries[1]); raffleCurrentTicketsArray.name.push(raffleentries[0]); raffleCurrentTicketsArray.level.push(raffleentries[1]); entriesloaded = true; for (var j = 1; j <= 5; j++) { if (raffleentries[1] == j) { raffleTicketsSoldLvl[j]++; raffleGoalTicketsSold++; raffleTotalTicketsSold++; raffleTotalTokens += rafflePrice[j]; raffleGoalTokens += rafflePrice[j]; break; } } } } if (entriesloaded) { cb.sendNotice('Previous Raffle List Load Completed.', sendto, appNoticeColor); } } else { cb.sendNotice('Cannot load previous raffle ticket list, invalid formatting of list: ' + temprafflearray, sendto, appNoticeColor); } } } function raffleNoticeTimer() { if (raffleToggle == 1) { if (!raffleSkipNotice) { cb.sendNotice(cb.settings.raffleNoticeText, '', ticketStatsBgColor,'','bold'); if (raffleEndMode === 'ticketgoal') { cb.sendNotice('Raffle End Mode: Ticket Goal\n Progress: ' + raffleGoalTicketsSold + ' / ' + raffleTicketGoalAmt + ' tickets', '', ticketStatsBgColor,'','bold'); } else if (raffleEndMode === 'tokengoal') { cb.sendNotice('Raffle End Mode: Token Goal\n Progress: ' + raffleGoalTokens + ' / ' + raffleTipGoalAmt + ' tokens', '', ticketStatsBgColor,'','bold'); } else if (raffleEndMode === 'timer') { if (raffleMinsRemain > 0 || raffleSecsRemain > 0) { cb.sendNotice('Raffle End Mode: Timer\n ' + raffleTimeLeft(), '', ticketStatsBgColor,'','bold'); } else { cb.sendNotice('Raffle End Mode: Timer (not running)', '', ticketStatsBgColor,'','bold'); } } else { cb.sendNotice('Raffle End Mode: Broadcaster Choice', '', ticketStatsBgColor,'','bold'); } if (raffleLevel1Active) { cb.sendNotice('Raffle Level 1 - ', '', ticketStatsBgColor,'','bold'); cb.sendNotice('...Ticket Price: ' + rafflePrice[1] + ' tokens', '', ticketStatsBgColor); cb.sendNotice('...Tickets Sold: ' + raffleTicketsSoldLvl[1], '', ticketStatsBgColor); cb.sendNotice('...Prize' + (rafflePrizeList1.length > 1 ? 's' : '') + ': ' + cbjs.arrayJoin(rafflePrizeList1, ' :: '), '', ticketStatsBgColor); } if (raffleLevel2Active) { cb.sendNotice('Raffle Level 2 - ', '', ticketStatsBgColor,'','bold'); cb.sendNotice('...Ticket Price: ' + rafflePrice[2] + ' tokens', '', ticketStatsBgColor); cb.sendNotice('...Tickets Sold: ' + raffleTicketsSoldLvl[2], '', ticketStatsBgColor); cb.sendNotice('...Prize' + (rafflePrizeList2.length > 1 ? 's' : '') + ': ' + cbjs.arrayJoin(rafflePrizeList2, ' :: '), '', ticketStatsBgColor); } if (raffleLevel3Active) { cb.sendNotice('Raffle Level 3 - ', '', ticketStatsBgColor,'','bold'); cb.sendNotice('...Ticket Price: ' + rafflePrice[3] + ' tokens', '', ticketStatsBgColor); cb.sendNotice('...Tickets Sold: ' + raffleTicketsSoldLvl[3], '', ticketStatsBgColor); cb.sendNotice('...Prize' + (rafflePrizeList3.length > 1 ? 's' : '') + ': ' + cbjs.arrayJoin(rafflePrizeList3, ' :: '), '', ticketStatsBgColor); } if (raffleLevel4Active) { cb.sendNotice('Raffle Level 4 - ', '', ticketStatsBgColor,'','bold'); cb.sendNotice('...Ticket Price: ' + rafflePrice[4] + ' tokens', '', ticketStatsBgColor); cb.sendNotice('...Tickets Sold: ' + raffleTicketsSoldLvl[4], '', ticketStatsBgColor); cb.sendNotice('...Prize' + (rafflePrizeList4.length > 1 ? 's' : '') + ': ' + cbjs.arrayJoin(rafflePrizeList4, ' :: '), '', ticketStatsBgColor); } if (raffleLevel5Active) { cb.sendNotice('Raffle Level 5 - ', '', ticketStatsBgColor,'','bold'); cb.sendNotice('...Ticket Price: ' + rafflePrice[5] + ' tokens', '', ticketStatsBgColor); cb.sendNotice('...Tickets Sold: ' + raffleTicketsSoldLvl[5], '', ticketStatsBgColor); cb.sendNotice('...Prize' + (rafflePrizeList5.length > 1 ? 's' : '') + ': ' + cbjs.arrayJoin(rafflePrizeList5, ' :: '), '', ticketStatsBgColor); } cb.setTimeout(raffleNoticeTimer, cb.settings.raffleNoticeInterval * 60000); } else { raffleSkipNotice = false; } } } function raffleTicketPurchase(buylevel,buyuser,buyamount) { raffleCurrentTicketsArray.name.push(buyuser); raffleCurrentTicketsArray.level.push(buylevel); checkTipGoalStartRaffle(buyamount,buylevel); checkTicketGoalStartRaffle(buyamount,buylevel); } function checkTipGoalStartRaffle(amount,level) { raffleTotalTokens += amount; raffleGoalTokens += amount; if (raffleEndMode === 'tokengoal' && raffleGoalTokens == raffleTipGoalAmt) { if (raffleDrawingMode === 'auto') { cb.sendNotice(dashLine80 + '\n *The raffle goal has been met!! Starting a 2 minute timer for automatic drawing!\n' + dashLine80,'', raffleBgColor, raffleTextColor, 'bold'); raffleEndMode = 'timer'; raffleAutoTimer(2); } else if (raffleDrawingMode === 'bc') { cb.sendNotice(dashLine80 + '\n *The raffle goal has been met!! The Broadcaster will now perform a drawing for the raffle prize(s)!\n' + dashLine80,'', raffleBgColor, raffleTextColor, 'bold'); } } } function checkTicketGoalStartRaffle(amount,level) { raffleGoalTicketsSold++; raffleTotalTicketsSold++; raffleTicketsSoldLvl[level]++; if (raffleEndMode === 'ticketgoal' && raffleGoalTicketsSold == raffleTicketGoalAmt) { if (raffleDrawingMode === 'auto') { cb.sendNotice(dashLine80 + '\n *The raffle goal has been met!! Starting a 2 minute timer for automatic drawing!\n' + dashLine80,'', raffleBgColor, raffleTextColor, 'bold'); raffleEndMode = 'timer'; raffleAutoTimer(2); } else if (raffleDrawingMode === 'bc') { cb.sendNotice(dashLine80 + '\n *The raffle goal has been met!! The Broadcaster will now perform a drawing for the raffle prize(s)!\n' + dashLine80,'', raffleBgColor, raffleTextColor, 'bold'); } } } function raffleAutoTimer(addtime) { if (raffleDrawingMode === 'auto') { cb.sendNotice('An automatic timer was started for the raffle drawing.', '', raffleBgColor, raffleTextColor, 'bold'); } else if (raffleDrawingMode === 'bc') { cb.sendNotice('A timer was started for the raffle drawing, the Broadcaster will trigger the drawing after the timer runs out.', '', raffleBgColor, raffleTextColor, 'bold'); } raffleMinsRemain = addtime; raffleSecsRemain = 0; raffleStartTime = new Date(); raffleStopTime = new Date(raffleStartTime.getTime() + raffleMinsRemain * 60000); raffleTimerMin(); } function raffleTimerMin() { raffleSeconds = raffleCheckMin(); if (raffleSkipMin === false && raffleEndMode === 'timer' && raffleToggle == 1 && (raffleSeconds >= 55 || raffleSeconds == 0)) { switch (raffleMinsRemain) { case 120: case 90: case 60: case 45: case 30: case 20: case 15: case 10: case 9: case 8: case 7: case 6: case 5: case 4: case 3: case 2: cb.sendNotice('\u23f1 \u23f1 \u23f1 There are ' + raffleMinsRemain + ' minutes left on the timer to buy a raffle ticket before the drawing takes place! \u23f1 \u23f1 \u23f1', '', appWarningColor, '', 'bold'); } raffleMinsRemain--; if (raffleMinsRemain > 0) { cb.setTimeout(raffleTimerMin, 60000); } else { raffleSecsRemain = 60; cb.sendNotice('\u23f1 \u23f1 \u23f1 There is 1 minute left on the timer to buy a raffle ticket before the drawing takes place!! \u23f1 \u23f1 \u23f1', '', red, '', 'bold'); raffleTimerSec(); } } else { if (raffleSkipMin === true) { raffleSkipMin = false; } } } function raffleCheckMin() { var raffleTimeLeft = raffleTimeCal(); var raffleMS = raffleTimeLeft % 1000; var raffleSeconds = ((raffleTimeLeft - raffleMS) % 60000); raffleSeconds = raffleSeconds / 1000; return raffleSeconds; } function raffleTimerSec() { if (!raffleSkipSec && raffleEndMode === 'timer' && raffleToggle == 1) { if (raffleMinsRemain > 0) { cb.setTimeout(raffleTimerMin, raffleSecsRemain*1000); } else { raffleSecsRemain--; winner = false; if (raffleSecsRemain < 1) { cb.sendNotice('\u23f0 \u23f0 \u23f0 Time is up! Raffle Drawing now! \u23f0 \u23f0 \u23f0', '', raffleBgColor, raffleTextColor, 'bold'); if (raffleEndMode === 'timer' && raffleDrawingMode === 'auto') { selectAllRaffleWinners('The Automatic Timer'); winner = true; } } else { switch (raffleSecsRemain) { case 30: case 10: case 5: case 4: case 3: case 2: case 1: cb.sendNotice('\u23f1 \u23f1 \u23f1 There ' + (raffleSecsRemain == 1 ? 'is ' : 'are ') + raffleSecsRemain + ' second' + (raffleSecsRemain == 1 ? '' : 's') + ' left! \u23f1 \u23f1 \u23f1', '', red, '', 'bold'); } } if (raffleSecsRemain > 0 && !winner) { cb.setTimeout(raffleTimerSec, 1000); } } } else { raffleSkipSec = false; } } function raffleAddTime(raffletimetoadd, u) { raffleStopTime = new Date(raffleStopTime.getTime() + raffletimetoadd * 60000); if (raffletimetoadd < 0) { cb.sendNotice(u + ' has subtracted ' + Math.abs(raffletimetoadd) + ' minute' + (raffletimetoadd === 1 || raffletimetoadd === -1 ? '' : 's') + ' from the raffle drawing timer.',cb.room_slug,'','', 'bold'); cb.sendNotice(Math.abs(raffletimetoadd) + ' minute' + (raffletimetoadd === 1 || raffletimetoadd === -1 ? ' has' : 's have') + ' been subtracted from the raffle drawing timer. Now ' + raffleTimeLeft(),'',appWarningColor,'', 'bold'); } else { cb.sendNotice(u + ' has added ' + raffletimetoadd + ' minute' + (raffletimetoadd === 1 || raffletimetoadd === -1 ? '' : 's') + ' to the raffle drawing timer.',cb.room_slug,'','', 'bold'); cb.sendNotice(raffletimetoadd + ' minute' + (raffletimetoadd === 1 || raffletimetoadd === -1 ? ' has' : 's have') + ' been added to the raffle drawing timer. Now ' + raffleTimeLeft(),'',appWarningColor,'', 'bold'); } raffleMinsRemain = raffleMinsRemain + raffletimetoadd; if (raffleMinsRemain < 1) { raffleSkipMin = true; raffleTimeLeft = raffleTimeCal(); raffleMS = raffleTimeLeft % 1000; raffleSeconds = ((raffleTimeLeft - raffleMS) % 60000) / 1000; raffleSecsRemain = raffleSeconds; raffleTimerSec(); } } function raffleTimeCal() { raffleStartTime = new Date(); return raffleStopTime - raffleStartTime.getTime(); } function stopRaffleTimer(mod) { raffleStopTime = new Date(); raffleSkipNotice = true; if (raffleMinsRemain > 0 || raffleSecsRemain > 0) { raffleSkipMin = true; raffleSkipSec = true; } raffleMinsRemain = 0; raffleSecsRemain = 0; if(mod != null) { cb.sendNotice(mod + ' has stopped the raffle drawing timer.','',appWarningColor,'', 'bold'); } } function raffleTimeLeft(user) { var raffleTimeLeft = raffleTimeCal(); var raffleMS = raffleTimeLeft % 1000; var raffleSeconds = ((raffleTimeLeft - raffleMS) % 60000); var raffleMinutes = ((raffleTimeLeft - raffleSeconds - raffleMS) % 3600000); raffleSeconds = raffleSeconds / 1000; raffleMinutes = raffleMinutes / 60000; if (raffleMinutes > 0 && raffleSeconds == 0) { return raffleMinutes + ' minute' + (raffleMinutes > 1 ? 's' : '') + ' remaining on the raffle drawing timer.'; } else if (raffleMinutes > 0) { return raffleMinutes + ' minute' + (raffleMinutes > 1 ? 's' : '') + ' and ' + raffleSeconds + ' second' + (raffleSeconds > 1 ? 's' : '') + ' remaining on the raffle drawing timer.'; } else { return raffleSeconds + ' second' + (raffleSeconds > 1 ? 's' : '') + ' remaining on the raffle drawing timer.'; } } function selectAllRaffleWinners(drawingby) { levelcompleted = false; if (raffleLevel1Active) { if (checkRaffleDrawingArray(1)) { selectSingleRaffleWinner(1,drawingby); levelcompleted = true; } } if (raffleLevel2Active) { if (checkRaffleDrawingArray(2)) { selectSingleRaffleWinner(2,drawingby); levelcompleted = true; } } if (raffleLevel3Active) { if (checkRaffleDrawingArray(3)) { selectSingleRaffleWinner(3,drawingby); levelcompleted = true; } } if (raffleLevel4Active) { if (checkRaffleDrawingArray(4)) { selectSingleRaffleWinner(4,drawingby); levelcompleted = true; } } if (raffleLevel5Active) { if (checkRaffleDrawingArray(5)) { selectSingleRaffleWinner(5,drawingby); levelcompleted = true; } } if (cb.settings.raffleContinuous == 'Continuous') { if (cb.settings.raffleResetCycle == 'Yes') { clearRaffleEntries('all',drawingby); } else { clearRaffleEntries('resume',drawingby); } resumeRaffle(drawingby); } else { if (levelcompleted) { cb.sendNotice('The Raffle Drawing has been performed for all levels (levels with no tickets sold were skipped) and the Raffle is now Over!!! Thank you to everyone who bought a ticket!', '', raffleBgColor, raffleTextColor, 'bold'); stopRaffleTimer(); setRaffleToggle('off',drawingby); } else { cb.sendNotice('There were no tickets sold for any of the active raffle levels, drawing not performed.', '', raffleBgColor, raffleTextColor, 'bold'); } } } function resumeRaffle(drawingby) { setRaffleMode('init',drawingby); raffleSkipMin = false; raffleSkipSec = false; raffleSkipNotice = false; } function selectSingleRaffleWinner(level,drawingby) { raffleDrawingArray = []; buildRaffleDrawingArray(level); if (raffleDrawingArray.length > 0) { maxPrizes = raffleDrawingArray.length; if (level == 1) { if (rafflePrizeList1.length <= maxPrizes) { maxPrizes = rafflePrizeList1.length; } else { cb.sendNotice('There are fewer raffle tickets available (' + raffleDrawingArray.length + ') than prizes (' + rafflePrizeList1.length + ') for level ' + level + ', only rewarding prizes for the number of tickets sold.', '', raffleBgColor,raffleTextColor,'bold'); } for (var i = 0; i < maxPrizes; i++) { rafflePrize = rafflePrizeList1[i]; raffleAnnounceWinner(level,rafflePrize,drawingby); } if (cb.settings.raffleContinuous == 'Single Drawing') { raffleLevel1Active = false; } } else if (level == 2) { if (rafflePrizeList2.length <= maxPrizes) { maxPrizes = rafflePrizeList2.length; } else { cb.sendNotice('There are fewer raffle tickets available (' + raffleDrawingArray.length + ') than prizes (' + rafflePrizeList2.length + ') for level ' + level + ', only rewarding prizes for the number of tickets sold.', '', raffleBgColor,raffleTextColor,'bold'); } for (var i = 0; i < maxPrizes; i++) { rafflePrize = rafflePrizeList2[i]; raffleAnnounceWinner(level,rafflePrize,drawingby); } if (cb.settings.raffleContinuous == 'Single Drawing') { raffleLevel2Active = false; } } else if (level == 3) { if (rafflePrizeList3.length <= maxPrizes) { maxPrizes = rafflePrizeList3.length; } else { cb.sendNotice('There are fewer raffle tickets available (' + raffleDrawingArray.length + ') than prizes (' + rafflePrizeList3.length + ') for level ' + level + ', only rewarding prizes for the number of tickets sold.', '', raffleBgColor,raffleTextColor,'bold'); } for (var i = 0; i < maxPrizes; i++) { rafflePrize = rafflePrizeList3[i]; raffleAnnounceWinner(level,rafflePrize,drawingby); } if (cb.settings.raffleContinuous == 'Single Drawing') { raffleLevel3Active = false; } } else if (level == 4) { if (rafflePrizeList4.length <= maxPrizes) { maxPrizes = rafflePrizeList4.length; } else { cb.sendNotice('There are fewer raffle tickets available (' + raffleDrawingArray.length + ') than prizes (' + rafflePrizeList4.length + ') for level ' + level + ', only rewarding prizes for the number of tickets sold.', '', raffleBgColor,raffleTextColor,'bold'); } for (var i = 0; i < maxPrizes; i++) { rafflePrize = rafflePrizeList4[i]; raffleAnnounceWinner(level,rafflePrize,drawingby); } if (cb.settings.raffleContinuous == 'Single Drawing') { raffleLevel4Active = false; } } else if (level == 5) { if (rafflePrizeList5.length <= maxPrizes) { maxPrizes = rafflePrizeList5.length; } else { cb.sendNotice('There are fewer raffle tickets available (' + raffleDrawingArray.length + ') than prizes (' + rafflePrizeList5.length + ') for level ' + level + ', only rewarding prizes for the number of tickets sold.', '', raffleBgColor,raffleTextColor,'bold'); } for (var i = 0; i < maxPrizes; i++) { rafflePrize = rafflePrizeList5[i]; raffleAnnounceWinner(level,rafflePrize,drawingby); } if (cb.settings.raffleContinuous == 'Single Drawing') { raffleLevel5Active = false; } } if (cb.settings.raffleContinuous == 'Single Drawing') { if (!raffleLevel1Active && !raffleLevel2Active && !raffleLevel3Active && !raffleLevel4Active && !raffleLevel5Active) { setRaffleToggle('off',drawingby); } } } else { cb.sendNotice('Cannot perform drawing for Level ' + level + ', there are no raffle tickets purchased for this level.', '', raffleBgColor,raffleTextColor,'bold'); } } function checkRaffleDrawingArray(level) { for (var j = 0; j < raffleCurrentTicketsArray.name.length; j++) { if (raffleCurrentTicketsArray.level[j] == level) { return true; } } cb.sendNotice('Cannot perform drawing for Level ' + level + ', there are no raffle tickets purchased for this level.', '', raffleBgColor,raffleTextColor,'bold'); return false; } function buildRaffleDrawingArray(level) { for (var j = 0; j < raffleCurrentTicketsArray.name.length; j++) { if (raffleCurrentTicketsArray.level[j] == level) { raffleDrawingArray.push(raffleCurrentTicketsArray.name[j]); } } } function raffleAnnounceWinner(level,rafflePrize,drawingby) { cb.sendNotice('Raffle Level ' + level + ': ' + drawingby + ' is drawing a winner for the prize of ' + rafflePrize + '...', '', raffleBgColor,raffleTextColor,'bold'); totalEntries = raffleDrawingArray.length; raffleWinnerIndex = Math.floor(Math.random() * totalEntries); if(raffleWinnerIndex > (raffleDrawingArray.length - 1)) { raffleWinnerIndex = (raffleDrawingArray.length - 1); } raffleWinner = raffleDrawingArray[raffleWinnerIndex]; cb.sendNotice(':raffleticket :WINNER', '', raffleBgColor,raffleTextColor,'bold'); cb.sendNotice('Congratulations!!! ' + raffleWinner + ' has won ' + rafflePrize + '!', '', raffleWinnerBgColor,raffleTextColor,'bold'); removeWinner(level,raffleWinner); } function removeWinner(level,raffleWinner) { drawingIndex = raffleDrawingArray.indexOf(raffleWinner); raffleDrawingArray.splice(drawingIndex,1); for (var j = 0; j < raffleCurrentTicketsArray.name.length; j++) { if (raffleCurrentTicketsArray.level[j] == level && raffleCurrentTicketsArray.name[j] == raffleWinner) { raffleCurrentTicketsArray.name.splice(j,1); raffleCurrentTicketsArray.level.splice(j,1); break; } } } function removeTicket(level,user) { for (var j = 0; j < raffleCurrentTicketsArray.name.length; j++) { if (raffleCurrentTicketsArray.level[j] == level && raffleCurrentTicketsArray.name[j] == user) { raffleCurrentTicketsArray.name.splice(j,1); raffleCurrentTicketsArray.level.splice(j,1); raffleGoalTicketsSold--; raffleTotalTicketsSold--; raffleTicketsSoldLvl[level]--; break; } } } function displayEntries(sendto) { var outString = 'Listing of Raffle entries (Combines Previous Show Sales and Current Sales) is below.'; outString += '\nCopy this list as it is displayed and paste it into the field for previous ticket holders on the start page:\n'; for (var i = 0; i < raffleCurrentTicketsArray.name.length; i++) { if (raffleCurrentTicketsArray.name[i] == null) { break } else { outString += (i > 0 ? ',' : '') + raffleCurrentTicketsArray.name[i] + ':' + raffleCurrentTicketsArray.level[i]; } } outString += '\nEnd of List'; cb.sendNotice(outString, sendto, appNoticeColor); } function clearRaffleEntries(mode,by) { if (mode === 'all') { cb.sendNotice('The raffle ticket list has been cleared. In case this was done in error, the current list is printed below, and can be added back if needed.', cb.room_slug, appNoticeColor); displayEntries(cb.room_slug); if (by != cb.room_slug) { cb.sendNotice('The raffle ticket list has been cleared, and a backup list has been displayed to the broadcaster.', by, appNoticeColor); } raffleCurrentTicketsArray.name.length = 0; raffleCurrentTicketsArray.level.length = 0; for (var j = 1; j <= 5; j++) { raffleTicketsSoldLvl[j] = 0; } } raffleGoalTicketsSold = 0; raffleGoalTokens = 0; } // *********************************** Help Function ************************************** function helpCommon(from) { cb.sendNotice('Dorothy\'s Raffle Bot Help Menu', from, appNoticeColor); cb.sendNotice('',from,appNoticeColor); cb.sendNotice( '/reply [msg]: If a moderator or broadcaster PMs you in the chat, you can use the command /reply [msg] to send a message back to the last person that PMd you.' + '\n/tipmenu: Display the tip menu at any time in the chat, only to the user that requests it.' + '\n/posmenu: Display the positions tip menu at any time in the chat, only to the user that requests it.' + '\n/timeleft: Display the time left on a timed countdown clock.' + '\n/leaders: Display the tip leaderboard at any time in the chat, only to the user that requests it.' + '\n/poll: Display the current results of the token poll at any time in the chat, only to the user that requests it.' + '\n/wordlist: Display the blocked word list at any time in the chat, only to the user that requests it.' + '\n/lushmenu: Display the interactive toy tip menu at any time in the chat, only to the user that requests it.' + '\n/media: Display the broadcaster media list at any time in the chat, only to the user that requests it.' + '\n/top10 (or /alltimetop10, or /dsptop10): Display a listing of the top 10 all time tippers. Sent to the user that requested, unless requested by moderator or broadcaster, then sent to all. This list is presented in the same format as the notice, not in the format needed to paste into the previous show totals field on the launch page (use the "/alltime" command for that).' + '\n/prizes: Display the dice game prizes menu at any time in the chat, only to the user that requests it.' ,from); cb.sendNotice('',from,appNoticeColor); } function helpModBC(from) { cb.sendNotice('Raffle Bot Command List',from,appNoticeColor); cb.sendNotice( '\n/raffle [on/off]: (mods/bc only) Toggle the setting for whether the Raffle Feature is "on" or "off". Overrides the initial setting, and allows you to turn the Raffle on or off during the show. Note that turning the raffle off will suspend the display of the notice, and tips will no longer buy a ticket, however, the ticket purchase history is kept until the Raffle Bot is restarted.' + '\n/entries (or /raffletickets, or /raffleentries): (mods/bc only) Display the list of raffle ticket entries in a format that can be pasted directly into the bot launch page "previous show" raffle list. As noted above, this must be done to track ticket purchases between shows, or restarts of the Raffle Bot.' + '\n/previousentries : (mods/bc only) Display the same list of previous ticket purchases that was specified when launching the bot, mainly for informational purposes if there is a question of what was bought in previous shows vs the current total list.' + '\n/resetraffle (or /clearraffle): (bc only) Delete all raffle ticket purchase history and start a new raffle with the existing settings. Obviously be careful using this command as you will lose all outstanding tickets. It will display a list of ticket holders in the chat for the broadcaster in case this is done by mistake, the list could be put back in.' + '\n/addraffle [level] [user]: (bc only) Manually add a user to the specified ticket purchase level. The synatx would be "/addraffle 2 john" to give user name john a ticket for the level 2 drawing.' + '\n/rmvraffle [level] [user]: (bc only) Manually remove a user from the specified ticket purchase level. The synatx would be "/rmvraffle 2 john" to remove the ticket for user name john for the level 2 drawing. Note that it will only remove the first occurrence of that user ticket for that level, the command must be executed multiple times if they have multiple tickets.' + '\n/raffleprizes: (all users) Display the available prizes in the Raffle, by level, only shown to the user that requests it.' + '\n/setraffleprice [level] [newprice]: (mods/bc only) Change the price of Level 2 raffle tickets, where [newprice] is the new price to use. ' + '\n/raffledrawing: (bc, mods when configured) Perform the raffle drawing when not set to Automatic Drawing mode. The winners from each level will be chosen and displayed in the chat. Note that the winner history is not tracked, so you must distribute the prizes or make note of the winners as they are shown in the chat. If continuous mode is selected, the goals are reset and the next cycle is started, which may clear the ticket pool if configured to do so in continuous mode.' + '\n/rafflestarttimer (or /startraffletimer) [time]: (mods/bc only) Start a [time] minute timer for the raffle drawing when in "timer" mode with the drawing to be triggered by the /raffledrawing command. The timer will count down but not automatically perform the drawing (unless set to automatic mode but the auto-timer was ended, and this is a restart of that timer)' + '\n/raffleaddtime (or /addraffletime) [time]: (mods/bc only) Add [time] minutes to the timer for either automatic or manual drawing mode. The [time] value can be a negative number to subtract time, but cannot be greater than the remaining time.' + '\n/rafflestoptimer (or /stopraffletimer): (mods/bc only) Stop the raffle timer for either automatic or manual drawing mode.' + '\n/raffletimeleft : (mods/bc only) Display the time left on the raffle timer for either automatic or manual drawing mode.' + '\n/chgrafflemode [manual/timer/ticketgoal/tokengoal]: (mods/bc only) Switch between the modes being used to determine when to perform the raffle drawing. If switching from a timer show to a non-timer show, the timer will be ended. Ticket count and Tip Count are being tracked regardless of mode, so switching to a "goal" mode should not require starting progress at 0.' + '\n/addraffleprize [level] [prize]: (mods/bc only) Add a raffle prize to the specified [level] (1-5) with a description of [prize].' + '\n/rmvraffleprize [level] [prize]: (mods/bc only) Remove the specified raffle [prize] from the specified [level] (1-5), the text must match the existing prize exactly (case and punctuation).' ,from); cb.sendNotice('',from,appNoticeColor); } } } // ******************************* Upon user entry of a Message ************************************** { cb.onMessage(function (msg) { var message = msg['m'].split(' '); var cmd = 0; var m = msg.m; var u = msg.user; var isMod = msg.is_mod; var isBC = (u === 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; switch(command) { case '/raffle': { cmd = 1; if (isMod || isBC) { if(message[1] == null || message[1] == '') { cb.sendNotice('You did not enter a valid option for /raffle, the option should be "on" or "off".', u, appNoticeColor); } else if (message[1] != 'on' && message[1] != 'off') { cb.sendNotice(message[1] + ' is not a valid option for /raffle, the option should be "on" or "off".', u, appNoticeColor); } else { setRaffleToggle(message[1], u); } } else { cb.sendNotice('Only moderators and broadcasters are able to use that command.', u, appNoticeColor); } break; } case '/resetraffle': case '/clearraffle': { cmd = 1; if (isBC) { if (raffleToggle == 1) { clearRaffleEntries('all',u); } else { cb.sendNotice('The Raffle feature has not been turned on, you can use the command "/raffle on" to enable it.', u, appNoticeColor); } } else { cb.sendNotice('Only broadcasters are able to use that command.', u, appNoticeColor); } break; } case '/addraffletkt1': case '/addraffletkt2': case '/addraffletkt3': case '/addraffletkt4': case '/addraffletkt5': { cmd = 1; if (isBC) { if (raffleToggle == 1) { rlevel = message[0].substring(13).trim(); numtickets = parseInt(message[1]); adduser = message[2]; if (isNaN(numtickets)) { cb.sendNotice('The value entered for the Number of tickets is not numeric, please try again. The syntax for this command is "/addraffletktL [level] [user]" where "L" is the level, and both the number of tickets and user must be populated. The value for L for level must be from 1-5.', u, appNoticeColor); } else if (!message[2]) { cb.sendNotice('The value for user was not provided, please try again. The syntax for this command is "/addraffletktL [level] [user]" where "L" is the level, and both the number of tickets and user must be populated. The value for L for level must be from 1-5.', u, appNoticeColor); } else if (rafflePrice[rlevel] == null || rafflePrice[rlevel] <= 0) { cb.sendNotice('Level ' + rlevel + ' has not been configured as a valid level in the current raffle.', u, appNoticeColor); } else { for (let i = 1; i <= numtickets; i++) { raffleTicketPurchase(rlevel,adduser,0); } cb.sendNotice('You have manually added ' + numtickets + ' raffle tickets for level ' + rlevel + ' for user "' + adduser + '".', u, appNoticeColor); } } else { cb.sendNotice('The raffle is not enabled, you can use the command "/raffle on" to enable it.', u, appNoticeColor); } } else { cb.sendNotice('Only broadcasters are able to use that command.', u, appNoticeColor); } break; } case '/rmvraffletkt': { cmd = 1; if (isBC) { if (raffleToggle == 1) { level = parseInt(message[1]); rmvuser = message[2]; if (isNaN(level)) { cb.sendNotice('The value entered for the Level is not numeric, please try again. The syntax for this command is "/rmvraffletkt [level] [user]" and both level and user must be populated, and level must be from 1-5.', u, appNoticeColor); } else if (level < 1 || level > 500) { cb.sendNotice('The value entered for the Level is outside allowable values from 1 to 5, please try again. The syntax for this command is "/rmvraffletkt [level] [user]" and both level and user must be populated, and level must be from 1-5.', u, appNoticeColor); } else if (!message[2]) { cb.sendNotice('The value for user was not provided, please try again. The syntax for this command is "/rmvraffletkt [level] [user]" and both level and user must be populated, and level must be from 1-5.', u, appNoticeColor); } else { removeTicket(level,rmvuser); cb.sendNotice('One level ' + level + ' raffle ticket removed for ' + rmvuser + '.', u, appNoticeColor); } } else { cb.sendNotice('The raffle is not enabled, you can use the command "/raffle on" to enable it.', u, appNoticeColor); } } else { cb.sendNotice('Only broadcasters are able to use that command.', u, appNoticeColor); } break; } case '/setraffleprice': { cmd = 1; if (isMod || isBC) { level = parseInt(message[1]); numtokens = parseInt(message[2]); if (isNaN(level) || level < 1 || level > 5) { cb.sendNotice('The first parameter is the level and must be a number between 1 and 5. For example, use "/setraffleprice 2 18" to change the price of raffle level 2 ticket to 18 tokens.', u, appNoticeColor); } else if (isNaN(numtokens) || numtokens < 1 || numtokens > 500) { cb.sendNotice('The value entered for the new Level ' + level + ' Raffle Ticket Price is outside allowable values from 1 to 500, please try again. For example, use "/setraffleprice 2 18" to change the price of raffle level 2 ticket to 18 tokens.', u, appNoticeColor); } else { rafflePrice[level] = numtokens; priceChecker('add','Raffle Price ' + level,rafflePrice[level]); cb.sendNotice('You have updated the Level ' + level + ' Raffle Ticket Price to ' + numtokens + ' tokens.', u, appNoticeColor); cb.sendNotice(u + ' updated the raffle price for Level ' + commandVar1 + ' to ' + numtokens + '.', '', appNoticeColor, '', '', 'red'); cb.sendNotice(u + ' updated the raffle price for Level ' + commandVar1 + ' to ' + numtokens + '.', cb.room_slug, appNoticeColor); } } else { cb.sendNotice('Only moderators and broadcasters are able to use that command.', u, appNoticeColor); } break; } case '/addraffleprize': { cmd = 1; if (isMod || isBC) { if (isNaN(commandVar1) || commandVar1 < 1 || commandVar1 > 5) { cb.sendNotice('The first parameter is the level and must be a number between 1 and 5. For example, "/addraffleprize 2 Free Video" to add a level 2 raffle prize of a free video', u, appNoticeColor); } else if (!rafflePrice[commandVar1] > 0) { cb.sendNotice('The level ' + commandVar1 + ' raffle price has not yet been set, please set the price first using the command "/setraffleprice ' + commandVar1 + ' [amt]"', u, appNoticeColor); } else if (!message[2]) { cb.sendNotice('The second parameter is the description of prize being added (can be multiple words) and is required. For example, "/addraffleprize 2 Free Video" to add a level 2 raffle prize of a free video', u, appNoticeColor); } else { for (let i = 2; i < message.length; i++) { if (i === 2) { label = message[i]; } else { label += ' ' + message[i]; } } switch (commandVar1) { case 1: { rafflePrizeList1.push(label); break; } case 2: { rafflePrizeList2.push(label); break; } case 3: { rafflePrizeList3.push(label); break; } case 4: { rafflePrizeList4.push(label); break; } case 5: { rafflePrizeList5.push(label); break; } cb.sendNotice('Raffle Prize "' + label + '" was added to Raffle Level ' + commandVar1 + '.', u, appNoticeColor); cb.sendNotice(u + ' added Raffle Prize "' + label + '" to Raffle Level ' + commandVar1 + '.', '', appNoticeColor, '', '', 'red'); cb.sendNotice(u + ' added Raffle Prize "' + label + '" to Raffle Level ' + commandVar1 + '.', cb.room_slug, appNoticeColor); } } } else { cb.sendNotice('Only broadcasters and moderators are able to use that command.', u, appNoticeColor); } break; } case '/rmvraffleprize': { cmd = 1; if (isMod || isBC) { if (isNaN(commandVar1) || commandVar1 < 1 || commandVar1 > 5) { cb.sendNotice('The first parameter is the level and must be a number between 1 and 5. For example, use "/rmvraffleprize 2 Free Video" to remove an existing level 2 raffle prize named "Free Video"', u, appNoticeColor); } else if (!message[2]) { cb.sendNotice('The second parameter is the description of prize being remove (must match the text of the prize being removed exactly) and is required. For example, use "/rmvraffleprize 2 Free Video" to remove an existing level 2 raffle prize named "Free Video"', u, appNoticeColor); } else { for (let i = 2; i < message.length; i++) { if (i === 2) { label = message[i]; } else { label += ' ' + message[i]; } } switch (commandVar1) { case 1: { let labelFound = false; for (let i = 0; i < rafflePrizeList1.length; i++) { if (label === rafflePrizeList1[i]) { labelFound = true; while (label === rafflePrizeList1[i]) { rafflePrizeList1.splice(i,1); cb.sendNotice('Raffle prize "' + label + '" was removed from Raffle Level ' + commandVar1 + '.', u, appNoticeColor); cb.sendNotice(u + ' removed Raffle Prize "' + label + '" from Raffle Level ' + commandVar1 + '.', '', appNoticeColor, '', '', 'red'); cb.sendNotice(u + ' removed Raffle Prize "' + label + '" from Raffle Level ' + commandVar1 + '.', cb.room_slug, appNoticeColor); } } } if (!labelFound) { cb.sendNotice('Unable find item "' + label + '" in the raffle list for level ' + commandVar1 + '.', u, appNoticeColor); } break; } case 2: { let labelFound = false; for (let i = 0; i < rafflePrizeList2.length; i++) { if (label === rafflePrizeList2[i]) { labelFound = true; while (label === rafflePrizeList1[i]) { rafflePrizeList1.splice(i,1); cb.sendNotice('Raffle prize "' + label + '" was removed from Raffle Level ' + commandVar1 + '.', u, appNoticeColor); cb.sendNotice(u + ' removed Raffle Prize "' + label + '" from Raffle Level ' + commandVar1 + '.', '', appNoticeColor, '', '', 'red'); cb.sendNotice(u + ' removed Raffle Prize "' + label + '" from Raffle Level ' + commandVar1 + '.', cb.room_slug, appNoticeColor); } } } if (!labelFound) { cb.sendNotice('Unable find item "' + label + '" in the raffle list for level ' + commandVar1 + '.', u, appNoticeColor); } break; } case 3: { let labelFound = false; for (let i = 0; i < rafflePrizeList3.length; i++) { if (label === rafflePrizeList3[i]) { labelFound = true; while (label === rafflePrizeList1[i]) { rafflePrizeList1.splice(i,1); cb.sendNotice('Raffle prize "' + label + '" was removed from Raffle Level ' + commandVar1 + '.', u, appNoticeColor); cb.sendNotice(u + ' removed Raffle Prize "' + label + '" from Raffle Level ' + commandVar1 + '.', '', appNoticeColor, '', '', 'red'); cb.sendNotice(u + ' removed Raffle Prize "' + label + '" from Raffle Level ' + commandVar1 + '.', cb.room_slug, appNoticeColor); } } } if (!labelFound) { cb.sendNotice('Unable find item "' + label + '" in the raffle list for level ' + commandVar1 + '.', u, appNoticeColor); } break; } case 4: { let labelFound = false; for (let i = 0; i < rafflePrizeList4.length; i++) { if (label === rafflePrizeList4[i]) { labelFound = true; while (label === rafflePrizeList1[i]) { rafflePrizeList1.splice(i,1); cb.sendNotice('Raffle prize "' + label + '" was removed from Raffle Level ' + commandVar1 + '.', u, appNoticeColor); cb.sendNotice(u + ' removed Raffle Prize "' + label + '" from Raffle Level ' + commandVar1 + '.', '', appNoticeColor, '', '', 'red'); cb.sendNotice(u + ' removed Raffle Prize "' + label + '" from Raffle Level ' + commandVar1 + '.', cb.room_slug, appNoticeColor); } } } if (!labelFound) { cb.sendNotice('Unable find item "' + label + '" in the raffle list for level ' + commandVar1 + '.', u, appNoticeColor); } break; } case 5: { let labelFound = false; for (let i = 0; i < rafflePrizeList5.length; i++) { if (label === rafflePrizeList5[i]) { labelFound = true; while (label === rafflePrizeList1[i]) { rafflePrizeList1.splice(i,1); cb.sendNotice('Raffle prize "' + label + '" was removed from Raffle Level ' + commandVar1 + '.', u, appNoticeColor); cb.sendNotice(u + ' removed Raffle Prize "' + label + '" from Raffle Level ' + commandVar1 + '.', '', appNoticeColor, '', '', 'red'); cb.sendNotice(u + ' removed Raffle Prize "' + label + '" from Raffle Level ' + commandVar1 + '.', cb.room_slug, appNoticeColor); } } } if (!labelFound) { cb.sendNotice('Unable find item "' + label + '" in the raffle list for level ' + commandVar1 + '.', u, appNoticeColor); } break; } } } } else { cb.sendNotice('Only broadcasters and moderators are able to use that command.', u, appNoticeColor); } break; } case '/entries': case '/raffletickets': case '/raffleentries': { cmd = 1; if (isMod || isBC) { if (raffleCurrentTicketsArray.name.length > 0) { displayEntries(u); } else { cb.sendNotice('No entries in the raffle yet.', u, appNoticeColor); } } else { cb.sendNotice('Only moderators and broadcasters are able to use that command.', u, appNoticeColor); } break; } case '/previousentries': { cmd = 1; if (isMod || isBC) { if (rafflePrevTicketsArray.name.length > 0) { cb.sendNotice('Listing of Previous Show Raffle entries : ', u, appNoticeColor); outString = ''; for (var i = 0; i < rafflePrevTicketsArray.name.length; i++) { if (rafflePrevTicketsArray.name[i] == null) { break } else { outString += (i > 0 ? ',' : '') + rafflePrevTicketsArray.name[i] + ':' + rafflePrevTicketsArray.level[i]; } } cb.sendNotice(outString, u); cb.sendNotice('End of List', u, appNoticeColor); } else { cb.sendNotice('No previous entries were imported in the raffle.', u, appNoticeColor); } } else { cb.sendNotice('Only moderators and broadcasters are able to use that command.', u, appNoticeColor); } break; } case '/raffleprizes': { cmd = 1; outString = 'Listing of Raffle Prizes by Level : '; if (raffleLevel1Active && rafflePrizeList1.length > 0) { outString += '\nLevel 1 (ticket price = ' + rafflePrice[1] + ' tokens) -- '; for (var pindex = 0; pindex < rafflePrizeList1.length; pindex++) { if (rafflePrizeList1[pindex]) { outString += '\nPrize #' + (pindex+1) + ': ' + rafflePrizeList1[pindex]; } else { break; } } } else { outString += '\nNo prize(s) or invalid setup for level 1.'; } if (raffleLevel2Active && rafflePrizeList2.length > 0) { outString += '\nLevel 2 (ticket price = ' + rafflePrice[2] + ' tokens) -- '; for (var pindex = 0; pindex < rafflePrizeList2.length; pindex++) { if (rafflePrizeList2[pindex]) { outString += '\nPrize #' + (pindex+1) + ': ' + rafflePrizeList2[pindex]; } else { break; } } } else { outString += '\nNo prize(s) or invalid setup for level 2.'; } if (raffleLevel3Active && rafflePrizeList3.length > 0) { outString += '\nLevel 3 (ticket price = ' + rafflePrice[3] + ' tokens) -- '; for (var pindex = 0; pindex < rafflePrizeList3.length; pindex++) { if (rafflePrizeList3[pindex]) { outString += '\nPrize #' + (pindex+1) + ': ' + rafflePrizeList3[pindex]; } else { break; } } } else { outString += '\nNo prize(s) or invalid setup for level 3.'; } if (raffleLevel4Active && rafflePrizeList4.length > 0) { outString += '\nLevel 4 (ticket price = ' + rafflePrice[4] + ' tokens) -- '; for (var pindex = 0; pindex < rafflePrizeList4.length; pindex++) { if (rafflePrizeList4[pindex]) { outString += '\nPrize #' + (pindex+1) + ': ' + rafflePrizeList4[pindex]; } else { break; } } } else { outString += '\nNo prize(s) or invalid setup for level 4.'; } if (raffleLevel5Active && rafflePrizeList5.length > 0) { outString += '\nLevel 5 (ticket price = ' + rafflePrice[5] + ' tokens) -- '; for (var pindex = 0; pindex < rafflePrizeList5.length; pindex++) { if (rafflePrizeList5[pindex]) { outString += '\nPrize #' + (pindex+1) + ': ' + rafflePrizeList5[pindex]; } else { break; } } } else { outString += '\nNo prize(s) or invalid setup for level 5.'; } cb.sendNotice(outString, u, appNoticeColor); break; } case '/raffledrawing': { cmd = 1; if (isBC || (isMod && cb.settings.raffleModDrawing == 'Yes')) { rdlevel = parseInt(message[1]); if (!message[1]) { cb.sendNotice('This command requires a parameter to define what level to perform the drawing for. You can use a value of "all" for all levels, or a specific level number. For example "/raffledrawing all" or "/raffledrawing 1".', u, appNoticeColor); } else if (message[1].toLowerCase() == 'all') { selectAllRaffleWinners(u); } else if (rdlevel == 1 && !raffleLevel1Active) { cb.sendNotice('Raffle Level 1 is not currently active. It either was not setup with a price and at least one prize, or the drawing has already been completed.', u, appNoticeColor); } else if (rdlevel == 2 && !raffleLevel2Active) { cb.sendNotice('Raffle Level 2 is not currently active. It either was not setup with a price and at least one prize, or the drawing has already been completed.', u, appNoticeColor); } else if (rdlevel == 3 && !raffleLevel3Active) { cb.sendNotice('Raffle Level 3 is not currently active. It either was not setup with a price and at least one prize, or the drawing has already been completed.', u, appNoticeColor); } else if (rdlevel == 4 && !raffleLevel4Active) { cb.sendNotice('Raffle Level 4 is not currently active. It either was not setup with a price and at least one prize, or the drawing has already been completed.', u, appNoticeColor); } else if (rdlevel == 5 && !raffleLevel5Active) { cb.sendNotice('Raffle Level 5 is not currently active. It either was not setup with a price and at least one prize, or the drawing has already been completed.', u, appNoticeColor); } else if (rdlevel >= 1 && rdlevel <= 5) { selectSingleRaffleWinner(rdlevel,u); } else { cb.sendNotice('Invalid value entered for the level to perform the drawing for. The parameter value should be "all" for all levels, or a specific level number. For example "/raffledrawing all" or "/raffledrawing 1".', u, appNoticeColor); } } else { cb.sendNotice('Only broadcasters and moderators with privileges are able to use that command.', u, appNoticeColor); } break; } case '/raffledrawing1': case '/raffledrawing2': case '/raffledrawing3': case '/raffledrawing4': case '/raffledrawing5': { cmd = 1; if (isBC || (isMod && cb.settings.raffleModDrawing == 'Yes')) { rlevel = msg['m'].substring(14).trim(); selectSingleRaffleWinner(rlevel,u); } else { cb.sendNotice('Only broadcasters and moderators with privileges are able to use that command.', u, appNoticeColor); } break; } case '/rafflestarttimer': case '/startraffletimer': { cmd = 1; if (raffleToggle == 1) { if (isMod || isBC) { if (raffleEndMode == 'timer') { numtimer = parseInt(message[1]) if(isNaN(numtimer)) { cb.sendNotice('The value entered for the minutes to use for the raffle drawing timer is not numeric, please try again.', u, appNoticeColor); } else if(numtimer < 1 || numtimer > 120) { cb.sendNotice('The value entered for the minutes to use for the raffle drawing timer is outside allowable values from 1 to 120 (up to 2 hrs), please try again.', u, appNoticeColor); } else if(raffleMinsRemain > 0 || raffleSecsRemain > 0) { cb.sendNotice('A raffle timer is already running.', u, appNoticeColor); } else { raffleMinsRemain = numtimer; raffleAutoTimer(raffleMinsRemain); } } else { cb.sendNotice('Cannot start a timer unelss the end mode is "timer".', u, appNoticeColor); } } else { cb.sendNotice('Only moderators and broadcasters are able to use that command.', u, appNoticeColor); } } else { cb.sendNotice('The raffle feature is disabled.', u, appNoticeColor); } break; } case '/addraffletime': case '/raffleaddtime': { cmd = 1; if (raffleToggle == 1) { if (isMod || isBC) { if (raffleEndMode == 'timer') { numtimer = parseInt(message[1]); if (isNaN(numtimer)) { cb.sendNotice('The value entered for the minutes to add to the raffle drawing timer is not numeric, please try again.', u, appNoticeColor); break; } else if (numtimer < -60 || numtimer > 60) { cb.sendNotice('The value entered for the minutes to add to the raffle drawing timer is outside allowable values from -60 to 60, please try again. Negative numbers can be used to subtract time.', u, appNoticeColor); } else if (numtimer == 0) { cb.sendNotice('Cannot add zero time.', u, appNoticeColor); } else if (numtimer < 0 && Math.abs(numtimer) > raffleMinsRemain) { cb.sendNotice('The value entered for the minutes to subtract is greater than the remaining timeon the timer, please try again. Negative numbers can be used to subtract time.', u, appNoticeColor); } else { raffleAddTime(numtimer, u); } } else { cb.sendNotice('Cannot perform timer functions when end mode is not "timer".', u, appNoticeColor); } } else { cb.sendNotice('Only moderators and broadcasters are able to use that command.', u, appNoticeColor); } } else { cb.sendNotice('The raffle feature is disabled.', u, appNoticeColor); } break; } case '/rafflestoptimer': case '/stopraffletimer': { cmd = 1; if (raffleToggle == 1) { if (isMod || isBC) { if (raffleEndMode == 'timer') { stopRaffleTimer(u); } else { cb.sendNotice('Cannot perform timer functions when end mode is not "timer".', u, appNoticeColor); } } else { cb.sendNotice('Only moderators and broadcasters are able to use that command.', u, appNoticeColor); } } else { cb.sendNotice('The raffle feature is disabled.', u, appNoticeColor); } break; } case '/chgrafflemode': { cmd = 1; if (isMod || isBC) { if (raffleToggle == 1) { newRaffleEndMode = message[1].toLowerCase(); if (newRaffleEndMode != 'manual' && newRaffleEndMode != 'timer' && newRaffleEndMode != 'ticketgoal' && newRaffleEndMode != 'tokengoal') { cb.sendNotice('The value entered for the new mode is not valid, please try again using a value of "manual", "timer", "ticketgoal", or "tokengoal".', u, appNoticeColor); } else { if (newRaffleEndMode === raffleEndMode) { cb.sendNotice('The value entered for the new mode is the same as the existing mode, command ignored.', u, appNoticeColor); } else { setRaffleMode(newRaffleEndMode,u); } } } else { cb.sendNotice('The raffle feature is disabled.',u,appNoticeColor); } } else { cb.sendNotice('Only moderators and broadcasters are able to use that command.', u, appNoticeColor); } break; } case '/raffletimeleft': { cmd = 1; if (raffleToggle == 1) { if (raffleMinsRemain >= 1 || raffleSecsRemain >= 1) { cb.sendNotice(raffleTimeLeft(), '', appWarningColor, '', 'bold'); } else { cb.sendNotice('A raffle drawing timer is not running.', u, appNoticeColor); } } else { cb.sendNotice('The raffle feature is disabled.',u,appNoticeColor); } break; } //********* Help Menu case '/rhelp': { cmd = 1; if (isMod || isBC) { helpModBC(u); } else { helpCommon(u); } break; } } } }); } // *********************************** Actions on user entering ************************************** { cb.onEnter(function(user) { var onEnterUser = user.user; if (user.has_tokens) { if (raffleToggle == 1) { temptextcolor = checkTextColor('Dark Green'); tempbgcolor = checkBgColor('Cream'); cb.sendNotice('\u21E8 A raffle is running today, the recurring notice will provide info on raffle ticket prices and the prize list, or you can use the command "/raffleprizes" to display the list at any time.', onEnterUser, tempbgcolor, temptextcolor, 'bold'); } } }); } // *********************************** Actions upon tipping ************************************** { cb.onTip(function (tip) { var tipAmount = Number.parseInt(tip.amount, 10); var onTipUser = tip.from_user if (raffleToggle == 1) { if (cb.settings.raffleTipMultiple == 'Yes') { for (var lvlindex = 1; lvlindex <= 5; lvlindex++) { if (tipAmount % rafflePrice[lvlindex] == 0) { if (this['raffleLevel'+lvlindex+'Active']) { var numberOfTickets = Math.floor(parseInt(tip['amount']) / rafflePrice[lvlindex]); for (var j = 0; j < numberOfTickets; j++) { raffleTicketPurchase(lvlindex,onTipUser,rafflePrice[lvlindex]) } cb.sendNotice(onTipUser + ' has bought ' + (numberOfTickets > 1 ? numberOfTickets : 'a') + ' Level ' + lvlindex + ' Raffle Ticket' + (numberOfTickets > 1 ? 's' : '') + '!', '', raffleBgColor, raffleTextColor, 'bold'); break; } else { cb.sendNotice('Thank you for tipping, raffle tickets for prize level ' + lvlindex + ' are not enabled or are no longer being sold.', onTipUser, raffleBgColor, raffleTextColor, 'bold'); } } } } else { for (var lvlindex = 1; lvlindex <= 5; lvlindex++) { if (rafflePrice[lvlindex] > 0 && tipAmount == rafflePrice[lvlindex]) { if (this['raffleLevel'+lvlindex+'Active']) { raffleTicketPurchase(lvlindex,onTipUser,tipAmount); cb.sendNotice(onTipUser + ' has bought a Level ' + lvlindex + ' Raffle Ticket!', '', raffleBgColor, raffleTextColor, 'bold'); break; } else { cb.sendNotice('Thank you for tipping, raffle tickets for prize level ' + lvlindex + ' are not enabled or are no longer being sold.', onTipUser, raffleBgColor, raffleTextColor, 'bold'); } } } } } }); } // *********************************** Initialize ************************************** { if (initialize == 0) { intromessage = 'Dorothys Raffle Bot v1.0'; intromessage += '** Version 1.1 was released on 12/20/2019.'; intromessage += '\nYou can type "/rhelp" to display the command list summary.'; cb.sendNotice(intromessage, cb.room_slug, red); raffleTicketsSoldLvl[1] = 0; raffleTicketsSoldLvl[2] = 0; raffleTicketsSoldLvl[3] = 0; raffleTicketsSoldLvl[4] = 0; raffleTicketsSoldLvl[5] = 0; rafflePrice[1] = cb.settings.rafflePrice1; rafflePrice[2] = cb.settings.rafflePrice2; rafflePrice[3] = cb.settings.rafflePrice3; rafflePrice[4] = cb.settings.rafflePrice4; rafflePrice[5] = cb.settings.rafflePrice5; if (rafflePrice[5] > 0 && (rafflePrice.indexOf(rafflePrice[5]) !== rafflePrice.lastIndexOf(rafflePrice[5]))) { cb.sendNotice('Warning! Raffle Level 5 has a duplicate Price Value! Level 5 will not be used!', cb.room_slug, appWarningColor, '', 'bold'); } else if (rafflePrice[4] > 0 && (rafflePrice.indexOf(rafflePrice[4]) !== rafflePrice.lastIndexOf(rafflePrice[4]))) { cb.sendNotice('Warning! Raffle Level 4 has a duplicate Price Value! Level 4 will not be used!', cb.room_slug, appWarningColor, '', 'bold'); } else if (rafflePrice[3] > 0 && (rafflePrice.indexOf(rafflePrice[3]) !== rafflePrice.lastIndexOf(rafflePrice[3]))) { cb.sendNotice('Warning! Raffle Level 3 has a duplicate Price Value! Level 3 will not be used!', cb.room_slug, appWarningColor, '', 'bold'); } else if (rafflePrice[2] > 0 && (rafflePrice.indexOf(rafflePrice[2]) !== rafflePrice.lastIndexOf(rafflePrice[2]))) { cb.sendNotice('Warning! Raffle Level 2 has a duplicate Price Value! Level 2 will not be used!', cb.room_slug, appWarningColor, '', 'bold'); } loadPrevRaffleResults(cb.room_slug); currentlevel = 0; for (let levelindex = 1; levelindex <= 5; levelindex++) { for (let prizeindex = 1; prizeindex <= 5; prizeindex++) { prize = this['raffleLevel'+levelindex+'Prize'+prizeindex]; if (prize) { this['rafflePrizeList'+levelindex].push(prize); if (currentlevel != levelindex) { currentlevel = levelindex; } } } } initialize = 1; } }
© Copyright Chaturbate 2011- 2024. All Rights Reserved.