Bots Home
|
Create an App
Chatroom Visit Time
Author:
gargoyle1
Description
Source Code
Launch Bot
Current Users
Created by:
Gargoyle1
/** * Bot: Chatroom Visit Time * Version: 1.0 * Author: gargoyle1 * Date: 23.12.15 */ var visitors = []; var count = -1; var time = -1; var toprank = 0; var timeinmin; var hours; var minutes; colname = new Array('black','grey','blue','green','red','fire-red','pink'); colcode = new Array('#000000','#666699','#003399','#669a5e','#b84040','#ff0000','#ff6699'); var textcolor = '#669a5e'; cb.settings_choices = [ {name:'color', type:'choice', label:'Note Color', choice1:'black', choice2:'grey', choice3:'blue', choice4:'green', choice5:'red', choice6:'fire-red', choice7:'pink', defaultValue:'green', required:false}, {name: 'timeset', type:'int', label:'Visit time (minutes) [set 0 for no prize!]', minValue:0, maxValue:999, defaultValue:60}, {name: 'prize', type:'str', minLength:1, maxLength:255, label:'Prize for loality', defaultValue:'', required:false}, {name:'nogreys', type:'choice', label:'Count', choice1:'all', choice2:'no greys', defaultValue:'all', required:false}, {name:'showwin', type:'choice', label:'Show winner', choice1:'all', choice2:'only you', defaultValue:'all', required:false}, ]; cb.onEnter(function(user) { if ((cb.settings.nogreys == 'no greys') && (!user['has_tokens']) && (!user['is_mod']) && (!user['in_fanclub']) && (user['user'] != cb['room_slug'])) { } else { welcome(user); checkentry(user); } }); cb.onLeave(function(user) { checkleave(user); }); cb.onMessage(function (msg) { if (msg['user'] == cb.room_slug || msg['is_mod']) { var message = msg['m'].split(' '); if (msg['m'] == '!c') { msg['X-Spam'] = true; cb.sendNotice('!top # = show you time ranking in chatroom (# = number of top, e.g. /top 10)', msg['user'], '', '', ''); cb.sendNotice('!topall # = show everybody time ranking in chatroom', msg['user'], '', '', ''); cb.sendNotice('!runtime = show the time, this bot is running', msg['user'], '', '', ''); cb.sendNotice('!time = show your own time in chatroom (command for everybody)', msg['user'], '', '', ''); cb.sendNotice('!reset = set time for everybody in the list to 0', msg['user'], '', '', ''); cb.sendNotice('!set name # = set time of someone to a specific value (e.g. /set gargoyle1 0)', msg['user'], '', '', ''); cb.sendNotice('!color x = set color to x (name (black, grey, blue, green, red fire-red & pink) or code e.g. #FF6699)', msg['user'], '', '', ''); } if (msg['m'] == '!runtime') { msg['X-Spam'] = true; timeinmin = time; converttime(); cb.sendNotice('This bot is running for ' + hours + ' h ' + minutes + ' min!', msg['user'], '', textcolor, ''); } if (message[0] == '!color') { msg['X-Spam'] = true; cb.settings.color = message[1]; var codetest = message[1].split(''); if (codetest[0] == '#' && codetest.length == 7) { textcolor = message[1]; cb.sendNotice('Color set to code ' + textcolor + '!', msg['user'], '', textcolor, ''); } else { setcolor(); } } if (message[0] == '!top') { msg['X-Spam'] = true; if (count < message[1]) { toprank = count; } else if (message[1] == undefined) { if (count < 9) { toprank = count; } else { toprank = 9; } } else { toprank = message[1] - 1; } cb.sendNotice('Top list of continuous time in this chatroom!', msg['user'], '', textcolor, ''); for (var i=0; i<=toprank; i++) { timeinmin = visitors[i]['staytime']; converttime(); cb.sendNotice(hours + ' h ' + minutes + ' min - ' + visitors[i]['name'], msg['user'], '', textcolor, ''); } } if (message[0] == '!topall') { msg['X-Spam'] = true; if (count < message[1]) { toprank = count; } else if (message[1] == undefined) { if (count < 9) { toprank = count; } else { toprank = 9; } } else { toprank = message[1] - 1; } cb.sendNotice('Top list of continuous time in this chatroom!', '', '', textcolor, ''); for (var i=0; i<=toprank; i++) { timeinmin = visitors[i]['staytime']; converttime(); cb.sendNotice(hours + ' h ' + minutes + ' min - ' + visitors[i]['name'], '', '', textcolor, ''); } } if (message[0] == '!set') { msg['X-Spam'] = true; for (var i=0; i<=count; i++) { if (visitors[i]['name'] == message[1]) { visitors[i]['staytime'] = message[2]; } } } if (msg['m'] == '!reset') { msg['X-Spam'] = true; time = 0; for (var i=0; i<=count; i++) { visitors[i]['staytime'] = 0; } } } if (msg['m'] == '!time') { msg['X-Spam'] = true; for (var i=0; i<=count; i++) { if (visitors[i]['name'] == msg['user']) { timeinmin = visitors[i]['staytime']; converttime(); cb.sendNotice(hours + ' h ' + minutes + ' min - ' + visitors[i]['name'], msg['user'], '', textcolor, ''); } } } return msg; }); function welcome(user) { cb.sendNotice('Chatroom Visit Time by gargoyle1!', user['user'], '', textcolor, 'bold'); if (cb.settings.timeset > 0) { cb.sendNotice('Welcome to ' + cb.room_slug + 's chatroom! If you stay at least ' + cb.settings.timeset + ' minutes, ' + cb.room_slug + ' will do ' + cb.settings.prize + ' as a loality prize!', user['user'], '', textcolor, 'bold'); } cb.sendNotice('The command !time shows your continuous time in this chatroom!', user['user'], '', textcolor, 'bold'); } function checkentry(user) { count++; visitors[count] = new Object (); visitors[count]['name'] = user['user']; visitors[count]['staytime'] = 0; } 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 checkprize() { if (cb.settings.timeset > 0) { for (var i=0; i<=count; i++) { if (visitors[i]['staytime'] == cb.settings.timeset) { if (visitors[i]['name'] != cb.room_slug) { timeinmin = visitors[i]['staytime']; converttime(); if (cb.settings.showwin == 'only you') { cb.sendNotice(visitors[i]['name'] + ' is here for ' + hours + ' h ' + minutes + ' min and reached your set time for the prize of ' + cb.settings.prize + '!', cb.room_slug, '', textcolor, 'bold'); } else { cb.sendNotice(visitors[i]['name'] + ' is here for ' + hours + ' h ' + minutes + ' min and ' + cb.room_slug + ' will do ' + cb.settings.prize + ' as a loality prize!', '', '', textcolor, 'bold'); } } } } } } function timer() { time++; cb.setTimeout(timer, 60000); checktime(); checkprize(); } function converttime() { hours = Math.floor(timeinmin/60); minutes = timeinmin - (hours * 60); } function setcolor() { for(var i=0;i<=6;i++) { if (cb.settings.color == colname[i]) { textcolor = colcode[i]; cb.sendNotice('Color set to ' + cb.settings.color + '!', cb.room_slug, '', textcolor, ''); } } } function init() { setcolor(); timer(); } init();
© Copyright Chaturbate 2011- 2026. All Rights Reserved.