Bots Home
|
Create an App
Speed Raffell
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 Winners = Array(); 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:'' }, ] var RaffleTks = cb.settings.TokensOneTicket; var RaffleDiscription = cb.settings.RaffleDiscription; var MaxTime = cb.settings.MaxTime; var HowManyLetters = cb.settings.NumLetters; var Command = cb.settings.Command; var ReminderInterval = cb.settings.ReminderInterval; var StartMessage = cb.settings.StartRaffleMessage; var TimeToRaffle = MaxTime; /* 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 ' + MaxTime +' minutes ' + 'Get prepered You can Still buy tickets for \n' + RaffleDiscription.toUpperCase() +"\nDouble the Ticket price and you will win double the prize\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() " + time); //ReminderTimerId = window.setInterval(EndTimerCallBack, time * 60 * 1000); cb.setTimeout(EndTimerCallBack, time * 60 * 1000); } /* EndTimerCallBack */ function SendRaffleStartMessage(){ cb.cancelTimeout(ReminderTimerId); Debug("SendRaffleStartMessage()"); GetRaffleWord(); var PN = new Array; PN['Type'] = 'StartRaffle'; PN['Notice'] = StartMessage; PN['Reciever'] = ""; PN['Background'] = "##C0C0C0"; PN['Forground']= "#0000FF"; PN['FontType']="bold"; PN['Sender']= "System"; SendNotice(PN); cb.sendNotice("------------ " + RafflePhrase + " ------------","","#FF0000","#00FF00","bold",""); StartTime = GetTime(); SetEndRaffleTimer(); } 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("getRandomInt() for word" + 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("StartRaffle()"); if (TimeToRaffle == 0) SendRaffleStartMessage(); else { var time = getRandomInt(0, TimeToRaffle); Debug("time " + time); 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, you tip and you type"; 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 && ThisTipperMsg.toLowerCase() == 'speed'){ var Buyer = new Array; Buyer['Name'] = ThisTipper; Buyer['Tip'] = ThisTip; Buyers.push(Buyer); for(var x = 0 ; x< Buyers.length; x++) Debug("ontip() buyer " + Buyers[x].Name); Debug("ontip() buyer " + Buyer['Name'] + " Buyers "+ Buyers); } }); cb.onMessage( function (message){ Debug("onMessage()"); if(IsCommand(message['m'], message["user"])) { message["X-Spam"] = true; StartRaffle(); return message; } Debug("onMessage() message " + message['m'] + " phrase "+ RafflePhrase); Debug("onMessage() message[user] " + message["user"] + " Buyers "+ Buyers); for(var x = 0 ; x < Buyers.length; x++) { if ( message['m'] == RafflePhrase && Buyers[x].Name == message["user"]){ if( cb.room_slug == message["user"]){ var PN = new Array; PN = DefaultPN(PN); PN['Notice'] = "You are kidding me? you can not have your own prize"; PN['Reciever'] = message["user"]; PN['Sender']= "System"; SendNotice(PN); return message; } EndTime = GetTime(); var TypeTime = EndTime - StartTime; var Win = new Array; Win['Name'] = message["user"]; Win['Time'] = TypeTime; Debug ("user: " + message["user"] + "Time: " + TypeTime); Winners.push(Win); var PN = new Array; PN = DefaultPN(PN); PN['Notice'] = "Your Phrase Exepted"; PN['Reciever'] = message["user"]; PN['Sender']= "System"; SendNotice(PN); message["X-Spam"] = true; return message; } } var PN = new Array; PN = DefaultPN(PN); PN['Notice'] = "You are kidding me? next time buy a ticket"; PN['Reciever'] = message["user"]; PN['Sender']= "System"; SendNotice(PN); 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, you tip and you type"; PN['Reciever'] = user['user']; PN['Sender']= "System"; SendNotice(PN); }); Init(); Debug("Starting");
© Copyright Chaturbate 2011- 2024. All Rights Reserved.