Bots Home
|
Create an App
v_tipperbot
Author:
birdy2test
Description
Source Code
Launch Bot
Current Users
Created by:
Birdy2test
/* -------------------------------------------------------------------- * Name: V's Tipper Bot * Author: Birdy * -------------------------------------------------------------------- * Version: 0.1 * Built on: 30 april 2021 * -------------------------------------------------------------------- * * --------------------------------------------------------------------*/ var BMO = { init : false }; var tipperList = []; var totalTippedUser=0; var totalCorrectTippers=0; var timeoutId=0; var colorNotice = '#0080ff'; cb.settings_choices = [ { name: 'goal_description', type: 'str', minLength: 1, maxLength: 255, label : 'Goal Description' }, { name:'number_of_tippers', type:'int', minValue:1, maxValue:99, defaultValue:5, label: "Number of Tippers for goal" }, { name:'score_kind', type:'choice', choice1:'minimal amount per tip', choice2:'total tipped amount', defaultValue:'minimal amount per tip', label: "Score kind" }, { name:'minimal_tip_amount', type:'int', minValue:1, maxValue:999, defaultValue:15, label: "Minimal tip amount" } , { name:'notifier_time_out', type:'int', minValue:0, maxValue:9999, defaultValue:240, label: "Notifier timeout in seconds, 0 (zero) is off" } , { name:'notice_new_tipper', type:'choice', choice1:'yes', choice2:'no', defaultValue:'yes', label: "Send notice when a new tipper tips" } ]; var startUpBot = function() { if (cb.settings.notifier_time_out > 0) { timeoutId = cb.setTimeout(displayGoalNotice, cb.settings.notifier_time_out * 1000); } } var findTipper = function (user) { for (var i = 0; i < tipperList.length; i++) { if (tipperList[i].user == user) { return i; } } return false; } var addTipper = function (user) { var tipperObj = {user:user,total:0}; tipperList.push(tipperObj); return findTipper(user); } var addAmountToTipper = function(tipperListId,amount) { var amountReached = false; if (cb.settings.score_kind == 'total tipped amount') { tipperList[tipperListId].total += amount; if (tipperList[tipperListId].total >= cb.settings.minimal_tip_amount) amountReached = true; } else { if (amount >= cb.settings.minimal_tip_amount) { tipperList[tipperListId].total += amount; amountReached = true; } } return {amountReached:amountReached,total:tipperList[tipperListId].total}; } var displayGoalNotice = function () { var tipperGoalProgress=''; var totalNeeded=0; for (i=0;i<totalCorrectTippers;i++) { // tipperGoalProgress += 'x'; //tipperGoalProgress += '\u2589'; tipperGoalProgress += '\u2588'; } for (;i<cb.settings.number_of_tippers;i++) { // tipperGoalProgress += '-'; // tipperGoalProgress += '\u259A'; tipperGoalProgress += '|'; } tipperGoalProgress += (' (' + totalCorrectTippers + ' / ' + cb.settings.number_of_tippers + ')'); cb.sendNotice('Tipper goal: ' + cb.settings.goal_description ,'','',colorNotice); // cb.sendNotice('Progress: ' + tipperGoalProgress); cb.sendNotice('Progress: ' + tipperGoalProgress, '', '', colorNotice); totalNeeded = cb.settings.number_of_tippers - totalCorrectTippers; if (totalNeeded < 6) { if (totalNeeded>1) cb.sendNotice('Still ' + totalNeeded + ' unique tippers needed to reach goal', '', '', colorNotice); else cb.sendNotice('Still one more tipper needed to reach goal', '', '', colorNotice); } if (cb.settings.score_kind == 'total tipped amount') { cb.sendNotice('Tip a total of ' + cb.settings.minimal_tip_amount + ' tokens to advance the unique tipper goal', '', '', colorNotice); } else { cb.sendNotice('Tip a total of ' + cb.settings.minimal_tip_amount + ' tokens in one tip to advance the unique tipper goal', '', '', colorNotice); } if (cb.settings.notifier_time_out > 0) { timeoutId = cb.setTimeout(displayGoalNotice, cb.settings.notifier_time_out * 1000); } } var checkGoal = function () { totalCorrectTippers=0; for (var i = 0; i < tipperList.length; i++) { if (tipperList[i].total >= cb.settings.minimal_tip_amount) { totalCorrectTippers++; } } if (totalCorrectTippers >= cb.settings.number_of_tippers) { //goal is reached cb.sendNotice('Tipper goal has been reached!!','','',colorNotice) //reset tipperlist tipperList = []; totalCorrectTippers=0; cb.cancelTimeout(timeoutId); } else { } } var total_tipped = 0; cb.onTip(function (tip) { var total_tipped=0, user='', tippedAmount=0, tipperListId=0, newTotal=0; user = tip.from_user; tippedAmount = parseInt(tip.amount); total_tipped += tippedAmount; tipperListId = findTipper(user); if (tipperListId===false) { tipperListId=addTipper(user); newTotal = addAmountToTipper(tipperListId,tippedAmount); if (cb.settings.notice_new_tipper == 'yes') { cb.sendNotice("Thank you new Tipper " + user + ' for tipping','','',colorNotice); if (!newTotal.amountReached) { if (cb.settings.score_kind == 'total tipped amount') { cb.sendNotice('Tip a total of ' + cb.settings.minimal_tip_amount + ' tokens to advance the unique tipper goal','','',colorNotice); } else { cb.sendNotice('Tip a total of ' + cb.settings.minimal_tip_amount + ' tokens in one tip to advance the unique tipper goal','','',colorNotice); } } } // cb.sendNotice("Thank you new Tipper " + user + 'for tipping'); } else { addAmountToTipper(tipperListId,tippedAmount); // cb.sendNotice("Thank you " + tip['from_user'] + 'for tipping again. Your total = ' + tipperList[tipperListId].total); } // cb.sendNotice(tipperList); checkGoal(); }); cb.onMessage(function (message) { var str = ''; var posSpace = 0; var command = ''; var info = ''; var isCommand=false; // Check is the user is the model if (message.user == cb.room_slug) { str = message.m.trim(); //check param if (str.substr(0, 3)=='/vb') { //we have a command start command = str; info = ''; posSpace = str.search(" "); if (posSpace>0) { command = str.slice(0, posSpace); info = str.slice(posSpace,str.length); } switch (command) { case '/vbdesc': cb.settings.goal_description = info; message['X-Spam'] = true; break; // name: 'goal_description', case '/vbtippers' : cb.settings.number_of_tippers = parseInt(info); message['X-Spam'] = true; break; case '/vbtokens' : cb.settings.minimal_tip_amount = parseInt(info); message['X-Spam'] = true; break; case '/vbtimeout' : cb.settings.notifier_time_out = parseInt(info); message['X-Spam'] = true; break; case '/vbrestart' : tipperList = []; totalCorrectTippers=0; displayGoalNotice(); message['X-Spam'] = true; break; case '/vbnotice' : displayGoalNotice(); message['X-Spam'] = true; break; case '/vbstop': message['X-Spam'] = true; tipperList = []; totalCorrectTippers=0; cb.cancelTimeout(timeoutId); break; case '/vbhelp' : message['X-Spam'] = true; var helpmessage=''; helpmessage += '/vbdesc new goal description \n'; helpmessage += '/vbtippers # number of minimum tippers \n' ; helpmessage += '/vbtokens # minimum amount for tips\n' ; helpmessage += '/vbtimeout # set notifier in seconds\n' ; helpmessage += '/vbrestart restarts setting all amounts to 0\n' ; helpmessage += '/vbnotice sends notice\n' ; helpmessage += '/vbstop stops the bot temporary\n'; cb.sendNotice(helpmessage, cb.room_slug); } } } if (isCommand) { } return message; }); function main() { if (BMO.init == false) { startUpBot(); BMO.init = true; } } main();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.