Bots Home
|
Create an App
Title Bot
Author:
bbftest
Description
Source Code
Launch Bot
Current Users
Created by:
Bbftest
//Set up choices on the launch page cb.settings_choices = [ {name: 'users', type: 'str', label: 'List of users and titles (user1:user2@title1, user3@title2, ...)'}, {name: 'leftsep', type: 'str', label: 'Left separator:', default: '(', required: false}, {name: 'rightsep', type: 'str', label: 'Right separator:', default: ')', required: false}, {name: 'placement', type: 'choice', label: 'Title placement:', choice1: 'before message',choice2:'after message',default: 'before message'}, {name: 'showtip', type: 'choice', label: 'Display tips:', choice1: 'yes',choice2:'no',default: 'no'}, {name: 'tipsep', type: 'str', label: 'Tip separator (only applies if the user has a title and yes is selected above)', default: '|'}, {name: 'kingtitle', type: 'str', label: 'Custom title for highest tipper (disabled if left blank):',default: 'Tip King', required: false}, {name: 'showcrown', type: 'choice', label: 'Show crown for highest tipper:', choice1: 'yes',choice2:'no',default: 'yes'} ]; var userbase={}; var highest_tip=0; var king; //Iterate through each user and enter their user name and title into the userbase addTitles(cb.settings.users); cb.onMessage(function (msg) { var user=msg['user']; var message=msg['m']; var addin='', title='', tipsep='',tips='',crown=''; if (user==cb.room_slug) { if (message.substring(0,6)=='/title') { addTitles(message.substring(7)); cb.sendNotice('Room owner '+cb.room_slug+' has updated one or more titles.'); msg['X-Spam']=true; return; } else if (message=='/getlist') { sendList(); msg['X-Spam']=true; return; } } if (user in userbase) { if ('title' in userbase[user]) title=userbase[user]['title']; if (cb.settings.showtip && 'tips' in userbase[user]) { tips=userbase[user].tips; if ('tips' in userbase[user]) { tips=userbase[user]['tips']; if (title != '') tipsep=' '+cb.settings.tipsep+' '; } } if (user==king && cb.settings.kingtitle != '') { title=cb.settings.kingtitle; if (cb.settings.showcrown=='yes') crown=':smallCrown ' } var addin=cb.settings.leftsep+title+tipsep+tips+cb.settings.rightsep; if (cb.settings.placement=='before message') msg['m']=addin+' '+message; else msg['m']=message+' '+addin; } msg['m']=crown+msg['m']; return msg; }); cb.onTip(function (tip) { var tipper=tip['from_user']; var amount=tip['amount']; var kingtitle=cb.settings.kingtitle; if (tipper in userbase) { if ('tips' in userbase[tipper]) userbase[tipper]['tips']+=amount; else userbase[tipper]['tips']=amount; } else { userbase[tipper]={'tips':amount}; } if (kingtitle != '' && userbase[tipper]['tips'] > highest_tip) { highest_tip=userbase[tipper]['tips']; if (tipper != king) cb.sendNotice(tipper+' is now '+kingtitle+'!'); king=tipper; } }); function sendList() { var list=''; copybase=clone(userbase); while (Object.keys(copybase).length>0) { for (user in copybase) break; search_title=copybase[user]['title']; for (user2 in copybase) { title2=copybase[user2]['title']; if (title2==search_title) { list=list+user2+":"; delete copybase[user2]; } } list=list.substring(0,list.length-1); //trim last colon list=list+'@'+search_title+','; } list=list.substring(0,list.length-1); //trim last comma cb.sendNotice('(Sent to room owner - '+cb.room_slug+') List of users with their titles including ones added in this session: '+list,cb.room_slug); } function addData(user,property,data) { cb.sendNotice(property); if (user in userbase) userbase[user][property]=data; else { userbase[user]={}; userbase[user][property]=data; } } function addTitles(input) { var entries=String(input).split(','); for (i in entries) { index=entries[i].indexOf('@') u=entries[i].substring(0,index).split(':'); for (j in u) addData(u[j].trim(),"title",entries[i].substring(index+1).trim()); } } function clone(obj) { var target = {}; for (var i in obj) { if (obj.hasOwnProperty(i)) { target[i] = obj[i]; } } return target; }
© Copyright Chaturbate 2011- 2024. All Rights Reserved.