Bots Home
|
Create an App
moloh_loto_bot
Author:
molohlove
Description
Source Code
Launch Bot
Current Users
Created by:
Molohlove
cb.settings_choices = [ {label:'Ticket Price', name: 'ticket_price', type: 'int', minValue: 1, default: 7}, {label:'Starting Prize', name: 'start_val', type: 'int', minValue: 1, default: 1000}, {label:'Cat 4 - 3 winning Nr %', name: 'cat4', type: 'int', minValue: 1, maxValue:50, default: 3}, {label:'Cat 3 - 4 winning Nr %', name: 'cat3', type: 'int', minValue: 1, maxValue:50, default: 5}, {label:'Cat 2 - 5 winning Nr %', name: 'cat2', type: 'int', minValue: 1, maxValue:70, default: 10}, {label:'Cat 1 - 6 winning Nr %', name: 'cat1', type: 'int', minValue: 1, maxValue:100, default: 20}, {label:'Prizes Notification(mins)', name: 'not1', type: 'int', minValue: 1, maxValue:100, default: 5}, {label:'Jackpot Notification(mins)', name: 'not2', type: 'int', minValue: 1, maxValue:100, default: 5} ]; var displayCatNameArr = new Object(); displayCatNameArr[3] = 4; displayCatNameArr[4] = 3; displayCatNameArr[5] = 2; displayCatNameArr[6] = 1; var calculatePrizes = 0; var ticketsArr = new Object(); var winArr = new Object(); var winnersArr = new Object(); var winCatArr = new Object(); var winnersPerCatArr = new Object(); var totalPrizeVal = cb.settings['start_val']; var repeatTime = cb.settings['not1'] * 1000 * 60; var repeatTimeJackpot = cb.settings['not2'] * 1000 * 60; var cat4P = cb.settings['cat4']; var cat3P = cb.settings['cat3']; var cat2P = cb.settings['cat2']; var cat1P = cb.settings['cat1']; var cat4Val, cat3Val, cat2Val, cat1Val; var cat4Prize, cat3Prize, cat2Prize, cat1Prize; cb.onTip(function (tip) { if(tip['amount'] == cb.settings['ticket_price']) buy_ticket(tip); }); cb.onMessage(function (msg) { if (msg['user'] == cb.room_slug && msg['m'].match(/\/draw/i)) draw_rizes(); if (msg['user'] == cb.room_slug && msg['m'].match(/\/pot/i)) show_pot(); if(msg['m'].match(/\/tickets/i)) show_tickets(msg); if(msg['m'].match(/\/prizes/i)) show_prizes(msg); }); function buy_ticket(tip){ calculate_prizes(tip['amount']); if(typeof ticketsArr[tip['from_user']] === 'undefined' || !ticketsArr[tip['from_user']]) ticketsArr[tip['from_user']] = new Object(); var randArr = new Object(); while(Object.keys(randArr).length < 6){ var newNr = Math.floor((Math.random() * 49) + 1); if(inArray(newNr, randArr) == false) randArr[Object.keys(randArr).length] = newNr; } ticketsArr[tip['from_user']][Object.keys(ticketsArr[tip['from_user']]).length] = randArr; var ticketText = ''; for(i = 0; i < 6; i++) ticketText += randArr[i]+'_'; cb.sendNotice('User '+tip['from_user']+' bought 1 lottery ticket.', '', '#b6b409'); cb.sendNotice('May the odds be always in your favor! Your ticket numbers are: ' + ticketText, tip['from_user'], '#b6b409'); } function show_tickets(msg) { if(typeof ticketsArr[msg['user']] === 'undefined' || !ticketsArr[msg['user']]){ cb.sendNotice('You don\'t have any tickets...', msg['user']); } else { var nrTickets = Object.keys(ticketsArr[msg['user']]).length; cb.sendNotice('You have '+nrTickets+' tickets. Get more to increase your chances.', msg['user']); for(i = 0; i < nrTickets; i++){ var ticketText = ''; for(j = 0; j < 6; j++) ticketText += ticketsArr[msg['user']][i][j]+'_'; cb.sendNotice(ticketText, msg['user']); } } } function show_prizes(msg){ cb.sendNotice('1 ticket = '+cb.settings['ticket_price']+' tokens. More tickets = more chances.', msg['user'], '#b6b409'); cb.sendNotice('6/49 Prize list:', msg['user'], '#b6b409'); cb.sendNotice('Cat 1: '+cat1Val+' tokens. To win you need 6 correct numbers', msg['user'], '#b6b409'); cb.sendNotice('Cat 2: '+cat2Val+' tokens. To win you need 5 correct numbers', msg['user'], '#b6b409'); cb.sendNotice('Cat 3: '+cat3Val+' tokens. To win you need 4 correct numbers', msg['user'], '#b6b409'); cb.sendNotice('Cat 4: '+cat4Val+' tokens. To win you need 3 correct numbers', msg['user'], '#b6b409'); cb.sendNotice('type /tickets to see your tickets and numbers', msg['user'], '#b6b409'); } function calculate_prizes(tipVal) { if(typeof tipVal !== 'undefined' || tipVal) totalPrizeVal += tipVal; cat4Val = Math.round(cat4P * totalPrizeVal / 100); cat3Val = Math.round(cat3P * totalPrizeVal / 100); cat2Val = Math.round(cat2P * totalPrizeVal / 100); cat1Val = Math.round(cat1P * totalPrizeVal / 100); } function send_room_notification(){ if(calculatePrizes == 0) { cb.sendNotice('1 ticket = '+cb.settings['ticket_price']+' tokens. More tickets = more chances.', '', '#b6b409'); cb.sendNotice('6/49 Prize list:', '', '#b6b409'); cb.sendNotice('Cat 1: '+cat1Val+' tokens. To win you need 6 correct numbers', '', '#b6b409'); cb.sendNotice('Cat 2: '+cat2Val+' tokens. To win you need 5 correct numbers', '', '#b6b409'); cb.sendNotice('Cat 3: '+cat3Val+' tokens. To win you need 4 correct numbers', '', '#b6b409'); cb.sendNotice('Cat 4: '+cat4Val+' tokens. To win you need 3 correct numbers', '', '#b6b409'); cb.sendNotice('type /tickets to see your tickets and numbers', '', '#b6b409'); cb.sendNotice('More info on BIO', '', '#b6b409'); cb.setTimeout(send_room_notification, repeatTime); } } function send_jackpot_notification(){ cb.sendNotice('Current pot: '+totalPrizeVal+' tokens worth. More tickets more chances.', '', '#b6b409'); cb.setTimeout(send_jackpot_notification, repeatTimeJackpot); } function show_pot(){ cb.sendNotice('Current pot: '+totalPrizeVal+' tokens worth. More tickets more chances.', '', '#b6b409'); } function inArray(needle,haystack) { var count = Object.keys(haystack).length; for(var i=0; i < count; i++) if(haystack[i] === needle) return true; return false; } function draw_rizes() { if(Object.keys(ticketsArr).length >= 1){ if(Object.keys(winArr).length == 6){ var ticketText = ''; for(j = 0; j < 6; j++) ticketText += winArr[j]+'_'; cb.sendNotice('You already drew the winning numbers. You must restart the app to play again.', cb.room_slug); cb.sendNotice('The winning numbers are: ' + ticketText); } else { while(Object.keys(winArr).length < 6){ var newNr = Math.floor((Math.random() * 49) + 1); if(inArray(newNr, winArr) == false) winArr[Object.keys(winArr).length] = newNr; } var ticketText = ''; for(j = 0; j < 6; j++) ticketText += winArr[j]+'_'; cb.sendNotice('The winning numbers are: ' + ticketText,'', '#b6b409'); } show_winners(winArr); } else { cb.sendNotice('There are no tickets, so there is no point to draw a winning number yet.', cb.room_slug); } } function show_winners(winArr) { var winNr; var k; winnersArr = new Object(); winCatArr = new Object(); winnersPerCatArr = new Object(); for(var userName in ticketsArr) { for(i = 0; i < Object.keys(ticketsArr[userName]).length; i++) { for(j = 0; j < 6; j++) { if(inArray(winArr[j], ticketsArr[userName][i]) == true){ if(typeof winnersArr[userName] === 'undefined' || !winnersArr[userName]) winnersArr[userName] = new Object(); if(typeof winnersArr[userName][i] === 'undefined' || !winnersArr[userName][i]) winnersArr[userName][i] = 0; winnersArr[userName][i]++; } } } } winCatArr[1] = 0; winCatArr[2] = 0; winCatArr[3] = 0; winCatArr[4] = 0; winCatArr[5] = 0; winCatArr[6] = 0; for(var userName in winnersArr) { for(key in winnersArr[userName]){ winCatArr[winnersArr[userName][key]]++; if(winnersArr[userName][key] == 3 || winnersArr[userName][key] == 4 || winnersArr[userName][key] == 5 || winnersArr[userName][key] == 6 ){ if(typeof winnersPerCatArr[winnersArr[userName][key]] === 'undefined' || !winnersPerCatArr[winnersArr[userName][key]]) winnersPerCatArr[winnersArr[userName][key]] = new Object(); if(typeof winnersPerCatArr[winnersArr[userName][key]][userName] === 'undefined' || !winnersPerCatArr[winnersArr[userName][key]][userName]) winnersPerCatArr[winnersArr[userName][key]][userName] = 0; winnersPerCatArr[winnersArr[userName][key]][userName]++; } } } if( winCatArr[3] != 0 ) cat4Prize = Math.round(cat4Val / winCatArr[3]); if( winCatArr[4] != 0 ) cat3Prize = Math.round(cat3Val / winCatArr[4]); if( winCatArr[5] != 0 ) cat2Prize = Math.round(cat2Val / winCatArr[5]); if( winCatArr[6] != 0 ) cat1Prize = Math.round(cat1Val / winCatArr[6]); var catPrizesArr = new Object(); catPrizesArr[3] = cat4Prize; catPrizesArr[4] = cat3Prize; catPrizesArr[5] = cat2Prize; catPrizesArr[6] = cat1Prize; if( Object.keys(winnersPerCatArr).length == 0){ if(typeof winnersPerCatArr[4] === 'undefined' || !winnersPerCatArr[4]) cb.sendNotice('Cat 4 - No Winners', '', '#b6b409'); if(typeof winnersPerCatArr[3] === 'undefined' || !winnersPerCatArr[4]) cb.sendNotice('Cat 3 - No Winners', '', '#b6b409'); if(typeof winnersPerCatArr[2] === 'undefined' || !winnersPerCatArr[4]) cb.sendNotice('Cat 2 - No Winners', '', '#b6b409'); if(typeof winnersPerCatArr[1] === 'undefined' || !winnersPerCatArr[4]) cb.sendNotice('Cat 1 - No Winners', '', '#b6b409'); cb.sendNotice('Nobody won today. The Jackpot will be reported to the next day.', '', '#b6b409'); } else { cb.sendNotice('Winners', '', '#b6b409'); for(cat in winnersPerCatArr) { for(userName in winnersPerCatArr[cat]){ var totalPrizeInTokens = winnersPerCatArr[cat][userName] * catPrizesArr[cat]; cb.sendNotice('Cat '+displayCatNameArr[cat]+': '+userName+'('+winnersPerCatArr[cat][userName]+' tickets) = '+totalPrizeInTokens+' tokens', '', '#b6b409'); } } if(typeof winnersPerCatArr[4] === 'undefined' || !winnersPerCatArr[4]) cb.sendNotice('Cat 4 - No Winners', '', '#b6b409'); if(typeof winnersPerCatArr[3] === 'undefined' || !winnersPerCatArr[4]) cb.sendNotice('Cat 3 - No Winners', '', '#b6b409'); if(typeof winnersPerCatArr[2] === 'undefined' || !winnersPerCatArr[4]) cb.sendNotice('Cat 2 - No Winners', '', '#b6b409'); if(typeof winnersPerCatArr[1] === 'undefined' || !winnersPerCatArr[4]) cb.sendNotice('Cat 1 - No Winners', '', '#b6b409'); } } calculate_prizes(); cb.setTimeout(send_room_notification, repeatTime); cb.setTimeout(send_jackpot_notification, repeatTimeJackpot);
© Copyright Chaturbate 2011- 2024. All Rights Reserved.