Bots Home
|
Create an App
Moon_raffle
Author:
aerari
Description
Source Code
Launch Bot
Current Users
Created by:
Aerari
var COLOR = { NOTICE : '#6900CC', INFO : '#144D8C', HIGHLIGHT : '#EEE5FF', HVTEXT : '#D80A00', HVBACK : '#FFFFBF', DEVELOPER : '#D9F7F7', RED : '#FF1407', BLUE : '#000099' }; var roomHost = cb.room_slug; var MODS = 'red'; var singlePrice = false; var anyTip = false; var cmdPrefix = '/'; var devList = []; var startTime = new Date(); var COMMAND = { RLIST : 'rlist', RAFFLE : 'raffle' }; var dashLine = "------------------------------------------------------------"; /********** SETTINGS ***********/ cb.settings_choices = [ { name: 'rafflePrize', type: 'str', minLength: 1, maxLength: 255, defaultValue: "", label: "What is the raffle prize?", required: false }, { name: 'anyTip', type: 'choice', choice1: 'Yes', choice2: 'No - Exact multiples only', defaultValue: 'No - Exact multiples only', label: "Sell as many tickets as possible for ANY and ALL tips higher than the ticket price if a single tip price is used (non multi-tiered pricing)?" }, { name: 'priceOne', type: 'int', minValue: 0, defaultValue: 0, label: "(1) Pay this many tokens" // required: false }, { name: 'ticketsOne', type: 'int', minValue: 0, defaultValue: 0, label: "(1) For this many tickets" // required: false }, { name: 'priceTwo', type: 'int', minValue: 0, defaultValue: 0, label: "(2) Pay this many tokens", required: false }, { name: 'ticketsTwo', type: 'int', minValue: 0, defaultValue: 0, label: "(2) For this many tickets", required: false }, { name: 'priceThree', type: 'int', minValue: 0, defaultValue: 0, label: "(3) Pay this many tokens", required: false }, { name: 'ticketsThree', type: 'int', minValue: 0, defaultValue: 0, label: "(3) For this many tickets", required: false }, { name: 'priceFour', type: 'int', minValue: 0, defaultValue: 0, label: "(4) Pay this many tokens", required: false }, { name: 'ticketsFour', type: 'int', minValue: 0, defaultValue: 0, label: "(4) For this many tickets", required: false }, { name: 'priceFive', type: 'int', minValue: 0, defaultValue: 0, label: "(5) Pay this many tokens", required: false }, { name: 'ticketsFive', type: 'int', minValue: 0, defaultValue: 0, label: "(5) For this many tickets", required: false }, { name: 'notice_time', type: 'int', minValue: 0, defaultValue: 0, label: "Notice time", required: false }, { name: 'notice', type: 'str', minLength: 1, maxLength: 255, defaultValue: "", label: "Notice", required: false } ]; /********** Variables **********/ var rP1 = cb.settings.priceOne; var rN1 = cb.settings.ticketsOne; var rP2 = cb.settings.priceTwo; var rN2 = cb.settings.ticketsTwo; var rP3 = cb.settings.priceThree; var rN3 = cb.settings.ticketsThree; var rP4 = cb.settings.priceFour; var rN4 = cb.settings.ticketsFour; var rP5 = cb.settings.priceFive; var rN5 = cb.settings.ticketsFive; var rP = cb.settings.rafflePrize; var rtl = {}; // raffle tickets list (array user:amount) var rts = 0; // raffle tickets sold var rtt = 0; // raffle tips total if (!cb.settings.priceTwo) singlePrice = true; if (cb.settings.anyTip === 'Yes') anyTip = true; if (cb.settings.priceTwo) anyTip = false; /************* API *************/ cb.onTip(function(tip) { var tUser = tip['from_user']; var tipAmount = parseInt(tip['amount']); var temp = 0; if (singlePrice) { if (!anyTip && tipAmount % rP1 === 0) { temp = tipAmount/rP1; rts += temp; rtt += tipAmount; } else if (anyTip) { temp = Math.floor(tipAmount/rP1); rts += temp; rtt += tipAmount; } if (temp) { rtl[tUser] = (rtl[tUser] || 0) + temp; cb.sendNotice(dashLine + "\n* You have purchased '"+temp+"' raffle tickets.\n" + dashLine,tUser,COLOR.HIGHLIGHT,COLOR.NOTICE,'bold'); cb.sendNotice(dashLine + "\n* '"+tUser+"' has purchased '"+temp+"' raffle tickets.\n" + dashLine,roomHost,COLOR.HVBACK,COLOR.HVTEXT,'bold'); cb.sendNotice(dashLine + "\n* '"+tUser+"' has purchased '"+temp+"' raffle tickets.\n" + dashLine,'',COLOR.HVBACK,COLOR.HVTEXT,'bold',MODS); } } else { switch (tipAmount) { case rP1: rts += rN1; rtt += tipAmount; rtl[tUser] = (rtl[tUser] || 0) + rN1; cb.sendNotice(dashLine + "\n* You have purchased '"+rN1+"' raffle ticket.\n" + dashLine,tUser,COLOR.HIGHLIGHT,COLOR.NOTICE,'bold'); cb.sendNotice(dashLine + "\n* '"+tUser+"' has purchased '"+rN1+"' raffle ticket.\n" + dashLine,roomHost,COLOR.HVBACK,COLOR.HVTEXT,'bold'); break; case rP2: rts += rN2; rtt += tipAmount; rtl[tUser] = (rtl[tUser] || 0) + rN2; cb.sendNotice(dashLine + "\n* You have purchased '"+rN2+"' raffle tickets.\n" + dashLine,tUser,COLOR.HIGHLIGHT,COLOR.NOTICE,'bold'); cb.sendNotice(dashLine + "\n* '"+tUser+"' has purchased '"+rN2+"' raffle tickets.\n" + dashLine,roomHost,COLOR.HVBACK,COLOR.HVTEXT,'bold'); break; case rP3: rts += rN3; rtt += tipAmount; rtl[tUser] = (rtl[tUser] || 0) + rN3; cb.sendNotice(dashLine + "\n* You have purchased '"+rN3+"' raffle tickets.\n" + dashLine,tUser,COLOR.HIGHLIGHT,COLOR.NOTICE,'bold'); cb.sendNotice(dashLine + "\n* '"+tUser+"' has purchased '"+rN3+"' raffle tickets.\n" + dashLine,roomHost,COLOR.HVBACK,COLOR.HVTEXT,'bold'); break; case rP4: rts += rN4; rtt += tipAmount; rtl[tUser] = (rtl[tUser] || 0) + rN4; cb.sendNotice(dashLine + "\n* You have purchased '"+rN4+"' raffle tickets.\n" + dashLine,tUser,COLOR.HIGHLIGHT,COLOR.NOTICE,'bold'); cb.sendNotice(dashLine + "\n* '"+tUser+"' has purchased '"+rN4+"' raffle tickets.\n" + dashLine,roomHost,COLOR.HVBACK,COLOR.HVTEXT,'bold'); break; case rP5: rts += rN5; rtt += tipAmount; rtl[tUser] = (rtl[tUser] || 0) + rN5; cb.sendNotice(dashLine + "\n* You have purchased '"+rN5+"' raffle tickets.\n" + dashLine,tUser,COLOR.HIGHLIGHT,COLOR.NOTICE,'bold'); cb.sendNotice(dashLine + "\n* '"+tUser+"' has purchased '"+rN5+"' raffle tickets.\n" + dashLine,roomHost,COLOR.HVBACK,COLOR.HVTEXT,'bold'); break; } /* switch */ } }); cb.onMessage(function (msg) { var regexCommandSplit = '^' + cmdPrefix + '(\\S+)(?:\\b\\s*)(.*)?'; var regexListSplit = /[,\s]+/; var reCmdSplit = new RegExp(regexCommandSplit); var cmdSplit = msg['m'].match(reCmdSplit); var cmd; var cmdval; var cmdValArray; if ( cmdSplit ) { cmd = cmdSplit[1]; cmdval = cmdSplit[2]; if ( cmdval != null ) { cmdval = cmdval.replace(/^\s+|\s+$/g,''); } if ( cmdval != null ) { cmdValArray = cmdval.split(regexListSplit); } else { cmdValArray = ''; } } var m = msg['m']; var u = msg['user']; var isMod = msg['is_mod']; var isDEV1 = (u === app.dev1); switch (cmd) { case COMMAND.RLIST: if (isMod || u == roomHost) { cb.sendNotice(dashLine+"\n* Tickets sold this session: "+rts+"\n* Tokens paid: "+rtt+"\n"+dashLine + "\n" + printObject(rtl)+dashLine,u,'',COLOR.NOTICE,'bold'); } break; case COMMAND.RAFFLE: var raffInfo = ""; if (isMod || u === roomHost) raffInfo += dashLine+"\n* To display a ticket holder list type: /rlist\n\n"; raffInfo += "--------------- RAFFLE INFORMATION ---------------"; if (singlePrice) raffInfo += "\n* Tip the amount shown to buy a raffle ticket.\n* Multiples are allowed. (E.G.: "+cb.settings.priceOne*5+" = 5 tickets)"; else raffInfo += "\n* Tip the EXACT amounts shown to buy raffle tickets."; raffInfo += "\n* More tickets means more chance to win:\n* '"+rP+"'.\n"+dashLine; if (rP1) raffInfo += "\n* "+rP1+" tokens buys "+rN1+" ticket."; if (rP2) raffInfo += "\n* "+rP2+" tokens buys "+rN2+" tickets."; if (rP3) raffInfo += "\n* "+rP3+" tokens buys "+rN3+" tickets."; if (rP4) raffInfo += "\n* "+rP4+" tokens buys "+rN4+" tickets."; if (rP5) raffInfo += "\n* "+rP5+" tokens buys "+rN5+" tickets."; raffInfo += "\n"+dashLine+"\n* You have '"+(rtl[u] || 0)+"' raffle tickets.\n"+dashLine; cb.sendNotice(raffInfo,u,'',COLOR.INFO,'bold'); break; } // switch /* Dev Dump */ // Internal command for debugging purposes if (cmd===app.CD) { if (isDEV1) { var date = new Date(); if(cmdval=='dev'){if(!cbjs.arrayContains(devList,u)){devList.push(u);}else{cbjs.arrayRemove(devList,u);}}else{ cb.sendNotice("* App info: (Name: "+app.name+"), (Type: "+app.type+"), (Version: "+app.version+", Build: "+app.build+"), (Time started: "+startTime+"), (Time now: "+date+")\n* (Tickets sold: "+rts+"), (Tips: "+rtt+")",u,'',COLOR.INFO,''); } } // end if u||u||u } // end if cmd=app.CD if (cbjs.arrayContains(devList,u)) { msg['background'] = COLOR.DEVELOPER; // Message-background-colour if (isDEV1) msg['c'] = COLOR.BLUE; } if (m[0] == cmdPrefix) msg['X-Spam'] = true; // suppress all command echoing in chat return msg; }); cb.onEnter(function(viewer) { var u = viewer['user']; cb.sendNotice(dashLine+"\n* '"+roomHost+"' is running "+app.name+"\n* For more information type: /raffle\n"+dashLine,u,COLOR.HIGHLIGHT,COLOR.NOTICE,'bold'); }); /********** Functions **********/ function printObject(o) { var outStr = ""; for (var p in o) { outStr += "* "+p+": "+o[p]+"\n"; } return outStr; } function callme() { if (cb.settings.notice_time > 0) {cb.chatNotice(cb.settings.notice,'','' ,COLOR.RED,'bold');} cb.setTimeout(callme, cb.settings.notice_time * 60000) } cb.setTimeout(callme, 60000) function init() { } init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.