Bots Home
|
Create an App
UserList
Author:
ptest
Description
Source Code
Launch Bot
Current Users
Created by:
Ptest
// // userlist bot // // the userlist function is sometimes broken for models and users // this bot tracks enter and exit of a room and provides a way // to list the users with tokens that are now in the room // // used during bot development to send a copy of messages // generated to the dev var dev='phredo'; //var dev='ptestviewer2'; // variables // commented out are for functions not working var initialize=0; // var viewerListSpam=0; // var viewerListTimer = parseInt(cb.settings.viewerListSpamTimer); var purple = "#C287C2"; //original color: #B369B3 var viewerArray = new Array; var numViewers = 0; var notifyToggle=0; // 0 off 1 on // settings page choices { cb.settings_choices = [ {name: 'enterExitToggle', label: 'Would you like the bot to write when users with tokens enter and exit the room?', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes'}, /* {name: 'viewerListSpam', label: 'Do you want to periodically print the list of viewers with tokens?', type: 'choice', choice1: 'Yes', choice2: 'No', defaultValue: 'Yes'}, {name: 'viewerListSpamTimer', label: 'Change this value if you would like the Viewer List announcement to happen at a different interval:', type: 'int', minValue: 1, maxValue: 60, defaultValue: 5} */ ] } // functions function viewerArrayPopulate(user) { // cb.sendNotice('debug.viewerArrayPopulate arrived with user '+user); viewerArray[numViewers] = new Array; viewerArray[numViewers][0] = user; // cb.sendNotice('debug.viewerArrayPopulate: added '+user+' to viewerArray'); numViewers++ } function findViewer(user) { // cb.sendNotice('debug.findViewer we are in findviewer with user '+user); //find the index of the user for(var i = 0; i < viewerArray.length; i++) { if(viewerArray[i][0] == user) { // cb.sendNotice('debug.findViewer: '+user+' in viewerArray'); break; } } //the user is not in the array. add him and call findViewer if((i == viewerArray.length) && (user != cb.room_slug)) { // cb.sendNotice('debug.findViewer'+user+'not in viewerArray we are calling viewerArrayPopulate'); viewerArrayPopulate(user); findViewer(user); } return i; } function deleteViewer(user) // // deletes viewer from array, called when they exit the room // { //find the index of the user and delete for(var i = 0; i < viewerArray.length; i++) { if(viewerArray[i][0] == user) { // cb.sendNotice('debug.deleteViewer: '+user+' in viewerArray'); if (i > -1) { viewerArray.splice(i,1); numViewers--; } break; } } } // function printViewers function printViewers(user) { if (viewerArray.length==0) { cb.sendNotice('No active viewers with tokens known to be in room.',user); } else { cb.sendNotice( (viewerArray.length).toString()+' viewers with tokens currently known to be in room.',user); } for(var i = 0; i < viewerArray.length; i++) { if (viewerArray[0][0]=="") { // cb.sendNotice('No viewers known since bot started'); } else { cb.sendNotice((i+1).toString()+". "+viewerArray[i][0],user); } } } // onMessage { cb.onMessage(function (msg) { //turn the message into an array var message = msg['m'].split(' '); //0 = invalid command, 1 = valid command var cmd = 0; var symbolString = '~`!@#$%^&*()_-+={[}]|\\:;"\'<,>.?/'; //check to see if the user is attempting to use a command if(message[0].charAt(0) == '/') { //don't print this message to chat msg['X-Spam'] = true; switch(message[0]) { case '/printusers': case '/printviewers': { //user entered a proper command cmd = 1; // cb.sendNotice ('goto function printviewers\n'); printViewers(msg['user']); break; } case '/notifyoff': { cmd = 1 //permission check if(msg['is_mod'] || msg['user'] == cb.room_slug || msg['user']==dev) { notifyToggle=0; cb.sendNotice('notify off',cb.room_slug); cb.sendNotice('notify off',dev); } else { // unauthorized user } break; } case '/notifyon': { cmd = 1 if(msg['is_mod'] || msg['user'] == cb.room_slug || msg['user']==dev) { notifyToggle=1; cb.sendNotice('notify on',cb.room_slug); cb.sendNotice('notify on',dev); } else { // unauthorized user } break; } } } // add person to viewer array when they talk if they have tokens and are missing if (msg['has_tokens']) { findViewer(msg['user']); } return msg; }); } /* function viewerSpam() { cb.setTimeout(viewerListSpamTimer,cb.settings.viewerListSpamTimer*60000); } function viewerListSpamTimer() { if (viewerListSpam==1){ cb.sendNotice('spam goes here'); } viewerSpam(); } */ // onEnter cb.onEnter(function(user) { if(user['has_tokens']) { if (notifyToggle == 1){ cb.sendNotice(user['user']+' has joined the room.',cb.room_slug) cb.sendNotice(user['user']+' has joined the room.',dev) } findViewer(user['user']); } }); // onleave cb.onLeave(function(user) { if(user['has_tokens']) { if (notifyToggle == 1){ cb.chatNotice(user['user'] + ' has left the room.',cb.room_slug); cb.chatNotice(user['user'] + ' has left the room.',dev); } deleteViewer(user['user']); } }); //init { if(initialize == 0) { /* if(cb.settings.viewerListSpam == 'Yes') { viewerlistSpam = 1; viewerSpam(); } */ if (cb.settings.enterExitToggle == 'Yes') { notifyToggle=1; } else { notifyToggle=0; } cb.sendNotice('This bot tracks users with tokens in a room as they enter or leave so the broadcaster can know who (with tokens) is in the room when the userlist is broken. It does not track grey users or users without tokens. /notifyon /notifyoff /printviewers', cb.room_slug, purple); initialize = 1; } }
© Copyright Chaturbate 2011- 2024. All Rights Reserved.