Bots Home
|
Create an App
Nikki_DavisXO Stop/Go Game
Author:
caniac71
Description
Source Code
Launch Bot
Current Users
Created by:
Caniac71
/********************************************* <b><u>Nikki Davis Stop/Go Game</u></b> <p>This is a bot create to support Nikki_DavisXO's Stop/Go Game</p> scheduleUpdate <p>Bot will display a go message for even tips over 10 tokens, and will show a stop message for odd tips over 10 tokens.</p> <p>Keeps track of all tips and will show a leaderboard of the top tippers for Team Go, top tippers for Team Stop, and the top overall tippers. The top 3 can be printed on a fixed interval. </p><p>Users can view the full leaderboard using the "/lb" command.</p> <p><u>These are the settings:</u> </p><p><b>Print the leaderboards once every (minutes, 0 to disable)</b> </p><p>Time (in minutes) to automatically print the leaderboards. </p><p>Setting this value to 0 disables this feature. </p> Version history: 12 Sept 2015; v1.0; first version created for nikki_davisxo *********************************************/ var VERSION = '1.0', COMMAND_SHOW_LEADERBOARD = '!lb', CONFIG_COLOR_LEADER = '#9f9', INTERVAL_MULTIPLIER = 60000, NL = '\n', last_top3 = '', leader_username, update_counter = 0, interval_counter = 0, silent_room = true, user_total_tips = {}, teamgo_total_tips = {}, teamstop_total_tips = {}, user_last_tip_time = {}; var TEAM_GO_COLOR = '#34a12c'; var TEAM_GO_MSG = ':GoSignSmall *** GO!!! *** :GoSignSmall'; var TEAM_GO_GRAPHIC = ':NDXOTeamGoLB'; var TEAM_STOP_COLOR = '#ff0000'; var TEAM_STOP_MSG = ':StopSignSmall *** STOP!!! *** :StopSignSmall'; var TEAM_STOP_GRAPHIC = ':NDXOTeamStopLB'; //var OVERALL_COLOR = '#000000'; var OVERALL_COLOR = '#fb1d98'; var OVERALL_GRAPHIC = ':NDXOOverallLB'; cb.settings_choices = [{ name: 'print_interval', type: 'int', minValue: 0, defaultValue: 10, label: "Print leader boards once every (minutes, 0 to disable)", required: true }]; //handlers cb.onTip(function (tip) { handleTip(tip.amount, tip.from_user); //scheduleUpdate(); silent_room = true; }); cb.onMessage(function (msg) { cb.log(msg); cb.log('In onMessage'); var message = msg['m'].split(' '); //0 = invalid command, 1 = valid command var cmd = 0; //1 = user is already silenced var silenced = 0; var symbolString = '~`!@#$%^&*()_-+={[}]|\\:;"\'<,>.?/'; // handle user commands if(message[0].charAt(0) == '/') { cb.log('In If Statement'); //don't print this message to chat msg['X-Spam'] = true; switch(message[0]) { case '/lb': { //user entered a proper command cmd = 1; sendLeaderboards(true, msg['user']); break; } /* case '/simtip': { cb.log('In Tip Case'); //user entered a proper command cmd = 1; handleTip(parseInt(message[1]),message[2]); break; } */ } } // highlight leader //if ((cb.settings.highlight == 'yes') && (msg.user == leader_username)) { // msg.background = CONFIG_COLOR_LEADER; //} // schedule interval //if (update_counter == 0){ // scheduleInterval(); //} if (!msg['X-Spam']){ silent_room = false; } return msg; }); //custom functions function handleTip(amount, user) { cb.log('In Handle Tip'); if (amount <= 0) return; updateOverallTips(amount,user); if(amount > 10){ checkIfTeamGoTip(amount, user); checkIfTeamStopTip(amount,user); } user_last_tip_time[user] = new Date().valueOf(); } function updateOverallTips(amount, user) { var before = user_total_tips[user] || 0, after = user_total_tips[user] = before + amount; } function updateTeamGoTips(amount, user) { var before = teamgo_total_tips[user] || 0, after = teamgo_total_tips[user] = before + amount; } function updateTeamStopTips(amount, user) { var before = teamstop_total_tips[user] || 0, after = teamstop_total_tips[user] = before + amount; } function sortLeaderboard(tipperList){ var lb = []; for (var user in tipperList) { if (tipperList.hasOwnProperty(user)){ lb.push([tipperList[user], -user_last_tip_time[user], user]); } } if (lb.length > 0){ lb.sort(function(a, b){ for (var i=0; i < a.length; i++){ if (a[i] < b[i]){ return 1; } if (a[i] > b[i]){ return -1; } } return 0; }); } return lb; } function formatRanking(leaderboard, rank){ if (rank < leaderboard.length) { var p = leaderboard[rank]; return p[2] + ' (' + p[0] + ' token' + (p[0]!=1 ? 's' : '') + ')'; } else { return '--'; } } function getTop3(leaderboard){ var rank, result=''; for (rank=0; rank<3; rank++){ if (rank>0){ result += '|'; } if (rank < leaderboard.length){ result += leaderboard[rank][2]; } } return result; } function scheduleInterval(){ cb.log('--> scheduleInterval'); var interval = cb.settings.print_interval; if (interval > 0) { var counter = ++interval_counter; cb.setTimeout(function(){ if (interval_counter == counter){ sendLeaderboards(!silent_room); } }, interval*INTERVAL_MULTIPLIER); silent_room = true; } cb.log('<-- scheduleInterval'); } function checkIfTeamGoTip(amount, user){ cb.log('In Team Go'); var result = amount % 2; if(result == 0){ cb.sendNotice(TEAM_GO_MSG,'', '',TEAM_GO_COLOR, 'bold'); updateTeamGoTips(amount,user); } } function checkIfTeamStopTip(amount, user){ cb.log('In Team Stop'); var result = amount % 2; if(result == 1){ cb.sendNotice(TEAM_STOP_MSG,'', '',TEAM_STOP_COLOR, 'bold'); updateTeamStopTips(amount,user); } } function sendLeaderboards(force, to_user){ sendTeamGoLB(force, to_user); sendTeamStopLB(force, to_user); sendOverallLB(force, to_user); if (to_user == undefined){ scheduleInterval(); } } function sendTeamGoLB(force, to_user) { var lb = sortLeaderboard(teamgo_total_tips), l = to_user ? lb.length : 3, out = TEAM_GO_GRAPHIC + ' '; /* if (!force) { var top3 = getTop3(lb); if (top3 == last_top3){ return; } last_top3 = top3; } */ //cb.sendNotice(':NDXOTopTippers2',to_user,'','#FF439F','bold'); for (var rank=0; rank<3; rank++) { out += NL + '' + (rank+1) + '. ' + formatRanking(lb, rank); //cb.sendNotice(out,to_user,'','#FF439F','bold'); } //cb.sendNotice(out,to_user,'','#000000','bold'); cb.sendNotice(out,to_user,'',TEAM_GO_COLOR,'bold'); } function sendTeamStopLB(force, to_user) { var lb = sortLeaderboard(teamstop_total_tips), l = to_user ? lb.length : 3, out = TEAM_STOP_GRAPHIC + ' '; /* if (!force) { var top3 = getTop3(lb); if (top3 == last_top3){ return; } last_top3 = top3; } */ //cb.sendNotice(':NDXOTopTippers2',to_user,'','#FF439F','bold'); for (var rank=0; rank<3; rank++) { out += NL + '' + (rank+1) + '. ' + formatRanking(lb, rank); //cb.sendNotice(out,to_user,'','#FF439F','bold'); } //cb.sendNotice(out,to_user,'','#000000','bold'); cb.sendNotice(out,to_user,'',TEAM_STOP_COLOR,'bold'); } function sendOverallLB(force, to_user) { var lb = sortLeaderboard(user_total_tips), l = to_user ? lb.length : 3, out = OVERALL_GRAPHIC + ' '; /* if (!force) { var top3 = getTop3(lb); if (top3 == last_top3){ return; } last_top3 = top3; } */ //cb.sendNotice(':NDXOTopTippers2',to_user,'','#FF439F','bold'); for (var rank=0; rank<3; rank++) { out += NL + '' + (rank+1) + '. ' + formatRanking(lb, rank); //cb.sendNotice(out,to_user,'','#FF439F','bold'); } cb.sendNotice(out,to_user,'',OVERALL_COLOR,'bold'); } function init(){ scheduleInterval(); } init();
© Copyright Chaturbate 2011- 2026. All Rights Reserved.