Bots Home
|
Create an App
Raffle At Speed
Author:
rasputin5888
Description
Source Code
Launch Bot
Current Users
Created by:
Rasputin5888
var Keys = ['a','A','b','B','C','c','D','d','E','e','F','f','G','g','H','h','i','I','j','J','k','K','l','L','m','M','n','N','o','O','p','P','q','Q','r','R','s','S','t','T','w','W','x','X','y','Y','z','Z','1','2', '3', '4', '5', '6', '7', '8', '9']; var Winner = ['Name', 'Time']; var Winners = Array(Winner); var Buyer = ['Name', 'tip']; var Buyers = Array(); var NUM_LETTERS = 55; var ReminderTimerId; var RafflePhrase; var StartTime; var EndTime; var dbug = true; //var EndRaffleTimer; cb.settings_choices = [ {name: 'MaxTime', label: 'How max time will pass from command till raffle (Minutes)\n0 will start the raffle right away \n this might cos arguments, void using it', type: 'str', required: true, deafultValue:'10'}, {name: 'StartRaffleMessage', label: 'Write the mesage to inform you users that the raffle start', type: 'str', required: true, deafultValue:"Raffle is ON type as fast as you can, Best Speed to all - GOOO\n maximum wait time 1 minute dont worry if the typo is not visable"}, {name: 'NumLetters', label: 'How many letters in the Raffle word\n( that the ticket buyers have to type fast like 5 letters word - dont make it to long)', type: 'str', required: true, deafultValue:'2'}, {name: 'Command', label: 'Command to start the raffle\n( what ever you enter here will start the raffle when you want)', type: 'str', required: true, deafultValue:'\\Start'}, {name: 'TokensOneTicket', label: 'How much tokens for one Ticket', type: 'str', required: true, deafultValue:'50'}, {name: 'ReminderInterval', label: 'Reminder notice Interval( minutes)', type: 'str', required: true, deafultValue:'10'}, {name: 'RaffleDiscription',label: 'Price', type: 'str', minLength: 1, maxLength: 255, required: false, defaultValue:'10 minutes private show\n( dont forget itas only 50 tkns ticket, u can talk with who want' }, ] var RaffleTks = cb.settings.TokensOneTicket; var RaffleDiscription = cb.settings.RaffleDiscription; var MaxTime = cb.settings.MaxTime; var TimeToRaffle = cb.settings.TimeToRaffle; var HowManyLetters = cb.settings.NumLetters; var Command = cb.settings.Command; var ReminderInterval = cb.settings.ReminderInterval; var StartMessage = cb.settings.StartRaffleMessage; /* GetPhrase */ function GetRaffleWord(){ Debug("GetRaffleWord()"); var Str = ""; for(var i = 0; i < HowManyLetters; i++){ var x = getRandomInt(1, NUM_LETTERS); Str += Keys[x]; } RafflePhrase = Str; } function SendTimerStartMessage(TimeToRaffle){ Debug("SendTimerStartMessage()"); var PN = Array(); PN['Type'] = 'StartTimer'; PN['Notice'] = 'Raffle starts in maximum ' + TimeToRaffle +' minutes ' + 'Get prepered You can Still buy tickets for \n' + RaffleDiscription.toUpperCase() +"\nDouble the Ticket price and you will win double the price\n dont forget to put the word - speed - at the tip note"; //PN['Notice'] += '\nThe model just Hit the command, the raffle should start any time now!!!!!'); PN['Reciever'] = ""; PN['Sender']= "System"; SendNotice(PN); } function SetEndRaffleTimer(){ //EndRaffleTimer = window.setInterval(EndRaffle, 60 * 1000); Debug("SetEndRaffleTimer()"); cb.setTimeout(EndRaffle, 60 * 1000); } function EndRaffle(){ Debug("EndRaffle()"); var Str; var PN = new Array; PN['Notice'] = 'RAFFLE END!!! RAFFLE END!!!\n'; PN['Notice'] = PN['Notice'] + "Name------------Time\n"; for( var x = 0; x < Winners.length; x++) Str = Str + Winners[x]['Name'] + "-------------" + Winners[x]['Time'] + '\n'; PN['Notice'] = PN['Notice'] + Str+ '\n'; PN['Notice'] = PN['Notice'] + "THE WINNER IS" + Winners[0]['Name'] + "-------------" + Winners[0]['Time']; PN['Type'] = 'EndTimer'; //PN['Notice'] += '\nThe model just Hit the command, the raffle should start any time now!!!!!'); PN['Reciever'] = ""; PN['Sender']= "System"; SendNotice(PN); //window.clearInterval(EndRaffleTimer); } function SetTimerToStart(time){ Debug("SetTimerToStart()"); //ReminderTimerId = window.setInterval(EndTimerCallBack, time * 60 * 1000); cb.setTimeout(EndTimerCallBack, time * 60 * 1000); } /* EndTimerCallBack */ function SendRaffleStartMessage(){ cb.cancelTimeout(ReminderTimerId); Debug("SetTimerToStart()"); GetRaffleWord(); var PN = new Array; PN['Type'] = 'StartRaffle'; PN['Notice'] = StartMessage; PN['Reciever'] = ""; PN['Sender']= "System"; SendNotice(PN); cb.sendNotice("------------ " + RafflePhrase + " ------------","","#FF0000","#00FF00","bold",""); StartTime = GetTime(); } function EndTimerCallBack(id){ Debug("EndTimerCallBack()"); //window.clearInterval(ReminderTimerId); SendRaffleStartMessage(); //sending a notice that raffle begin //Do the raffle //sending notice to winners } /* Ideal */ function Ideal(){ Debug("Ideal()"); //var id = window.setInterval(IdealCallBack, parseInt(ReminderInterval)*60*1000); ReminderTimerId = cb.setTimeout(IdealCallBack, parseInt(ReminderInterval)*60*1000); //return id; } /* SendNotice */ function SendNotice(PN){ Debug("SendNotice()"); cb.sendNotice(PN['Notice'], PN['Reciever'], PN['Background'], PN['Forground'], PN['FontType'], PN['Group']); } /* IdealCallBack */ function IdealCallBack(){ Debug("IdealCallBack()"); var PN = new Array; PN['Type'] = 'Ideal'; PN['Notice'] = 'Raffle is comming soon at only ' + RaffleTks +' tkns' + ' the WINNER get \n' + RaffleDiscription.toUpperCase() +"\ndouble the Ticket price and you will win double the price\n dont forget to put the word - speed - at the tip note"; //PN['Notice'] += '\nThe model just Hit the command, the raffle should start any time now!!!!!'); PN['Reciever'] = ""; PN['Sender']= "System"; SendNotice(PN); cb.setTimeout(IdealCallBack, parseInt(ReminderInterval)*60*1000); } function GetTime(){ Debug("GetTime()"); var d = new Date(); var n = d.getTime(); return n; } function getRandomInt(min, max){ Debug("getRandomInt()"); var Int = Math.floor(Math.random() * (max - min + 1)) + min; Debug(Int); return Int; } function DefaultPN(PN){ Debug("DefaultPN()"); PN['Reciever'] = ""; PN['Notice'] = ""; PN['Background'] = "##C0C0C0"; PN['Forground'] = "#FF0000"; PN['FontType'] = "bold"; PN['Group'] = ""; PN['Sender'] = ""; PN['Type'] = ""; return PN; } /* IsCommand */ function IsCommand(Msg , User){ Debug("IsCommand()"); if(Msg == Command && User == cb.room_slug ) { return true } return false; } function Init(){ Debug("Init"); SendWelcomeMessage(); Ideal(); } function Debug(Msg){ if(dbug == true) cb.sendNotice("Debug - " + Msg,"rasputin5888","#FF0000","#00FF00","bold",""); } function StartRaffle(){ Debug("tartRaffle()"); if (TimeToRaffle == 0) SendRaffleStartMessage(); else { var time = getRandomInt(0, TimeToRaffle); SetTimerToStart(time); } SendTimerStartMessage(TimeToRaffle); } function SendWelcomeMessage(){ Debug("SendWelcomeMessage"); var PN = new Array; PN = DefaultPN(PN); PN['Notice'] = "Wellcom to speed raffle, where all and none determent the winner"; PN['Reciever'] = ""; PN['Sender']= "System"; SendNotice(PN); } cb.onTip(function (tip){ Debug("onTip()"); var ThisTip = parseInt(tip['amount']); var ThisTipperMsg = tip['message']; var ThisTipper = tip['from_user']; if ( ThisTip%RaffleTks == 0 && ThisTipperMsg.toLowerCase() == 'speed'){ Buyer['Name'] == ThisTipper; Buyer['Tip'] == ThisTip; Buyers.push(Buyer); } }); cb.onMessage( function (message){ Debug("onMessage()"); if(IsCommand(message['m'], message["user"])) { message["X-Spam"] = true; StartRaffle(); } if ( message['m'] == RafflePhrase && Buyers.indexOf(message["user"]) !== -1){ message["X-Spam"] = true; EndTime = GetTime(); var TypeTime = StartTime - EndTime; Winner['Name'] = message["user"]; Winner['Time'] = TypeTime; Winners.push(Winner); } return message; }); cb.onEnter(function(user) { var PN = new Array; PN = DefaultPN(PN); PN['Notice'] = "Wellcom to speed raffle, where all and none determent the winner"; PN['Reciever'] = user['user']; PN['Sender']= "System"; SendNotice(PN); }); Init(); Debug("Starting");
© Copyright Chaturbate 2011- 2024. All Rights Reserved.