Bots Home
|
Create an App
teamtest
Author:
bob
Description
Source Code
Launch Bot
Current Users
Created by:
Bob
//Settings vars var maxTeams = 4; // Settings cb.settings_choices = [ {name:'tipOn',type:'choice', choice1:'On', choice2:'Off', defaultValue: 'Off',label: "Tip menu "}, {name:'tipNotifierOn',type:'choice', choice1:'On', choice2:'Off', defaultValue: 'Off',label: "Tip menu notifier "}, {name:'tipNotifierTime',type:'int', minValue:1, maxValue:99, defaultValue:1, label: "Time in minutes between notice being displayed "}, {name:'tipMenucolour', type:'str', minLength: 0, maxLength: 1000,defaultValue:'#ff0000', label: "Tip menu notice colour"}, {name:'tipFullMenucolour', type:'str', minLength: 0, maxLength: 1000,defaultValue:'#000000', label: "Tip menu full menu colour"}, {name:'tipMenuNotice', type:'str',required: false, minLength: 0, maxLength: 1000,defaultValue:'For the full tip menu type: #menu', label: "Notice for the line after your tip menu notifier is displayed, if there are no items set to display it will just show this notice"}, {name:'fanDiscountOn',type:'choice', choice1:'On', choice2:'Off', defaultValue: 'Off',label: "Fan club discount "}, {name:'tipSections', type:'str',required: false, minLength: 0, maxLength: 1000,defaultValue:'1)', label: "Enter all the sections for your tip menu, enter them with a number representing the order (do not use the same number twice) then a ) then the section name (can be multi word). seperate each section with a , eg 1)flashes,2)specials"}, {name:'tipMenuItems1', type:'str',required: false, minLength: 0, maxLength: 1000,defaultValue:'', label: "Enter menu items here, enter as item/price/section number/display/discount in chat, followed by a , item can be multi word, section number should be the number of the section in the above settings, display in chat is y if you want the msg displayed in the chat notifier and n if you want it only displayed on *menu, discount is a number0-100 it is the fanclub discount for this item, enter 0 if you want no discount ie boobs/25/1/y/10,ass/50/2/n/0"}, {name:'team1on', type:'choice', choice1:'On', choice2:'Off', defaultValue: 'Off',label: "Teams "}, {name:'team1name', type:'str', minLength: 0, maxLength: 255,defaultValue:'team1', label: "1st Team name, the team name can not contain spaces"}, {name:'team1hierarchy',type:'int', minValue:1, maxValue:99, defaultValue:1, label: "Hierarchy of this team, 1 is the highest hierarchy, if a user is the member of 2 teams the highest hierarchy gif will be chosen. Please make sure you do not have 2 teams with the same hierarchy"}, {name:'team1tkToJoin', type:'int', minValue:0, maxValue:99, defaultValue:0, label: "The tip value to join team, if set to 0 the bot will not auto add members"}, {name:'team1discountOn',type:'choice',required: true, choice1:'Yes', choice2:'No', defaultValue: 'No',label: "Apply the fanclub discount to this team"}, {name:'team1discounts', type:'str',required: false, minLength: 0, maxLength: 1000, label: "Discounted menu items for this team, must be the idetical name of the item as in the menu settings, discounts are not cumulative, so if a user is a memeber of 2 teams or a team and the fanclub and bot get a discount on an item only the highest discount will be applied. Enter as item/discount_percentage, ie boobs/10,ass/10"}, {name:'team1joinmsg',type:'str', minLength: 0, maxLength: 255, label: "The msg shown in chat when a new member joins the team, if blank no msg will be shown",required: false}, {name:'team1entrymsg',type:'str', minLength: 0, maxLength: 255, label: "The msg shown to team members when they enter the room, if blank no msg will be shown",required: false}, {name:'team1gif', type:'str', minLength: 0, maxLength: 255, label: "Team gif",required: false}, {name:'team1users', type:'str', minLength: 0, maxLength: 255, label: "Team members, must be exact username, seperate each entry with a comma, for an indervidual gif inplace of team gif add /:gifname. ie username1,username2/:personalgif,username3",required: false}, {name:'team2on', type:'choice', choice1:'On', choice2:'Off', defaultValue: 'Off'}, {name:'team2name', type:'str', minLength: 0, maxLength: 255,defaultValue:'team2', label: "2nd Team name, the team name can not contain spaces"}, {name:'team2hierarchy',type:'int', minValue:1, maxValue:99, defaultValue:1, label: "Hierarchy of this team, 1 is the highest hierarchy, if a user is the member of 2 teams the highest hierarchy gif will be chosen. Please make sure you do not have 2 teams with the same hierarchy"}, {name:'team2tkToJoin', type:'int', minValue:0, maxValue:99, defaultValue:0, label: "The tip value to join team, if set to 0 the bot will not auto add members"}, {name:'team2discountOn',type:'choice',required: true, choice1:'Yes', choice2:'No', defaultValue: 'No',label: "Apply the fanclub discount to this team"}, {name:'team2discounts', type:'str',required: false, minLength: 0, maxLength: 1000, label: "Discounted menu items for this team, must be the idetical name of the item as in the menu settings, discounts are not cumulative, so if a user is a memeber of 2 teams or a team and the fanclub and bot get a discount on an item only the highest discount will be applied. Enter as item/discount_percentage, ie boobs/10,ass/10"}, {name:'team2joinmsg',type:'str', minLength: 0, maxLength: 255, label: "The msg shown in chat when a new member joins the team, if blank no msg will be shown",required: false}, {name:'team2entrymsg',type:'str', minLength: 0, maxLength: 255, label: "The msg shown to team members when they enter the room, if blank no msg will be shown",required: false}, {name:'team2gif', type:'str', minLength: 0, maxLength: 255, label: "Team gif",required: false}, {name:'team2users', type:'str', minLength: 0, maxLength: 255, label: "Team members, must be exact username, seperate each entry with a comma, for an indervidual gif inplace of team gif add /:gifname. ie username1,username2/:personalgif,username3",required: false}, {name:'team3on', type:'choice', choice1:'On', choice2:'Off', defaultValue: 'Off'}, {name:'team3name', type:'str', minLength: 0, maxLength: 255,defaultValue:'team3', label: "3rd Team name, the team name can not contain spaces"}, {name:'team3hierarchy',type:'int', minValue:1, maxValue:99, defaultValue:1, label: "Hierarchy of this team, 1 is the highest hierarchy, if a user is the member of 2 teams the highest hierarchy gif will be chosen. Please make sure you do not have 2 teams with the same hierarchy"}, {name:'team3tkToJoin', type:'int', minValue:0, maxValue:99, defaultValue:0, label: "The tip value to join team, if set to 0 the bot will not auto add members"}, {name:'team3discountOn',type:'choice',required: true, choice1:'Yes', choice2:'No', defaultValue: 'No',label: "Apply the fanclub discount to this team"}, {name:'team3discounts', type:'str',required: false, minLength: 0, maxLength: 1000, label: "Discounted menu items for this team, must be the idetical name of the item as in the menu settings, discounts are not cumulative, so if a user is a memeber of 2 teams or a team and the fanclub and bot get a discount on an item only the highest discount will be applied. Enter as item/discount_percentage, ie boobs/10,ass/10"}, {name:'team3joinmsg',type:'str', minLength: 0, maxLength: 255, label: "The msg shown in chat when a new member joins the team, if blank no msg will be shown",required: false}, {name:'team3entrymsg',type:'str', minLength: 0, maxLength: 255, label: "The msg shown to team members when they enter the room, if blank no msg will be shown",required: false}, {name:'team3gif', type:'str', minLength: 0, maxLength: 255, label: "Team gif",required: false}, {name:'team3users', type:'str', minLength: 0, maxLength: 255, label: "Team members, must be exact username, seperate each entry with a comma, for an indervidual gif inplace of team gif add /:gifname. ie username1,username2/:personalgif,username3",required: false}, {name:'team4on', type:'choice', choice1:'On', choice2:'Off', defaultValue: 'Off'}, {name:'team4name', type:'str', minLength: 0, maxLength: 255,defaultValue:'team4', label: "4th Team name, the team name can not contain spaces"}, {name:'team4hierarchy',type:'int', minValue:1, maxValue:99, defaultValue:1, label: "Hierarchy of this team, 1 is the highest hierarchy, if a user is the member of 2 teams the highest hierarchy gif will be chosen. Please make sure you do not have 2 teams with the same hierarchy"}, {name:'team4tkToJoin', type:'int', minValue:0, maxValue:99, defaultValue:0, label: "The tip value to join team, if set to 0 the bot will not auto add members"}, {name:'team4discountOn',type:'choice',required: true, choice1:'Yes', choice2:'No', defaultValue: 'No',label: "Apply the fanclub discount to this team"}, {name:'team4discounts', type:'str',required: false, minLength: 0, maxLength: 1000, label: "Discounted menu items for this team, must be the idetical name of the item as in the menu settings, discounts are not cumulative, so if a user is a memeber of 2 teams or a team and the fanclub and bot get a discount on an item only the highest discount will be applied. Enter as item/discount_percentage, ie boobs/10,ass/10"}, {name:'team4joinmsg',type:'str', minLength: 0, maxLength: 255, label: "The msg shown in chat when a new member joins the team, if blank no msg will be shown",required: false}, {name:'team4entrymsg',type:'str', minLength: 0, maxLength: 255, label: "The msg shown to team members when they enter the room, if blank no msg will be shown",required: false}, {name:'team4gif', type:'str', minLength: 0, maxLength: 255, label: "Team gif",required: false}, {name:'team4users', type:'str', minLength: 0, maxLength: 255, label: "Team members, must be exact username, seperate each entry with a comma, for an indervidual gif inplace of team gif add /:gifname. ie username1,username2/:personalgif,username3",required: false} ]; function runTeamSettings(){ for(i=1;i<(maxTeams+1);i++){ makeTeam(i); } teams.list.sort(function(a, b){return a.hierarchy - b.hierarchy}); teams.tipValCreate(); } function makeTeam(i){ var t = 'team'+i; if(cb.settings[(t+'on')]=='On'){ var nt = new team(); if(cb.settings[(t+'name')]){ nt.name = cb.settings[(t+'name')]; } if(cb.settings[(t+'hierarchy')]){ nt.hierarchy = cb.settings[(t+'hierarchy')]; } if(cb.settings[(t+'tkToJoin')]){ nt.joinVal = cb.settings[(t+'tkToJoin')]; } if(cb.settings[(t+'discountOn')]){ if(cb.settings[(t+'discountOn')]=='Yes'){ nt.fanDiscountOn =true; }else{ nt.fanDiscountOn =false; } } if(cb.settings[(t+'discounts')]){ var a = cb.settings[(t+'discounts')].split(','); for(i=0;i<a.length;i++){ var b=a[i].split('/'); discounts[discounts.length]={team:cb.settings[(t+'name')],name:b[0],dis:b[1]}; } } if(cb.settings[(t+'joinmsg')]){ nt.joinmsg = cb.settings[(t+'joinmsg')]; } if(cb.settings[(t+'entrymsg')]){ nt.entrymsg = cb.settings[(t+'entrymsg')]; } if(cb.settings[(t+'gif')]){ nt.teamgif = cb.settings[(t+'gif')]; } nt.members= parseMemberStr(cb.settings[t+'users']); teams.list[teams.list.length]=nt; } } function parseMemberStr(memStr){ var list=[]; if(memStr==''){ return list; } var memberArr =memStr.split(','); for(j=0;j<memberArr.length;j++){ var m= memberArr[j].split('/'); var gif= ''; if(m.length>1){gif=m[1]} var mem = new teamMember(m[0],gif); list[list.length]=mem; } return list; } function runMenuSettings(){ if(cb.settings['tipOn']=='On'){ if(cb.settings['tipNotifierOn']){ if(cb.settings['tipNotifierOn']=='On'){ menu.notifier.on=true; } } if(cb.settings['tipNotifierTime']){ menu.notifier.time=cb.settings['tipNotifierTime']; } if(cb.settings['tipMenucolour']){ menu.notifier.colour=cb.settings['tipMenucolour']; } if(cb.settings['tipMenucolour']){ menu.notifier.fullcolour=cb.settings['tipFullMenucolour']; } if(cb.settings['tipMenuNotice']){ menu.notifier.txt=cb.settings['tipMenuNotice']; } if(cb.settings['fanDiscountOn']){ if(cb.settings['fanDiscountOn']=='On'){ menu.fanDiscountOn=true; } } if(cb.settings['tipSections']){ var x=cb.settings['tipSections'].split(','); for(i=0;i<x.length;i++){ var y=x[i].split(')'); if(y.length ==1){ menu.addSection(y[0],''); }else if(y.length==2){ menu.addSection(y[0],y[1]); }else{ //error } } }else{ //error } if(cb.settings['tipMenuItems1'] !=''){ var z=cb.settings['tipMenuItems1'].split(','); for(i=0;i<z.length;i++){ var mi=z[i].split('/'); if(mi.length==5){ menu.addItem(mi[0],mi[1],mi[2],mi[3],mi[4]); }else{ //error } } menu.make(); } } } // Vars var model=cb.room_slug; var discounts =[]; // menu Object constructors var menu=new Object(); menu.items = []; menu.display=[]; menu.sections=[]; menu.seperator=' | '; menu.fullMenu=''; menu.notifier={}; menu.notifier.on=false; menu.notifier.time=1; menu.notifier.colour='#000000'; menu.notifier.txt=''; menu.notifier.fullcolour='#000000'; menu.discountList=[]; menu.fanDiscountOn=false; menu.make=function(){ menu.addDiscounts(); menu.itemSort(); menu.makeDisplay(); menu.fillSections(); menu.sectionsSortItems(); menu.sortDisplay(); menu.makeFullMenu(); } menu.notifier.run=function(){ if(menu.notifier.on){ menu.notifier.showNotice(); cb.setTimeout(menu.notifierrun,menu.notifier.time*1000); } } menu.notifier.makeNotice=function(){ var it=menu.display; var sep=menu.seperator; var str=it[0].name+' '+it[0].amount; if(it.length>1){ for(i=1;i<it.length;i++){ str=str+sep+it[i].name+'('+it[i].amount+')'; } } str=str+'\n'+menu.notifier.txt; return str; } menu.notifier.showNotice=function(){ var str=menu.notifier.makeNotice(); cb.sendNotice(str,'','',menu.notifier.colour,'bolder'); } menu.makeFullMenu=function(){ var menutext=[]; for(i=0;i<menu.sections.length;i++){ var sec=menu.sections[i]; if(sec.items.length>0){ menutext[menutext.length]='***** '+sec.name+' *****'; for(j=0;j<sec.items.length;j++){ menutext[menutext.length]=sec.items[j].name+' '+sec.items[j].amount+'tk'; } } } var txt=menutext[0]; if(menutext.length>1){ for(k=1;k<menutext.length;k++){ txt=txt +'\n'+menutext[k]; } } menu.fullMenu=txt; } menu.displayFull=function(msg){ var discount=menu.inDiscountList(msg.user); var str=menu.fullMenu; if(discount!=-1){ str=menu.discountList[discount].fullMenu; } cb.sendNotice(str,msg.user,'',menu.notifier.fullcolour,'bolder'); } menu.itemSort=function(){ menu.items.sort(function(a, b){return a.amount - b.amount}); } menu.makeDisplay=function(){ if(menu.items.length>0){ for(i=0;i<menu.items.length;i++){ if(menu.items[i].display){ menu.display[menu.display.length]=menu.items[i]; } } } } menu.sortDisplay=function(){ menu.display.sort(function(a, b){return a.amount - b.amount}); } menu.addItem=function(name,amount,section,display){ var x=new menuItem(name,amount,section,display); menu.items[menu.items.length]=x; } menu.fillSections=function(){ for(i=0;i<menu.items.length;i++){ var x = menu.items[i]; menu.addSectionItem(x); } } menu.addSectionItem=function(item){ for(j=0;j<menu.sections.length;j++){ var x = menu.sections[j]; if(item.section==x.number){ x.items[x.items.length]=item; return; } } } menu.sectionsSort=function(){ menu.sections.sort(function(a, b){return a.number - b.number}); } menu.addSection=function(number,name){ var section=new menuSection(number,name); menu.sections[menu.sections.length]=section; menu.sectionsSort(); } menu.sectionsSortItems=function(){ for(i=0;i<menu.sections.length;i++){ var x = menu.sections[i]; x.itemsSort(); } } menu.addDiscounts=function(){ for(i=0;i<discounts;i++){ menu.addDiscount(discounts[i].name,discounts[i].dis,discounts[i].team); } db(menu.items); } menu.addDiscount=function(item,dis,team){ for(i=0;i<menu.items.length;i++){ if(item==menu.items[i].name){ menu.items[i].discounts.push({dis:dis,team:team}); } } } function menuItem(name,amount,section,display,fanDiscount){ this.type='menuItem'; this.name = name; this.amount=parseInt(amount); this.section=parseInt(section); this.fanDiscount=(parseInt(fanDiscount)/100)+1; this.discounts=[]; var x= false; if(display=='y'){x=true;} this.display=x; } function menuSection(number,name){ this.number=parseInt(number); this.name=name; this.items=[]; this.itemsSort=function(){ this.items.sort(function(a, b){return a.amount - b.amount}); } } // Team Object constructors var teams=new Object(); teams.list=[]; teams.returngif=function(user){ for(i=0;i<teams.list.length;i++){ var t=teams.list[i]; var x = t.inteam(user); if(x[0]){ return [true,x[1].gif]; } } return [false]; } teams.tipValCreate=function(){ for(i=0;i<teams.list.length;i++){ teams.tipVal[teams.tipVal.length]={name:teams.list[i].name,val:teams.list[i].joinVal}; } } teams.tipVal=[]; teams.inTeam=function(user){ var list=[]; for(i=0;i<teams.list.length;i++){ var t=teams.list[i]; if(t.members.length>0){ for(j=0;j<t.members.length;j++){ if(t.members[j].user==user){ list[list.length]=t; } } } } return list; } teams.inTeamNumber=function(user){ var list=[]; for(i=0;i<teams.list.length;i++){ var t=teams.list[i]; if(t.members.length>0){ for(j=0;j<t.members.length;j++){ if(t.members[j].user==user){ list[list.length]=i; } } } } return list; } teams.addMember=function(team,operator,user,gif){ for(i=0;i<teams.list.length;i++){ if(team==teams.list[i].name){ teams.list[i].addMember(operator,user,gif); return; } } errorMsg(operator,'That team does not exist'); } function team(){ this.name=''; this.hierarchy=''; this.joinVal=0; this.joinmsg=''; this.entrymsg=''; this.members=[]; this.teamgif=''; this.fanDiscountOn=false; this.inteam=function(user){ if(this.members.length==0){return [false];} for(i=0;i<this.members.length;i++){ if(this.members[i].user==user){ var x=new teamUser(this.name,this.hierarchy,this.entrymsg,this.teamgif); if(this.members[i].gif!=''){x.gif=this.members[i].gif;} return [true,x]; } } return [false]; } this.addMember=function(operator,user,gif){ if(this.inteam(user)[0]){ errorMsg(operator,'That user is already in '+team.name); }else{ this.members[this.members.length]=new teamMember(user,gif); noteMsg(operator, user+' added to team '+team); } } } function teamUser(team,hierarchy,entrymsg,gif){ this.team=team; this.hierarchy=hierarchy; this.entrymsg=entrymsg; this.gif=gif; } function teamMember(user,gif){ this.user=user; this.gif=gif; } function addgif(msg){ var user = msg.user; var gif = teams.returngif(user); if(gif[0]){ msg.m=gif[1]+' '+msg.m; } return msg; } function getWelcome(user){ var teamlist=teams.inTeam(user.user); var msgtxt='' if(teamlist.length>0){ for(i=0;i<teamlist.length;i++){ msgtxt=msgtxt+teamlist[i].name+' '; } msgtxt=msgtxt+user.user; } return msgtxt; } function noteMsg(operator,str){ cb.sendNotice(str,operator); } function errorMsg(operator,str){ cb.sendNotice(str,operator); } function db(str){ cb.sendNotice(str); } //---------- commands---------- function commandParse(msg){ if(msg.m.charAt(0)=='#'){ var user = msg.user; msg['X-Spam'] = true; var msgArr=msg.m.split(' '); var mal=msgArr.length; switch(msgArr[0]){ case '#addteammember': case '#atm': if(mal==3){ teams.addMember(msgArr[1],user,msgArr[2],''); }else if(mal==4){ teams.addMember(msgArr[1],user,msgArr[2],msgArr[3]); }else{ //help command } break; case '#menu': //menu.displayFull(msg); break; default: msg['X-Spam'] = false; } } return msg; } //---------- on msg---------------- cb.onMessage(function (msg) { msg= commandParse(msg); if(teams.inTeam(msg.user).length>0){ msg= addgif(msg); } return msg; }); //----------- on enter---------------- cb.onEnter(function(user) { var welcomeTxt=getWelcome(user); if(!(welcomeTxt == '')){ cb.chatNotice(welcomeTxt); } menu.addDiscountList(user); }); runTeamSettings(); runMenuSettings(); cb.setTimeout(menu.notifier.run,1000);
© Copyright Chaturbate 2011- 2024. All Rights Reserved.