Bots Home
|
Create an App
AntMoji
Author:
cbrocks101
Description
Source Code
Launch Bot
Current Users
Created by:
Cbrocks101
/* ################################################################################################################# # Name: AntMoji + KillSwitch # Author:alanstuart # Version 2.0 # Inspired by anthony19cal ################################################################################################################# # # Summary: # -------- # # AntMoji: # -------- # Allows emojis to be assigned to Model, Mods, or individual users # Emojis appear appear between the user's name and the message content in each Chat message . # # KillSwitch: # ----------- # Allows any mod to disconnect the model's stream if the model forgets to # ################################################################################################################# */ var mojihelp=` ################################################################################################################# # # Description # ----------- # These bots were inspired by anthony19cal. # # *** BROWSER SCRIPT (REQUIRED) *** # ================================== # A Browser Script is required for Killswitch to work, and for Emoji data to be saved between sessions. # The following commands are used for Browser Script install instructions and status # # /scriptinfo # .....Displays instructions and code for installing the Browser Script # # /scriptstat # .....Checks whether the browser script is running (this is automatically run every 15 minutes) # # # AntMoji: # ======== # Emojis can be setup either in the bot startup screen, or via the "/setmoji" command. An emoji can be setup for # either the mod group, or for an individual user. The emoji's are specified using the name of an uploaded # CB emoji GIF (e.g. ":crown"), which must already exist in CB. If an emoji is setup for a user, it will be # displayed next to their name before any message.they type in chat. Emojis setup using the /setmoji command # override any emojis in the startup screen, and get saved between sessions. Emojis can be removed via the /delmoji # command, however any emojies specified in the startup screen will be reestablished next time the bot is restarted. # The /moji command can be used to specify who besides the model is allowed to change emojis, and to turn the # displaying of emojis on and off. # # AntMoji Commands: # ================ # /setmoji [:emoji] # .....Sets your own emoji to :EMOJI. # .....[:emoji] must be an existing CB uploaded GIF, and must begin with ":" # # /setmoji [user] [:emoji] -or- /setmoji mods [:emoji] # .....Sets the emoji for [user] (or for all mods) to [:emoji] # .....Only allowed the by model, and by mods if changeothers=mod # # /delmoji # .....removes your own emoji, no emoji will be displayed # # /delmoji [user] -or- /delmoji mods # .....Removes the emoji for user USER (or for all mods) # .... Only allowed by the model, and by mods if changeothers=mod # # /delmoji all!! # .....Removes all emojis. Only allowed by the model # # /listmoji # .....Lists the user's currently assigned emojis. # .....If run by the model or a mod lists all assigned emojis. # # /moji changeself -or- /moji nochangeself # .....Determines if users can change their own emoji (default nochangeself) # # /moji modchange -or- /moji nomodchange # .....Determines if mods can change other users' emojis (default modchange) # .....Mods can never change the emojis of the model or the mod group # # /moji displayon -or- /moji displayoff # .....Determines whether emojis are displayed or not (default displayon) # # # KillSwitch # ========== # Allows mods to disconnect the video stream and put the room in "Offline" mode. This is done by resetting the # Broadcast Token (i.e. Stream Key) using a Browser Script. This requires the Browser Script to be running (see # instructions below), and will not work for broadcasts done with Flash Player. The stream can be killed by any # mod by issuing the /kill command. The model can restart a killed stream by reloading the broacast page. If an # external program like OBS used for streaming, the new Stream Key will need to be entered in the streaming # software (the new key is displayed by the /kill command). # # KillSwitch Commands: # =================== # /kill!! # .....Disconnects the model's stream (i.e. changes model status to Offline) # ################################################################################################################# `; /* ##################################### # Setup variables and Startup Screen ##################################### */ cb.settings_choices = [ {name:'changeself',type:'choice',defaultValue:'No',choice1:'No',choice2:'Yes',label: 'Users can change own Emojis?',required:true}, {name:'modchange',type:'choice',defaultValue:'Yes',choice1:'Yes',choice2:'No',label: "Mods can change users' Emojis?",required:true}, {name:'performer_emoji_name',type:'str',defaultValue:':emoji-weed', label: 'Emoji name (Performer)',required:false}, {name:'mod_emoji_name',type:'str',label:'Emoji name (Mods)',defaultValue:':crowngold',required:false }, {name:'user_2_name',type:'str',label:"Name (User 1)",defaultValue:'alanstuart',required:false}, {name:'user_2_emoji_name',type:'str',label:"Emoji Name (User 1)",defaultValue:':devil',required:false}, {name:'user_1_name',type:'str',label:"Name (User 2)",defaultValue:'thexander84',required:false}, {name:'user_1_emoji_name',type:'str',label:"Emoji Name (User 2)",defaultValue:':antcarr',required:false}, {name:'user_3_name',type:'str',label:"Name (User 3)",defaultValue:'the_slayer',required:false}, {name:'user_3_emoji_name',type:'str',label:"Emoji Name (User 3)",defaultValue:':jointsmoker',required:false}, {name:'user_4_name',type:'str',label:"Name (User 4)",defaultValue:'',required:false}, {name:'user_4_emoji_name',type:'str',label:"Emoji Name (User 4)",defaultValue:'',required:false}, {name:'user_5_name',type:'str',label:"Name (User 5)",defaultValue:'',required:false}, {name:'user_5_emoji_name',type:'str',label:"Emoji Name (User 5)",defaultValue:'',required:false}, {name:'user_6_name',type:'str',label:"Name (User 6)",defaultValue:'',required:false}, {name:'user_6_emoji_name',type:'str',label:"Emoji Name (User 6)",defaultValue:'',required:false}, {name:'user_7_name',type:'str',label:"Name (User 7)",defaultValue:'',required:false}, {name:'user_7_emoji_name',type:'str',label:"Emoji Name (User 7)",defaultValue:'',required:false}, {name:'user_8_name',type:'str',label:"Name (User 8)",defaultValue:'',required:false}, {name:'user_8_emoji_name',type:'str',label:"Emoji Name (User 8)",defaultValue:'',required:false}, {name:'user_9_name',type:'str',label:"Name (User 9)",defaultValue:'',required:false}, {name:'user_9_emoji_name',type:'str',label:"Emoji Name (User 9)",defaultValue:'',required:false} ]; var k="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/="; var srString,srOBJ={},encErr,encErrstr,srPend={},srPendID,srLastWarned=0,srWarnInt=900000,srDesc={"emoj":"Emoji"}; var cmdparms=[],cmds={},cbmsg,cmd,iscmd,cmdparmct,cmd0,cmd1,cmd2,ismod,ismodel,user,model=cb.room_slug; var killenabled=1,killactive=0,kmsg,knotice,scriptOK=-1,pingid=0; var savemoji={},emoji={},savepend={},restpend={},pref="",changeself,modchange,display="DISPLAY"; var lastsend=0,sendArgs=[]; /* ############################################################################################## # Initialize processing - Read startup screen data, Restore saved data, Setup Background Tasks ############################################################################################## */ function init(){ if (cb.settings.changeself=="Yes") {changeself="CHANGESELF";} else {changeself="NOCHANGESELF";} if (cb.settings.modchange=="Yes") {modchange="MODCHANGE";} else {modchange="NOMODCHANGE";} if (cb.settings.performer_emoji_name!=="") {emoji[model]=cb.settings.performer_emoji_name;} if (cb.settings.mod_emoji_name!=="") {emoji["MODS"]=cb.settings.mod_emoji_name;} if (cb.settings.user_1_name!=="") {emoji[cb.settings.user_1_name]=cb.settings.user_1_emoji_name;} if (cb.settings.user_2_name!=="") {emoji[cb.settings.user_2_name]=cb.settings.user_2_emoji_name;} if (cb.settings.user_3_name!=="") {emoji[cb.settings.user_3_name]=cb.settings.user_3_emoji_name;} if (cb.settings.user_4_name!=="") {emoji[cb.settings.user_4_name]=cb.settings.user_4_emoji_name;} if (cb.settings.user_5_name!=="") {emoji[cb.settings.user_5_name]=cb.settings.user_5_emoji_name;} if (cb.settings.user_6_name!=="") {emoji[cb.settings.user_6_name]=cb.settings.user_6_emoji_name;} if (cb.settings.user_7_name!=="") {emoji[cb.settings.user_7_name]=cb.settings.user_7_emoji_name;} if (cb.settings.user_8_name!=="") {emoji[cb.settings.user_8_name]=cb.settings.user_8_emoji_name;} if (cb.settings.user_9_name!=="") {emoji[cb.settings.user_9_name]=cb.settings.user_9_emoji_name;} setTimeout(Reminders,3000); setTimeout(srProcessPendReq,5000); setTimeout(function(){srReqRestoreObj("emoj",1)},10000); } /* ############################# # Process Messages ############################# */ cb.onMessage(function (msg) { cbmsg=msg; parseMsg(); /* ##################################### # Process non-commands, apply Emojis ##################################### */ if (!iscmd) { if (display="DISPLAY") { pref=""; if (ismod&&("MODS" in emoji)) {pref=emoji["MODS"];} if (ismod&&("MODS" in savemoji)) {pref=savemoji["MODS"];} if (user in emoji) {pref=emoji[user];} if (user in savemoji) {pref=savemoji[user];} if (pref!=="") {msg.m = pref+" "+msg.m;} } return msg; } msg['X-Spam'] = true; // cb.sendNotice(cmd+","+cmdparmct+","+cmd0+","+cmd1+","+cmd2+","+ismod+","+ismodel+","+cmdparms[1],user,"#ffffff","#ffffff","bold"); /* ##################################### # /mojihelp : Display Help message ##################################### */ cmds["mojihelp"]=1; if (cmd=='mojihelp') { cb.sendNotice(mojihelp,user,"#ffffff","#900000","normal"); return msg; } /* ##################################### # /kill : Kill Stream ##################################### */ cmds["kill!!"]=1; if (ismod&&(cmd0=='kill!!')) { var n = new Date().getTime(); cb.sendNotice('Killswitch Activated by '+user,"","#ffffff","#900000","bolder"); cb.sendNotice('/kill id='+n,model,"#ffffff","#900000","bolder"); return msg; } /* ########################################################### # /scriptstat: Request status from Browser Script ########################################################### */ cmds["scriptstat"]=1; if (ismod&&(cmd0=='scriptstat')) { pingBScript(user); return msg; } /* ############################################################# # Process Browser Script Status Response from Browser Script ############################################################# */ cmds["BrowserScript_OK"]=1; if (ismodel && (cmd=='BrowserScript_OK')) { if (msg.m.substr(18,13)==pingid) { scriptOK = 1; pingid=0; } msg.c="#ffffff"; return msg; } /* ######################################################## # Process Browser Script Startup Message from Browser Script ######################################################## */ cmds["BrowserScript_Started"]=1; if (ismodel && (cmd=='BrowserScript_Started')) { cb.sendNotice('Browser Script started',"","#ffffff","#900000","bold","red"); cb.sendNotice('Browser Script started',model,"#ffffff","#900000","bold"); scriptOK = 1; msg.c="#ffffff"; return msg; } /* ####################################################################### # /scriptinfo: Display Instructions/Code for installing Browser Script ####################################################################### */ cmds["scriptinfo"]=1; if (ismod && (cmd0=='scriptinfo')) { sendNotice(ksdesc,user,"#ffffff","#900000","bold"); sendNotice('Create a Chrome bookmark, edit it, and replace the URL with the string below (starting with "javascript")',user,"#ffffff","#002eff","bold"); sendNotice('> '+kscode,user,"#ffffff","#002eff","normal"); msg.c="#ffffff"; return msg; } /* ####################################################################### # /setmoji: Change emoji for user or mods group ####################################################################### */ cmds["setmoji"]=1; if ((cmd1=='setmoji')||(cmd2=='setmoji')) { if (cmdparmct==1) { cmdparms[2]=cmdparms[1]; cmdparms[1]=user; } if (ismodel||(ismod&&(modchange=="MODCHANGE")&&(cmdparms[1]!==model)&&(cmdparms[1]!=='#'+model))||(cmd1&&(changeself="CHANGESELF"))) { if (cmdparms[2].substr(0,1)!==':') {return badCommand('Emoji must begin with ":"');} if ((cmdparms[1].toUpperCase()=='MODS')||(cmdparms[1].toUpperCase()=='MOD')) {cmdparms[1]=MODS;} savemoji[cmdparms[1]] = cmdparms[2]; cb.sendNotice('Emoji for '+cmdparms[1]+" set to "+cmdparms[2],user,"#ffffff","#900000","bold"); if (!ismodel) {cb.sendNotice('Emoji for '+cmdparms[1]+" set to "+cmdparms[2],model,"#ffffff","#900000","bold");} srObj=savemoji; srSaveObj("emoj",0); } else {return badCommand("You do not have permisssion to change the emoji for "+cmdparms[1]+" ("+changeself+","+modchange+")");} return msg; } /* ####################################################################### # /delmoji: Remove emoji for user or mods group ####################################################################### */ cmds["delmoji"]=1; if ((cmd1=="delmoji")&&(cmdparms[1]=="all!!")&&ismodel) { cb.sendNotice('Removed all Emojis',user,"#ffffff","#900000","bold"); savemoji={}; return msg; } else if ((cmd0=='delmoji')||(cmd1=='delmoji')) { if (ismodel||(ismod&&(modchange=="MODCHANGE")&&(cmdparms[1]!==model)&&(cmdparms[1]!=='#'+model))||(cmd0&&(changeself="CHANGESELF"))) { if (cmdparmct==0) {cmdparms[1]=user;} if ((cmdparms[1].toUpperCase()=='MODS')||(cmdparms[1].toUpperCase()=='MOD')) {cmdparms[1]=MODS;} if (!(cmdparms[1] in savemoji)) {return badCommand("Emoji "+cmdparms[1]+" does not exist");} delete savemoji[cmdparms[1]]; cb.sendNotice('Emoji for '+cmdparms[1]+" removed",user,"#ffffff","#900000","bold"); if (!ismodel) {cb.sendNotice('Emoji for '+cmdparms[1]+" removed",model,"#ffffff","#900000","bold");} srObj=savemoji; srSaveObj("emoj",0); } else {return badCommand("You do not have permisssion to delete the umoji for "+cmdparms[1]+" ("+changeself+","+modchange+")");} return msg; } /* ####################################################################### # /listmoji: List emojis ####################################################################### */ cmds["listmoji"]=1; if (cmd0=='listmoji') { var liststr='==========================================================='+"\n"+ '= AntMoji Emoji List ('+display+", "+changeself+", "+modchange+")\n"+ '==========================================================='+"\n"; for (var emojiuser in savemoji) { if (!savemoji.hasOwnProperty(emojiuser)) {continue;} if (emojiuser.substr(0,1)=="#") {continue;} if ((ismod)||(emojiuser==user)) { liststr+="= "+emojiuser+" Emoji= "+savemoji[emojiuser]; if ('#'+emojiuser in savemoji) {liststr+=" enterMoji= "+savemoji['#'+emojiuser];} liststr+="\n"; } } for (emojiuser in emoji) { if (!emoji.hasOwnProperty(emojiuser)) {continue;} if (emojiuser in savemoji) {continue;} if ((ismod)||(emojiuser==user)) { liststr+="= "+emojiuser+" "+emoji[emojiuser]+"\n"; } } liststr+='==========================================================='; cb.sendNotice(liststr,user,"#ffffff","#900000","bold"); return msg; } /* ####################################################################### # /save Make request to Browser Script to save "emoji" object data ####################################################################### */ cmds["save"]=1; if (ismodel&&(cmd0=='save')) { srObj=savemoji; srSaveObj("emoj",1); return msg; } /* ############################################################ # /SRSAVE_OK: Process Save Confirmation from Browser Script ############################################################ */ cmds["SRSAVE_OK"]=1; if (ismodel && (cmd1=='SRSAVE_OK')) { if (cmdparms[1]==srPendID) { if (srPend[srPendID]["notify"]) { cb.sendNotice("Emoji data was saved by Browser Script, id="+srPendID,user,"#ffffff","#900000","bolder"); } delete srPend[srPendID]; srPendID=0; } else {return badCommand("Save ID "+cmdparms[1]+" not recognized, ignored");} msg.c="#ffffff"; return msg; } /* ################################################################################ # /rest Make request to Browser Script to return "emoji" object data for restore ################################################################################ */ cmds["rest"]=1; if (ismodel&&(cmd0=='rest')) { srReqRestoreObj("emoj",1); return msg; } /* ####################################################################### # /SRREST_OK: Restore saved data returned by Browser Script ####################################################################### */ cmds["SRREST_OK"]=1; if (ismodel&&(cmd2=='SRREST_OK')) { if (cmdparms[1]==srPendID) { if (srRestoreObj(srPendID,cmdparms[2])) { for (var srkey of Object.keys(srObj)) { // cb.sendNotice("srkey "+srkey+" srobj "+srObj[srkey],user,"#ffffff","#900000","bold"); if (!(srkey in savemoji)) {savemoji[srkey]=srObj[srkey];} } if (srPend[srPendID]["notify"]) { cb.sendNotice("Emoji data was Restored, id="+srPendID,user,"#ffffff","#900000","bold"); } } delete srPend[srPendID]; srPendID=0; } else {return badCommand("Restore ID "+cmdparms[1]+" not recognized, ignored");} msg.c="#ffffff"; return msg; } /* #################################################################################### # If one of our commands but not processed above, must be syntax or permission error #################################################################################### */ if (cmd in cmds) {return badCommand('Syntax or Authorization error in command, type "/mojihelp" for more info');} /* ####################################################################### # Otherwise pass through message unaltered ####################################################################### */ else {return msg;} }); /* ####################################################################### # Parse command paraeters and user info into variables ####################################################################### */ function parseMsg() { user=cbmsg.user; model=cb.room_slug if (cbmsg.is_mod) {ismod=1;} else {ismod=0;} if (user==model) {ismodel=1; ismod=1;} else {ismodel=0;} if (cbmsg.m.substr(0,1)!=='/') {iscmd=0; return} else {iscmd=1} cmdparms = notBlank(cbmsg.m.substr(1).split(" ")); cmd = cmdparms[0]; cmdparmct = cmdparms.length-1; cmd0=cmd1=cmd2=cmd1p=cms2p="" if (cmdparmct==0) {cmd0=cmd;} if (cmdparmct==1) {cmd1=cmd; cmd1p=cmd+" "+cmdparms[1];} if (cmdparmct==2) {cmd2=cmd; cmd2p=cmd+" "+cmdparms[1]+" "+cmdparms[2];} } /* ####################################################################### # When model enters room, check if Browser Script is runnung ####################################################################### */ cb.onEnter(function(user) { var euser=user["user"]; if (user['user']==model) {pingBScript();} if ('#'+euser in savemoji) { cb.sendNotice("===============================\n= User "+euser+" is in the House!!\n= "+savemoji['#'+euser]+"\n===============================","","#ffffff","#900000","bold"); } }); /* ############################################################################################## # Background Task, runs every 15 minute to issue reminders/checks: # - Notifies users that the bot is running, and how to get help # - Checks that the Browser Script is running # - Reminds Mods that KillSwitch is running, and how to activate ############################################################################################## */ function Reminders() { cb.sendNotice('AntMoji bot is running, type "/mojihelp" for more info',"","#ffffff","#900000","bold"); cb.sendNotice('Mods: To kill stream type "/kill!!", to check Browser Script status type "/scriptinfo"',"","#ffffff","#900000","normal","red"); pingBScript(); cb.setTimeout(Reminders,900000); } /* ###################################################################################################### # Ask Browser Script to issue a "/BrowserScript_OK" command in the model's chat to confirm it is running ###################################################################################################### */ function pingBScript(statusto="") { if (pingid==0) { scriptOK = 0; pingid = new Date().getTime(); cb.sendNotice('Checking for Browser Script ('+pingid+')...',model,"#ffffff","#900000","normal"); } cb.setTimeout(function(){checkBScriptResponse(statusto)},5000); } /* ###################################################################################################### # Confirm that the Browser Script responded to the confirmation request ("scriptOK" should have # been set to 1 when the /KillSwitch_OK command issued by the Browser Script was processed) ###################################################################################################### */ function checkBScriptResponse(statusto) { if (!scriptOK) { var killmsg = '*** WARNING (ACTION REQUIRED) - Browser Script is Not Running, type "/scriptinfo" for instructions ***'; cb.sendNotice(killmsg,"","#ffffff","#900000","bolder","red"); cb.sendNotice(killmsg,model,"#ffffff","#900000","bolder"); } else if ((statusto!=="")&&(statusto!==model)) { cb.sendNotice("Browser Script is Running",statusto,"#ffffff","#900000","normal"); } pingid=0; } /* ###################################################################################################### # Background task to process data save and restore requests in srPend ###################################################################################################### */ function srProcessPendReq() { now=new Date().getTime(); //cb.sendNotice('pend '+Object.keys(srPend).length,model,"#ffffff","#ffffff","bolder"); if (srPendID) { if ((now-srLastWarned)>srWarnInt) {} } else { var pendReq = Object.keys(srPend).sort(); if (pendReq.length>0) { if (scriptOK) { srPendID = pendReq[0]; srLastWarned=0; if (srPend[srPendID]["act"]=="S") { cb.sendNotice('/srsave id='+srPendID+" "+srPend[srPendID]["objkey"]+" "+srPend[srPendID]["data"],model,"#ffffff","#ffffff","bolder"); } else { cb.sendNotice('/srrest id='+srPendID+" "+srPend[srPendID]["objkey"],model,"#ffffff","#ffffff","bolder"); } } else { if ((now-srLastWarned)>srWarnInt) { if (pingid) {var bmsg="Browser Script check in process, please wait";} else {var bmsg='Browser Script is not running,type "/scriptinfo" for help';} cb.sendNotice('Unable process request to save/restore Emoji data: '+bmsg,model,"#ffffff","#900000","bolder"); srLastWarned=now; } } } } setTimeout(srProcessPendReq,5000); } /* ###################################################################################################### # Request that the Browser Script save srObj in the local session storage under the key specified ###################################################################################################### */ function srSaveObj(objkey,notify=0) { srPend[new Date().getTime()] = {"act":"S","objkey":objkey,"notify":notify,"data":encodeStr(JSON.stringify(srObj))}; return; } /* ###################################################################################################### # Request that the Browser Script retrieve data stored under the key specified ###################################################################################################### */ function srReqRestoreObj(objkey,notify=0) { srPend[new Date().getTime()] = {"act":"R","objkey":objkey,"notify":notify}; } /* ########################################################################################################## # Restores the data returned by the /SRSAVE_OK command into the srObj object ########################################################################################################## */ function srRestoreObj (srID,srdata) { if (srdata=="NONE") { cb.sendNotice("There is no saved data for "+srDesc[srPend[srID]["objkey"]],user,"#ffffff","#900000","bolder"); return 0; } else if (srdata.substr(0,4)=="ERR=") { cb.sendNotice("Browser Script error occurred restoring data for "+srDesc[srPend[srID]["objkey"]]+srdata,user,"#ffffff","#900000","bolder"); return 0; } srObj = JSON.parse(decodeStr(srdata)); return 1; } /* ########################################################################### # Escape a string so it can be passed as an argument ########################################################################### */ function encodeStr(a){ encErr=0; a=String(a); for(var g,b,p=0,c=k,r=""; a.charAt(p|0)||(c="=",p%1); r+=c.charAt(63&g>>8-p%1*8)) { b=a.charCodeAt(p+=.75); if (255<b) {encErrstr="encodeStr failed: The string to be encoded contains characters outside of the Latin1 range";encErr=1;return;} g=g<<8|b; } return r; } /* ########################################################################### # Unescape a string previously escaped by encodeStr ########################################################################### */ function decodeStr(a){ encErr=0; a=String(a).replace(/=+$/,""); if (1==a.length%4) {encErrstr="decodeStr failed: The string to be decoded is not correctly encoded";encErr=1;return;} for(var g=0,b,p,c=0,r=""; p=a.charAt(c++); ~p&&(b=g%4?64*b+p:p,g++%4)?r+=String.fromCharCode(255&b>>(-2*g&6)):0) { p=k.indexOf(p); } return r; } /* ########################################################################### # Sends an error message notice in response to an invalid command message ########################################################################### */ function badCommand(badmsg) { cb.sendNotice('Error in command "'+cbmsg.m+'"'+"\n"+badmsg,cbmsg.user,"#ffffff","#900000","bolder"); cbmsg['X-Spam'] = true; return cbmsg; } /* ########################################################################### # Function to facilitate splitting command message parms ########################################################################### */ function notBlank(array) { return array.filter(function(item){ return item != ""; }); } /* ##################################################################################### # Call sendNotice with a delay since the last call so messages are displayed in order ##################################################################################### */ function sendNotice(notice,user,color1,color2,weight,audience) { var now = new Date().getTime(); var wait = Math.max(lastsend+200-now,0); sendArgs=Array.from(arguments); setTimeout(function(){cb.sendNotice(notice,user,color1,color2,weight,audience);},wait); lastsend=now+wait; } init(); /* ##################################################################################### # # # BROWSER SCRIPT # # ##################################################################################### */ var ksdesc="########################################################################################\n"+ "# A Browser Script is required for Killswitch to work, and for Emoji data to be saved between sessions. To run the Browser Script,\n"+ '# the model must select a browser bookmark when they are on the CB "My Broadcast" page. To create this bookmark, the model should add'+"\n"+ '# a new bookmark in Chrome, and change the value of the URL field to the string below (starting with "javascript:")'+"\n"+ "########################################################################################"; var kscode=` javascript: (function(){ var first=1,killid,kill=[],chatNotices=[],killed,saveid,savekey,saveval,retrid,retrkey,retrval,notice,killNotice,pingid,ping=[],save=[],retr=[],err,cmsg; setTimeout(checkChatNotices,1000); function checkChatNotices() { if (first) { document.getElementById("chat_input").value="/BrowserScript_Started (message generated by browser script)"; document.getElementsByClassName("send_message_button")[0].click(); } killed=0; chatNotices = document.getElementsByClassName("emoticonImage"); for (chatNotice of chatNotices) { notice=chatNotice.innerHTML; if ((notice.substr(0,37)=="Notice: Checking for Browser Script (") && (notice.substr(notice.length-9)!=="Verified!") ) { pingid = notice.substr(37,notice.length-41); if ((!first) && !(pingid in ping)) { sendChat("/BrowserScript_OK "+pingid+ " (message generated by browser script)"); chatNotice.innerHTML=notice+"Verified!"; } ping[pingid]=1; } if (notice.substr(0,17)=="Notice: /kill id=") { killid=notice.substr(17); if (!first && !(killid in kill)) { killed=killid; killNotice=chatNotice; } kill[killid]=1; } if (notice.substr(0,19)=="Notice: /srsave id=") { saveid=notice.substr(19,13); savekey=notice.substr(33,4); saveval=notice.substr(38); if (!first && !(saveid in save)) { localStorage.setItem(savekey,saveval); sendChat("/SRSAVE_OK "+saveid); } save[saveid]=1; } if (notice.substr(0,19)=="Notice: /srrest id=") { retrid=notice.substr(19,13); retrkey=notice.substr(33,4); if (!first && !(retrid in retr)) { try {retrval=localStorage.getItem(retrkey);} catch(e) {retrval="ERR="+e.code;} if (retrval==null) {retrval="NONE";} sendChat("/SRREST_OK "+retrid+" "+retrval); } retr[retrid]=1; } } if (killed!==0) { resetOBS(); } first=0; setTimeout(checkChatNotices,3000); } function resetOBS() { var xhr = new XMLHttpRequest(); xhr.open("POST","/api/generate_new_auth_token/"); xhr.setRequestHeader('x-csrftoken',document.getElementsByName("csrfmiddlewaretoken")[0].value); xhr.send(); xhr.onload = function() { if (xhr.status==200) { killNotice.innerHTML="## Stream Ended by KillSwitch<br>## To reactivate, change the Stream Key in OBS to:<br>"+xhr.response; } else { alert("KillSwitch Error resetting stream key: "+xhr.status+" "+xhr.response); } }; xhr.onerror = function() { alert("KillSwitch Error resetting stream key: "+xhr.status+" "+xhr.response); }; } function sendChat(cmsg) { oldcmsg=document.getElementById("chat_input").value; document.getElementById("chat_input").value=cmsg; document.getElementsByClassName("send_message_button")[0].click(); document.getElementById("chat_input").value=oldcmsg; } })(); `.replace(/\s+/g,' ').trim();
© Copyright Chaturbate 2011- 2024. All Rights Reserved.