Bots Home
|
Create an App
ChatturRoyale
Author:
misc_
Description
Source Code
Launch Bot
Current Users
Created by:
Misc_
/********************************************* ChatturRoyale --------------- Limits number of Viewers by kicking those ranked lowest. User rank determined by tip amount. Acounts with zero tips are sorted by viewing time. (Longer viewing ranked the lower) A countdown begins before the purge to incentivise users to climb the ranks. Larger differrnce between minimum and maximum viewers reduces frequency of purge. PURGE_TIMER=10 MIN=20 MAX=50 Room Target is between $MIN and $MAX Viewers. The lowest rank who has been viewing the longest will be purged. Increase your rank by making an account and tipping. Type /rank to see your position Reducing to $MIN Viewers in $PURGE_COUNTDOWN seconds. Increase your rank by making an account and tipping. Purge Complete: $PURGED_USERS kicked from room /rank you have tipped $X and are ranked #. Viewing for X Minuets. No goals, nothing to configure. Version history: *********************************************/ var IAMBOT = false, COMMAND_SHOW_LEADERBOARD = '!lb', CONFIG_COLOR_LEADER = '#9f9', NL = '\n', user_total_tips = {}, user_last_tip_time = {}, last_top3 = '', leader_username, draw_leaderboard_counter = 0; cb.settings_choices = [ {label: "Some String", name:'MIN_USER', type:'int', minValue:1, maxValue:50000}, {label: "Some String", name:'MAX_USER', type:'int', minValue:1, maxValue:50000}, {label: "Some String", name:'PURGE_TIMER', type:'int', minValue:60, maxValue:600} ]; //handlers cb.onTip(function (tip) { handleTip(tip.amount, tip.from_user); IAMBOT ? scheduleDrawLeaderboard(5000) : cb.drawPanel(); }); if (!IAMBOT) { cb.onDrawPanel(function (user) { var lb = sortLeaderboard(); return { 'template': '3_rows_of_labels', 'row1_label': 'Tip leader:', 'row1_value': formatRanking(lb, 0), 'row2_label': 'Runner up:', 'row2_value': formatRanking(lb, 1), 'row3_label': 'Third place:', 'row3_value': formatRanking(lb, 2) }; }); } cb.onMessage(function (msg) { // user commands if ((msg.m.indexOf(COMMAND_SHOW_LEADERBOARD) == 0) && !msg['X-Spam']) { drawLeaderboard(true, msg.user); msg['X-Spam'] = true; } if (!IAMBOT && (msg.user == leader_username)) { msg.background = CONFIG_COLOR_LEADER; } return msg; }); function handleTip(amount, user) { user_total_tips[user] = (user_total_tips[user] || 0) + amount; user_last_tip_time[user] = new Date().valueOf(); } function sortLeaderboard(){ var lb = []; for (var user in user_total_tips) { if (user_total_tips.hasOwnProperty(user)){ lb.push([user_total_tips[user], -user_last_tip_time[user], user]); } } if (lb.length > 0){ lb.sort(function(a, b){ var r,i; for (i=0; i < a.length; i++){ if (a[i] < b[i]){ return 1; } if (a[i] > b[i]){ return -1; } } return 0; }); leader_username = lb[0][2]; } 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){ var p = leaderboard[rank]; result += leaderboard[rank][2]+':'+leaderboard[rank][0] } } return result; } function drawLeaderboard(full, to_user) { var rank, lb = sortLeaderboard(), l = full ? lb.length : 3, out = 'Tippers leaderboard'; if (!full && !to_user){ var top3 = getTop3(lb); if (top3 == last_top3){ return; } last_top3 = top3; } if (l<3) { l=3; } if (l < lb.length) { out += ' top 3 (Type !lb to see the full leaderboard)'; } for (rank=0; rank<l; rank++) { out += NL + '' + (rank+1) + '. ' + formatRanking(lb, rank); } cb.chatNotice(out, to_user); } function scheduleDrawLeaderboard(timeout){ var counter = ++draw_leaderboard_counter; cb.setTimeout(function(){ if (draw_leaderboard_counter == counter){ draw_leaderboard_counter = 0; drawLeaderboard(); } }, timeout); } function init(){ if (!IAMBOT) { cb.drawPanel(); } } init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.