Apps Home
|
Create an App
fishbowl
Author:
crystalsopen2
Description
Source Code
Launch App
Current Users
Created by:
Crystalsopen2
/******************************************************* * Title: fishbowl * * * Author: 'CrystalSopen' * *******************************************************/ var app = { name: "FishBowl", type: 'App', version: '0.0.5', build: '.003', date: '2018.05.02' }; var COLOR = { SYNTAX: '#995B00', RED: '#FF1407', AMBER: '#E56B00', MOD: '#DC0000', HVTEXT: '#D80A00', HVBACK: '#FFFFBF', NOTICE: '#6900CC', INFO: '#144D8C' }; var roomHost = cb.room_slug; var commandPrefix = '/'; var tickets = new Array(); var drawn = new Array(); var totalTipped = 0; var tokensToGoal = 1; // will be set when app 1st runs var bestTipper = "None yet"; var bestTip = 0; var lastTipper = "None yet"; var lastTip = 0; var gameOver = false; var finalSubject = false; var COMMAND = { FBTEST: 'fbtest', /* do several tests */ FBCMDS: 'fbcmds', /* list supported commands */ FBADD: 'fbadd', /* add a new prize to the bowl */ FBLIST: 'fblist', /** lists prizes still in bowl */ FBWON: 'fbwon', /** lists prizes won from the bowl */ }; cb.settings_choices = [{ name: 'Subject', type: 'str', minLength: 1, maxLength: 1023, default: 'Fishbowl running', label: "Set the subject 'X tokens for a special prize|Y to goal' will be added" }, { name:'InitialGoal', type:'int', minValue:1, default: 1000, label: "Starting goal" }, { name: 'fishAd', type: 'str', minLength: 1, maxLength: 2048, default: "Special prizes are on tickets in a fishbowl", label: "This is a message to explain the app to users." }, { name: 'controlString', type: 'str', minLength: 1, maxLength: 2048, default: "#prize strip; #add 100; #multiply 1.5; #divide 2; #subtract 100; #draw 2", label: "format '#prize text' or one of #add #subtract #multiply #divide and a number #draw draws more prizes. ; separates" }, { name:'Cost', type:'int', minValue:1, maxValue:999, default: 50, label: "Cost to pull from the fishbowl. must be tipped exactly" }, { name:'adTime', type:'int', minValue:1, maxValue:60, default: 5, label: "How often (in minutes) to advertize the app to users" }, { name: 'goalMSG', type: 'str', minLength: 1, maxLength: 2048, default: "GOAL REACHED | Sweet Victory! | Thanks to all tippers!!!", label: "This is a message sent to users when we reach the goal." } ]; cb.onMessage(function(msg) { var cmd = msg['m'].replace(/^\s+|\s+$/g, ''); if (cmd.startsWith(commandPrefix)) { cmd = cmd.slice(1) } var modOrHost = (msg['is_mod'] || (msg['user'] == roomHost)) cb.log("checking command:" + cmd) switch (cmd) { case COMMAND.FBCMDS: cb.sendNotice('* Syntax "/fbwon" lists winners and prizes in order', '', '', COLOR.INFO, 'bold'); cb.sendNotice('* Syntax "/fblist" lists remaining prize tickets in random order', '', '', COLOR.INFO, 'bold'); cb.sendNotice('* Syntax "/fbcmds" to list all commands.', '', '', COLOR.INFO, 'bold'); break; case COMMAND.FBADD: if (modOrHost) { /** add a ticket to the fish bowl */ } break; case COMMAND.FBLIST: /** list tickets in the fish bowl in random order*/ if (modOrHost) { listTickets(); } else { listTickets(msg['user']); } break; case COMMAND.FBWON: /** list tickets in the fish bowl in random order*/ if (modOrHost) { wonTickets(); } else { wonTickets(msg['user']); } break; case COMMAND.FBTEST: if (modOrHost) { /** run a series of tests */ } break; default: break; } }); cb.onTip(function (tip) { myTip = parseInt(tip['amount']); myTipper = tip['from_user']; totalTipped += myTip; tokensToGoal -= myTip; if (tokensToGoal < 0) { tokensToGoal = 0; } /** Check if this is a pull, if so do pull function */ if ((myTip == cb.settings["Cost"]) && (!gameOver)) { if (tickets.length > 0) { drawn.push({'user': myTipper, 'prize' : pullTicket()}) } else { cb.sendNotice('Cannot pull a ticket from an empty bowl. Sorry', '', '', COLOR.RED, 'bold'); }; }; /** Check if this alltime high tip, if so update*/ if (myTip > bestTip) { bestTip = myTip; bestTipper = myTipper; } /** Update latest tipper */ lastTip = myTip; lastTipper = myTipper; if (tokensToGoal < 0) { tokensToGoal = 0; } cb.drawPanel(); if ((tokensToGoal == 0) && (!gameOver)) { cb.sendNotice('*****************************************************', '', '', COLOR.RED, 'bold'); cb.sendNotice(cb.settings.goalMSG, '', '', COLOR.RED, 'bold'); cb.sendNotice('*****************************************************', '', '', COLOR.RED, 'bold'); gameOver = true; } if (!gameOver) { cb.changeRoomSubject(cb.settings.Subject + "|" + cb.settings.Cost + "tokens for a special prize|" + tokensToGoal + ' to goal'); } else if (!finalSubject) { cb.changeRoomSubject(cb.settings.goalMSG); finalSubject = true; } }); function wonTickets(to_user='') { var winner; cb.log("Entering won tickets"); cb.sendNotice("Tickets won from Bowl:", to_user, '', COLOR.INFO, 'bold'); for (var entry in drawn) { winner = drawn[entry]; cb.sendNotice(`# ${parseInt(entry) + 1} ${winner.user} won: ${winner.prize}`, to_user, '', COLOR.INFO, 'bold'); }; cb.log("Leaving won tickets") } function listTickets(to_user='') { cb.log("Entering list tickets") var array = new Array(); for (var entry in tickets) { array.push(tickets[entry]); }; var counter = array.length; // While there are elements in the array while (counter > 0) { // Pick a random index var index = Math.floor(Math.random() * counter); // Decrease counter by 1 counter--; // And swap the last element with it var temp = array[counter]; array[counter] = array[index]; array[index] = temp; } cb.sendNotice("Tickets Left in Bowl:", to_user, '', COLOR.INFO, 'bold'); for (var entry in array) { cb.sendNotice(array[entry], to_user, '', COLOR.INFO, 'bold'); }; cb.log("Leaving list tickets") } function pullInt(myString) { myString = new String(myString); for (var x=0; x< myString.length; x++) { if ("0123456789.".includes(myString[x])) { return parseInt(myString.slice(x, myString.length)) } } } function pullFl(myString) { myString = new String(myString); for (var x=0; x< myString.length; x++) { if ("0123456789.".includes(myString[x])) { return parseFloat(myString.slice(x, myString.length)) } } } function pullTicket() { // splice out a random ticket offset = Math.floor(Math.random() * tickets.length); var pulled = new String(tickets.splice(offset, 1)).trim(); cb.log(offset + "Pulled '" + pulled + "'"); if (pulled.includes("#prize")) { var prize = pulled.replace(/\#prize/i, "") cb.sendNotice('A prize has been won! The prize is => ' + prize, '', '', COLOR.NOTICE, 'bold'); } else if (pulled.includes("#add")) { cb.log(pullInt(pulled)); tokensToGoal += pullInt(pulled); cb.sendNotice("Adding tokens to goal, because of this ticket " + pulled, '', '', COLOR.NOTICE, 'bold'); } else if (pulled.includes("#subtract")) { cb.log(pullInt(pulled)); tokensToGoal -= pullInt(pulled); cb.sendNotice("Subtracting tokens to goal, because of this ticket " + pulled, '', '', COLOR.NOTICE, 'bold'); } else if (pulled.includes("#multiply")) { tokensToGoal *= pullFl(pulled); tokensToGoal = pullInt(tokensToGoal); cb.sendNotice("Multiplying tokens to goal, because of this ticket " + pulled, '', '', COLOR.NOTICE, 'bold'); } else if (pulled.includes("#divide")) { tokensToGoal = tokensToGoal / pullFl(pulled); tokensToGoal = pullInt(tokensToGoal); cb.sendNotice("Dividing tokens to goal, because of this ticket " + pulled, '', '', COLOR.NOTICE, 'bold'); } else if (pulled.includes("#draw")) { var draws = pullInt(pulled); cb.sendNotice("Drawing " + draws + " additional tickets b/c =>" + pulled, '', '', COLOR.NOTICE, 'bold'); while (draws > 0) { draws = draws - 1; if (tickets.length > 0) { pulled = pulled + '=>' + pullTicket() } else { cb.sendNotice('Cannot pull a ticket from an empty bowl. Sorry', '', '', COLOR.RED, 'bold'); }; }; }; return pulled; } function fillBowl() { // build the list that will act like a fishbowl var entries = cb.settings["controlString"].split(";"); for (var e in entries) { var entry = entries[e]; cb.log("adding '" + entry + "'"); if (entry.match(/\#(prize|add|multiply|divide|subtract|draw).*/i)) { tickets.push(entry); } else { cb.log(entry + " Insert failed. This ticket seems to be invalid"); }; }; } cb.onDrawPanel(function(user) { return { 'template': '3_rows_of_labels', 'row1_label': 'Tip Received / Goal :', 'row1_value': totalTipped + " / " + tokensToGoal, 'row2_label': 'Highest Tip:', 'row2_value': bestTipper + ":" + bestTip, 'row3_label': 'Latest Tip Received:', 'row3_value': lastTipper + ":" + lastTip, }; }); function fishAd() { cb.sendNotice('* Syntax "/fbwon" lists winners and prizes in order', '', '', COLOR.INFO, 'bold'); cb.sendNotice('* Syntax "/fblist" to list all tickets.', '', '', COLOR.INFO, 'bold'); cb.sendNotice('* Syntax "/fbcmds" to list all commands.', '', '', COLOR.INFO, 'bold'); cb.sendNotice("Tip exactly " + cb.settings.Cost + " to pull a special prize.", '', '', COLOR.INFO, 'bold'); cb.sendNotice(cb.settings.fishAd, '', '', COLOR.INFO, 'bold'); cb.setTimeout(fishAd, (cb.settings.adTime * 60000)); } function init() { /** set variables like tokensToGoal */ tokensToGoal = cb.settings["InitialGoal"]; /** build lists */ cb.setTimeout(fillBowl, (60)); cb.sendNotice('* Thanks for using ' + app.name + ' version:' + app.version + " Build:" + app.build + " Modified:" + app.date, '', '', COLOR.INFO, 'bold'); cb.sendNotice('* Syntax "/fbcmds" to list all commands.', '', '', COLOR.INFO, 'bold'); /** set the timout for the advert */ cb.setTimeout(fishAd, (cb.settings.chat_ad * 60000)); cb.changeRoomSubject(cb.settings.Subject + "|" + cb.settings.Cost + " tokens for a special prize|" + tokensToGoal + ' to goal'); }; init();
© Copyright Chaturbate 2011- 2025. All Rights Reserved.