Apps Home
|
Create an App
BaranJoymeter
Author:
prot0type_
Description
Source Code
Launch App
Current Users
Created by:
Prot0type_
/* Plugin details */ var app = { name : "'BaranJoymeter'", /* Script name */ type : 'App', /* Script type: bot|app */ version : '1.1', /* Internal: Script version number */ build : '.011', /* Internal: Script build number */ date : '2015.02.17', /* Internal: Script build date */ dev1 : 'phatkatmeow', /* main developer */ dev2 : 'acrazyguy', /* main developer */ host : cb.room_slug, /* Broadcaster (room host) */ prefix : '/' /* Example: /crazygoal */ }; /* Plugin settings */ cb.settings_choices = [ { name: 'goal', type: 'int', minValue: 0, label: "Token Goal", required: true }, { name: 'goal_description', type: 'str', minLength: 1, maxLength: 255, defaultValue: "", label: "Goal Description", required: true }, { name: 'goal_restart', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'No', label: "Automatically restart the goal again when reached?" } ]; /* Plugin Variables */ var tipTotal = 0; var ticketList = []; // list of users who tipped var goal = cb.settings.goal; var capitalizeMe = String(cb.settings.goal_description); var goalDesc = capitalizeMe.charAt(0).toUpperCase() + capitalizeMe.substring(1); var goalStatus = true; // true/false (true=active, default.) var goalCount = 0; // goal has been reached 0 times. var goalRestart = false; // Default to no-auto-restart of goal, but: if (cb.settings.goal_restart === 'Yes') goalRestart = true; var ui = { head : "-------------- "+app.name+" by CrazyWare --------------", line : "-----------------------------------------------------------", red : '#D80A00', /* Bright red */ notice : '#6900CC', /* Bluish purple */ info : '#144D8C' /* Blue-grey: Help and misc info */ }; /* API functions */ cb.onTip(function(tip) { /* Only process a tip if there is a goal running */ if (goalStatus) { var tip = { amount : tip['amount'], viewer : tip['from_user'] }; tipTotal += tip.amount; // we still need this if (!cbjs.arrayContains(ticketList,tip.viewer)) { ticketList.push(tip.viewer); } var output = ""; if (tipTotal >= goal) { goalCount++; output += goalText('finish'); if (goalRestart) { goalStatus = true; cb.sendNotice(" !! Hey "+app.host+", The goal was automatically restarted, people can continue tipping to reach it again.",app.host,'',ui.notice,'bold'); } else { goalStatus = false; cb.sendNotice(" !! Hey "+app.host+", type: '/cg start' to start a new goal",app.host,'',ui.notice,'bold'); } tipTotal = 0; colors = ui.red; } else { output += app.name+" * Info: '"+goalDesc+"' at: '"+goal+"' tokens.\n"+app.name+" * Progress: "+progressBar()+"."; colors = ui.notice; } cb.sendNotice(output,'','',colors,'bold'); // cb.drawPanel(); } }); cb.onEnter(function(viewer) { /* Only process a tip if there is a goal running */ if (goalStatus) { var viewer = { name : viewer['user'] }; cb.sendNotice(ui.head+"\n* Info: '"+goalDesc+"' at: '"+goal+"' tokens. \n* Progress: "+progressBar()+". \n* Help reach the goal by tipping any amount. \n "+ui.line,viewer.name,'',ui.red,'bold'); // TODO: Clean this 1 line up, goalText(start, perhaps status?) needed. } // end if goalStatus }); cb.onMessage(function(msg) { var regexCommandSplit = '^' + app.prefix + '(\\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']; // whole msg var u = msg['user']; // viewer name var isMod = msg['is_mod']; // true/false var isFan = msg['in_fanclub']; // true/false var isRoomHost = (u == app.host); // true/false if (m[0] == "?" || m[0] == "!") { msg['X-Spam'] = true; return cb.sendNotice(" * " +app.name+ ": Incorrect command prefix.",u,'',ui.notice,'bold'); } switch (cmd) { case 'crazygoal': case 'cg': var output = ""; var output2 = ""; if (!cmdval) { output += " * I need an argument, try: '/crazygoal details|start|stop'."; } if (cmdval == 'details') { output += " * Goal Status: "+(goalStatus == true ? "Active: Counting tips" : "Inactive: Not counting tips")+"."; output += "\n* Goal: '"+goal+"' tokens ('"+tipTotal+"' tokens received)."; output += "\n* Goal tippers: " + (ticketList.length < 1 == true ? "No tips by anybody yet!" : cbjs.arrayJoin(ticketList,", ")) + "."; output += "\n* Goal Description: "+goalDesc+"."; output += "\n* Goal Progress: "+progressBar()+"."; output += "\n* Goal has been reached: "+goalCount+" times (Goal will "+(goalRestart == true ? "" : "not")+" automatically restart)."; output += "\n\n* App: "+app.name+", version "+app.version + app.build+" ("+app.date+")."; output += "\n* Developers: "+app.dev1+" and "+app.dev2+"."; } // cmdval if (cmdval == 'start') { if (isRoomHost) { if (goalStatus == false) { goalStatus = true; output += " * Starting goal ..."; output2 += goalText('start'); } else { output += " * The goal is already running. You can stop it with: '/crazygoal stop'"; } } else { output += " * Sorry, this command is for the broadcaster only."; } } // cmdval start if (cmdval == 'stop') { if (isRoomHost) { if (goalStatus == true) { goalStatus = false; output2 += goalText('stop'); } else { output += " * There is no goal running to stop. You can start one with: '/crazygoal start'"; } } else { output += " * Sorry, this command is for the broadcaster only."; } } // cmdval stop // we are done, spit the stuff out if (output2 != "") { cb.sendNotice("\n"+ui.head+"\n"+output2+"\n"+ui.line+"\n",'','',ui.red,'bold'); } else { cb.sendNotice(ui.head+"\n"+output+"\n"+ui.line,u,'',ui.notice,'bold'); } break; } // switch // we are done, .. if (m[0] == app.prefix) msg['X-Spam'] = true; return msg; }); /* Plugin functions */ function round(value, decimals) { return Number(Math.round(value+'e'+decimals)+'e-'+decimals); } function goalText(goalArg) { var goalOutput = ""; if (goalArg == 'start') { goalOutput = "* Info: '"+goalDesc+"' at: '"+goal+"' tokens."; goalOutput += "\n* Okay, you can now tip any token amount."; } if (goalArg == 'stop') { goalOutput += "* Goal Stopped by "+app.host+", \n* Tips are no longer counted towards goal."; } if (goalArg == 'finish') { goalOutput += "\n"+ui.head+"\n* ----------------> GOAL ACHIEVED! <---------------- \n* "+progressBar()+"\n "+ui.line+" \n * A big thank you to " + (ticketList.length > 1 == true ? "all "+ticketList.length+" tippers" : ""+ticketList.length+" tipper") + ":"; goalOutput += "\n* " + cbjs.arrayJoin(ticketList,", "); goalOutput += "\n* It's time for: "+goalDesc+"\n* Goal has been reached "+goalCount+" times.\n"+ui.line+"\n"; } return goalOutput; } function progressBar() { var tipBar = ''; var tipBars = ''; var tipProgress = ''; var tipPercenty = ''; var tipPercent = ''; var tipPercentInt = ''; var tipLeft = ''; if (tipTotal > goal) { tipTotal = goal; tipPercent = 100; } else { tipPercent = round((tipTotal/goal)*100,2); // 10,45 } tipPercentInt = parseInt(tipPercent,10); // 10 tipLeft = (goal - tipTotal); var tipBars = { g00 : '\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592', g10 : '\u2593\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592', g20 : '\u2593\u2593\u2592\u2592\u2592\u2592\u2592\u2592\u2592\u2592', g30 : '\u2593\u2593\u2593\u2592\u2592\u2592\u2592\u2592\u2592\u2592', g40 : '\u2593\u2593\u2593\u2593\u2592\u2592\u2592\u2592\u2592\u2592', g50 : '\u2593\u2593\u2593\u2593\u2593\u2592\u2592\u2592\u2592\u2592', g60 : '\u2593\u2593\u2593\u2593\u2593\u2593\u2592\u2592\u2592\u2592', g70 : '\u2593\u2593\u2593\u2593\u2593\u2593\u2593\u2592\u2592\u2592', g80 : '\u2593\u2593\u2593\u2593\u2593\u2593\u2593\u2593\u2592\u2592', g99 : '\u2593\u2593\u2593\u2593\u2593\u2593\u2593\u2593\u2593\u2592', gxx : '\u2593\u2593\u2593\u2593\u2593\u2593\u2593\u2593\u2593\u2593' }; // Expand to be more detailed. if (tipPercentInt < 10) { tipBar = tipBars.g00; } else if (tipPercentInt < 11) { tipBar = tipBars.g10; } else if (tipPercentInt < 20) { tipBar = tipBars.g10; } else if (tipPercentInt < 30) { tipBar = tipBars.g20; } else if (tipPercentInt < 40) { tipBar = tipBars.g30; } else if (tipPercentInt < 50) { tipBar = tipBars.g40; } else if (tipPercentInt < 60) { tipBar = tipBars.g50; } else if (tipPercentInt < 70) { tipBar = tipBars.g60; } else if (tipPercentInt < 80) { tipBar = tipBars.g70; } else if (tipPercentInt < 99) { tipBar = tipBars.g99; } else if (tipPercentInt >= 100) { tipBar = tipBars.gxx; } tipProgress = tipBar+" ("+tipPercent+"%) (We need '"+tipLeft+"' more tokens!)"; /* DEBUG var debug = "\n DEBUG: "; debug += "\n tipTotal: "+tipTotal; debug += "\n goal: "+goal; debug += "\n tipPercenty: "+tipPercenty; debug += "\n tipPercent: "+tipPercent; debug += "\n tipPercentInt: "+tipPercentInt; debug += "\n tipLeft: "+tipLeft; debug += "\n tipBars: "+tipBars; debug += "\n tipBar: "+tipBar; debug += "\n tipProgress: "+tipProgress+"\n"; cb.sendNotice(debug); */ return tipProgress; } /* Plugin Initialization */ output = "\n* Hey "+app.host+"! You are now running "+app.name+", version "+app.version + app.build+" ("+app.date+")."; output += "\n* For more information about this app, type: /crazygoal"; cb.sendNotice("\n"+ui.head + output+"\n"+ui.line+"\n",app.host,'',ui.info,'bold'); cb.sendNotice("\n"+ui.head+"\n"+goalText('start')+"\n"+ui.line+"\n",'','',ui.red,'bold');
© Copyright Chaturbate 2011- 2026. All Rights Reserved.