Bots Home
|
Create an App
asdad1231
Author:
eddietest1
Description
Source Code
Launch Bot
Current Users
Created by:
Eddietest1
/** * Bot: Chatroom Stats * Version: 1.0 * Author: gargoyle1 * Date: 03.03.16 */ var minutes = []; var mcount = 0; var token_hours = []; var total_tokens = 0; var total_tips = 0; var average_tokens = 0; var average_tiptime = 0; var average_tokentime = 0; var high_tip = 0; var high_tipper = 'nobody'; var darkpurple_user = 0; var lightpurple_user = 0; var darkblue_user = 0; var lightblue_user = 0; var grey_user = 0; var highactual_user = 0; var color; var orange = '#db5300'; var red = '#dd0000'; var green = '#029903'; var lightblue = '#6699aa'; var darkblue = '#000099'; var lightpurple = '#be6bff'; var darkpurple = '#824bab'; var grey = '#494949'; var yellow = '#ffff33'; var visitors = []; var tippers = []; var count = -1; var toprank = 0; var message; var time = -1; var timeinmin = 0; var hours = 0; var minutes = 0; cb.onEnter(function(user) { checkentry(user); if ((count+1) > highactual_user) { highactual_user = count+1; } }); cb.onLeave(function(user) { checkleave(user); }); cb.onTip(function (tip) { total_tips++; total_tokens += parseInt(tip['amount']); tipsbytime(tip); hightipper(tip); checkvisitortip(tip); checktipper(tip); }); cb.onMessage(function (msg) { if (msg['m'].indexOf("!") == 0 && (msg['user'] == cb.room_slug || msg['is_mod'])) { message = msg['m'].split(' '); if (msg['m'] == '!c') { msg['X-Spam'] = true; cb.sendNotice('!topv # = shows you time ranking in chatroom (# = number of top, e.g. /topv 10)', msg['user'], '', '', ''); cb.sendNotice('!topt # = shows you top tipper (# = number of top, e.g. /topt 10)', msg['user'], '', '', ''); cb.sendNotice('!stats = shows you the tip statistics of your chatroom', msg['user'], '', '', ''); cb.sendNotice('!graph = shows you the tip graph by hours', msg['user'], '', '', ''); cb.sendNotice('!visits = shows you the visit statistics of your chatroom', msg['user'], '', '', ''); } else if (msg['m'] == '!stats') { msg['X-Spam'] = true; printstats(msg); } else if (msg['m'] == '!graph') { msg['X-Spam'] = true; printgraph(msg); } else if (msg['m'] == '!visits') { msg['X-Spam'] = true; printvisits(msg); } else if (message[0] == '!topv') { msg['X-Spam'] = true; if (count < message[1] || message[1] == 'all') { toprank = count; } else if (message[1] == undefined) { if (count < 9) { toprank = count; } else { toprank = 9; } } else { toprank = message[1] - 1; } printtimetop(msg); } else if (message[0] == '!topt') { msg['X-Spam'] = true; var x = tippers.length - 1; if (x < message[1] || message[1] == 'all') { toprank = x; } else if (message[1] == undefined) { if (x < 9) { toprank = x; } else { toprank = 9; } } else { toprank = message[1] - 1; } printtokentop(msg); } } }); function timer() { time++; cb.setTimeout(timer, 60000); checktime(); } function converttime() { timeinmin = time; hours = Math.floor(timeinmin/60); minutes = timeinmin - (hours * 60); } function converttimex() { hours = Math.floor(timeinmin/60); minutes = timeinmin - (hours * 60); } function checkentry(user) { count++; visitors[count] = new Object (); visitors[count]['name'] = user['user']; visitors[count]['staytime'] = 0; visitors[count]['usertip'] = 0; if (user['tipped_tons_recently']) { color = darkpurple; darkpurple_user++; } else if (user['tipped_alot_recently']) { color = lightpurple; lightpurple_user++; } else if (user['tipped_recently']) { color = darkblue; darkblue_user++; } else if (user['has_tokens']) { color = lightblue; lightblue_user++; } else { color = grey; grey_user++; } visitors[count]['usercolor'] = color; } function checkleave(user) { for (var i=0; i<=count; i++) { if (visitors[i]['name'] == user['user']) { visitors.splice(i,1); visitors.sort(function(a, b){return b.staytime-a.staytime}); count--; } } } function checktime() { for (var i=0; i<=count; i++) { visitors[i]['staytime']++; } } function checktipper(tip) { var newtipper = true; var x = tippers.length; if (tip['from_user_tipped_tons_recently']) { color = darkpurple; } else if (tip['from_user_tipped_alot_recently']) { color = lightpurple; } else if (tip['from_user_tipped_recently']) { color = darkblue; } else if (tip['from_user_has_tokens']) { color = lightblue; } else { color = grey; } for (var i=0; i<x; i++) { if (tippers[i]['name'] == tip['from_user']) { tippers[i]['usertip'] += parseInt(tip['amount']); tippers[i]['usercolor'] = color; newtipper = false; cb.sendNotice(tippers[i]['name'] + ' tipped \u2211 ' + tippers[i]['usertip'] + ' tokens', cb.room_slug, yellow, red, 'bold'); } } if (newtipper) { tippers[x] = new Object (); tippers[x]['name'] = tip['from_user']; tippers[x]['usertip'] = parseInt(tip['amount']); tippers[x]['usercolor'] = color; } tippers.sort(function(a, b){return b.usertip-a.usertip}) } function checkaverage() { average_tokens = Math.round(total_tokens/total_tips); average_tiptime = Math.round(time/total_tips); average_tokentime = Math.round(total_tokens/time*60); } function checkvisitortip(tip) { for (var i=0; i<=count; i++) { if (visitors[i]['name'] == tip['from_user']) { visitors[i]['usertip'] += parseInt(tip['amount']); } } } function printtimetop(msg) { for (var i=0; i<=toprank; i++) { timeinmin = visitors[i]['staytime']; converttimex(); cb.sendNotice(i+1 + '. ' + visitors[i]['name'] + ' - ' + visitors[i]['usertip'] + ' tokens - ' + hours + ' h ' + minutes + ' min', msg['user'], '', visitors[i]['usercolor'], ''); } } function printtokentop(msg) { for (var i=0; i<=toprank; i++) { cb.sendNotice(i+1 + '. ' + tippers[i]['name'] + ' - ' + tippers[i]['usertip'] + ' tokens', msg['user'], '', tippers[i]['usercolor'], ''); } } function tipsbytime(tip) { converttime(); if (token_hours[hours] == undefined) { token_hours[hours] = new Object (); token_hours[hours]['tips'] = 0; token_hours[hours]['token'] = 0; } token_hours[hours]['tips'] += 1; token_hours[hours]['token'] += parseInt(tip['amount']); } function hightipper(tip) { if (tip['amount'] > high_tip) { high_tip = tip['amount']; high_tipper = tip['from_user']; } } function printstats(msg) { converttime(); checkaverage(); cb.sendNotice('\u2211 ' + hours + ' h ' + minutes + ' min - ' + total_tokens + ' tokens - ' + total_tips + ' tips', msg['user'], '', '', ''); cb.sendNotice('\u2205 ' + average_tokens + ' Token/Tip - ' + average_tiptime + ' min/Tip - ' + average_tokentime + ' Token/h', msg['user'], '', '', ''); cb.sendNotice('\u22A4 ' + high_tip + ' tokens (' + high_tipper + ')', msg['user'], '', '', ''); } function printvisits(msg) { cb.sendNotice('\u22A4 ' + highactual_user + ' User', msg['user'], '', '', ''); cb.sendNotice('\u2211 ' + darkpurple_user + ' User', msg['user'], '', darkpurple, ''); cb.sendNotice('\u2211 ' + lightpurple_user + ' User', msg['user'], '', lightpurple, ''); cb.sendNotice('\u2211 ' + darkblue_user + ' User', msg['user'], '', darkblue, ''); cb.sendNotice('\u2211 ' + lightblue_user + ' User', msg['user'], '', lightblue, ''); cb.sendNotice('\u2211 ' + grey_user + ' User', msg['user'], '', grey, ''); } function printgraph(msg) { converttime(); var max = 0; for (var i=0; i<=hours; i++) { if (token_hours[i] == undefined) { token_hours[i] = new Object (); token_hours[i]['tips'] = 0; token_hours[i]['token'] = 0; } if (token_hours[i]['token'] > max) { max = token_hours[i]['token']; } } var blocksize = max/10; for (var i=0; i<=hours; i++) { if (blocksize == 0) { blocks = 0; } else { blocks = Math.floor(token_hours[i]['token']/blocksize) } if (blocks <= 2) { color = red; } else if (blocks <= 6) { color = orange; } else { color = green; } var graph = '|'; for (var n=0; n<blocks; n++) { graph += '[]' } for (var n=0; n<(10-blocks); n++) { graph += '\u00A0\u00A0' } graph += '\u00A0\u00A0\u00A0' + (i+1) + '. h (' + token_hours[i]['token'] + ' tokens / ' + token_hours[i]['tips'] + ' tips)' cb.sendNotice(graph, msg['user'], '', color, ''); } } function init() { timer(); } init();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.