Bots Home
|
Create an App
It's Raffle Time
Author:
mermmaids_couple
Description
Source Code
Launch Bot
Current Users
Created by:
Mermmaids_Couple
cb.settings_choices = [ {name:'raffle_ticket_cost', type:'int', minValue:1, maxValue:999, defaultValue:21, label: "Raffle Ticket Cost"} ]; var userArray = []; cb.onTip(function (tip) { var ticketsBought = 0; if (parseInt(tip['amount'])%cb.settings.raffle_ticket_cost == 0) { ticketsBought = parseInt(tip['amount'])/cb.settings.raffle_ticket_cost; cb.chatNotice(tip['from_user'] + " has bought " + ticketsBought + " raffle ticket(s)! Thank you!!"); addUser(userArray, tip['from_user'], ticketsBought); if (userInArray(userArray, tip['from_user']) === true) { for(i=0; i < userArray.length; i++) { if(userArray[i].username== tip['from_user']) { if (userArray[i].email == '') { cb.sendNotice('\n******\nPlease use the command /raffle_email then a space and your email so ' + cb.room_slug + ' can notify you if you win\n******', tip['from_user'], '#FFF0DE', '#8A4900', 'bold'); } } } } } }); cb.onMessage(function (msg) { var showMsg = true; if (msg['m'].substring(0, 14) == '/raffle_email ') { if (userInArray(userArray, msg['user']) === true) { for(i=0; i < userArray.length; i++) { if(userArray[i].username== msg['user']) { userArray[i].email = msg['m'].substring(14); cb.sendNotice('******\nThank you for adding your email for notification!', msg['user'], '#FFF0DE', '#8A4900', 'bold'); showMsg = false; } } } } else if (msg['m'].substring(0, 12) == '/raffle_list' && msg['user'] == cb.room_slug) { showRaffleTickets(); showMsg = false; } if (showMsg == false) msg['m'] = '.'; return msg; }); /* * return array of users with the new user added, duplicate, * or error string. * Req: userArray = array of users to add the new user to * Req: username = username of new user * Return: array of users with new users added * On error: return "duplicate" if username in user array already * On error: return "failed" if user no duplicate and wasn't added */ function addUser(userArray, username,ticketsBought) { var userArrayLength = userArray.length; username = username.toLowerCase(); //cb.chatNotice(userArray.length); // check if username is in userarray usernameExists = userInArray(userArray, username); if (usernameExists === true) { for(i=0; i < userArray.length; i++) { if(userArray[i].username== username) userArray[i].tickets += ticketsBought; } return userArray; // username found in array, return duplicate } else { // remove user from all user arrays //delUserFromAll(username); // add username to array //cb.chatNotice(userArrayLength); var valueToPush = { }; // or "var valueToPush = new Object();" which is the same valueToPush["username"] = username; valueToPush["tickets"] = ticketsBought; valueToPush["email"] = ''; userArray.push(valueToPush); // check to see that addition of user worked usernameExists = userInArray(userArray, username); if (usernameExists === true) { return userArray; // it worked, return the array } else { return "failed"; // failed, return failed } } } function userInArray(userArray, username) { var userFound = false; username = username.toLowerCase(); if (userArray.length > 0) { for(i=0; i < userArray.length; i++) { if(userArray[i].username== username) userFound = true; } } return userFound; } function showRaffleTickets() { var msg = "##### RAFFLE TICKET PURCHASERS #####"; msg += "\nList sorted in chronological order"; for (var i = 0; i < userArray.length; i++) msg += "\n" + userArray[i].username + ": " + userArray[i].tickets + " tickets " + userArray[i].email; cb.sendNotice(msg, cb.room_slug, '#FFF0DE', '#8A4900', 'bold'); }
© Copyright Chaturbate 2011- 2026. All Rights Reserved.