Bots Home
|
Create an App
jacebot.test
Author:
cbrocks101
Description
Source Code
Launch Bot
Current Users
Created by:
Cbrocks101
/* ################################################################################################################# # Custom bot for jacethesage # # Modules included are: spamKill,fanClubShoutout,Help # # Author: alanstuart_ # Version: 20201213.2331 ################################################################################################################# */ /* ####################################### # Module: Main (version 20201213.2331) ####################################### /* /* ##################################################### # Declare Global variables and initalization function ##################################################### */ var botname='jacebot'; //var modules=[],modnames=[]; var modules={},modnames; var model=cb.room_slug var debug=0; cb.settings_choices=[]; function init() { modnames=Object.keys(modules).join(); sendNotice(`:blankx Running ${botname} with the following functions enabled: ${modnames}\n:blankx (type /help for more info)\n:blankx ${botname} was created by alanstuart_`,"","#900000"); // for (let i=0;i<modules.length;i++) {modules[i]("init");} Object.keys(modules).forEach(m=>{modules[m].modfn("init")}); botInit(); } /* ############################# # Process Messages ############################# */ cb.onMessage(function (msg) { let c=parseMsg(msg); if (debug) {sendNotice("Debug: user="+c.user+",iscmd="+c.iscmd+",ismod="+c.ismod+",ismodel="+c.ismodel+",isgrey="+c.isgrey+",isfan="+c.isfan+",model="+model+",msg="+c.msg.m,c.user,"#ffffff","#000090","bold");} /* ####################################### # Process chat messages (non-commands) ####################################### */ if (!c.iscmd) { for (const m in modules) { if (modules[m].modfn("onMessage",c)) {return msg;} } // for (i=0;i<modules.length;i++) { // if (modules[i]("onMessage",c)) {return msg;} // } return msg; } /* ####################################### # Process command messages ####################################### */ if (c.iscmd) { if (debug) {sendNotice("Debug: cmd="+c.cmd+",cpct="+c.cmdparmct+",c0="+c.cmd0+",c1="+c.cmd1+",c2="+c.cmd2+",cp1="+c.cmdparms[1],c.user,"#ffffff","#000090","bold");} // for (i=0;i<modules.length;i++) { // if (modules[i]("command",c)) {msg['X-Spam']=true;return msg;} // } for (const m in modules) { if (modules[m].modfn("command",c)) {msg['X-Spam']=true;return msg;} } } // If it was a recognized command but not processed above, it must be syntax or permission error, // Otherwise pass through the command message unaltered (it may be used by another bot) if (c.cmd in c.cmds) {return badCommand('Syntax or Authorization error in command, type "/help" for more info',c);} else {return msg;} }); /* ############################# # Process User Entering Room ############################# */ cb.onEnter(function(user) { if (debug) {sendNotice("Debug: user "+user.user+" entered room","","#ffffff","#000090","bold");} // for (i=0;i<modules.length;i++) {modules[i]("onEnter",user);} Object.keys(modules).forEach(m=>{modules[m].modfn("onEnter",user)}); }); /* ############## # Process Tip ############## */ cb.onTip(function(tip) { if (debug) {sendNotice(`Debug: amt=${tip.smount},msg=${tip.message},from=${tip.from_user}`,"","#ffffff","#000090","bold");} // for (i=0;i<modules.length;i++) {modules[i]("onTip",tip);} Object.keys(modules).forEach(m=>{modules[m].modfn("onTip",tip)}); }); /* ################## # CORE FUNCTIONS # ################## */ /* ####################################################################### # Parse command paraeters and user info into variables ####################################################################### */ function parseMsg(msg) { let c=[]; c.msg=msg; c.user=msg.user; if (msg.is_mod) {c.ismod=1;} else {c.ismod=0;} if (msg.has_tokens) {c.isgrey=0;} else {c.isgrey=1;} if (msg.in_fanclub) {c.isfan=1;} else {c.isfan=0;} if (c.user==model) {c.ismodel=1; c.ismod=1;} else {c.ismodel=0;} if (msg.m.substr(0,1)!=='/') {c.iscmd=0; return c;} else {c.iscmd=1} c.cmdparms=[]; c.cmdparms = notBlank(msg.m.substr(1).split(" ")); c.cmd = c.cmdparms[0]; c.cmdparmct = c.cmdparms.length-1; c.cmd0=c.cmd1=c.cmd2=c.cmd1p=c.cms2p=""; if (c.cmdparmct==0) {c.cmd0=c.cmd;} if (c.cmdparmct==1) {c.cmd1=c.cmd; c.cmd1p=c.cmd+" "+c.cmdparms[1];} if (c.cmdparmct==2) {c.cmd2=c.cmd; c.cmd2p=c.cmd+" "+c.cmdparms[1]+" "+c.cmdparms[2];} c.cmds=[]; return c; } /* ########################################################################### # Sends an error message notice in response to an invalid command message ########################################################################### */ function badCommand(badmsg,c) { cb.sendNotice('Error in command "'+c.msg.m+'"'+"\n"+badmsg,c.user,"#900000","#ffffff"); c.msg['X-Spam'] = true; return c.msg; } /* ########################################################################### # Function to facilitate splitting command message parms ########################################################################### */ function notBlank(array) { return array.filter(function(item){ return item != ""; }); } /* ##################################################################################### # Notice management # (if your bot uses this function, add "checkNotices()" into the init section) ##################################################################################### */ var notices={},notice={};notice.timer=0; // function checkNotices() { const now=new Date().getTime(); if (notice.timer==0) {notice.last=now;} Object.keys(notices).forEach(n=>{ if (notices[n].interval>0) { notices[n].timeleft-=now-notice.last; if (notices[n].timeleft<=0) { showNotice(n); notices[n].timeleft+=notices[n].interval; } } }); notice.last=now; notice.timer=cb.setTimeout(checkNotices,1000); } // function addNotice(n,msg,interval,delay=0,fgcolor="#000090",bgcolor="#ffffff",weight="bold") { if (n in notices) {delete notices[n];} if (delay==-1) {delay=Math.floor(Math.random()*interval);} notices[n]={"message":msg,"interval":interval*1000,"fgcolor":fgcolor,"bgcolor":bgcolor,"weight":weight,"timeleft":delay*1000}; showNotice(n); } // function delNotice(n) {if (n in notices) {notices[n].interval=0;}} // function listNotices(user) { if (Object.keys(notices).length==0) {sendNotice("There are currently no Notices",user); return;} sendNotice("# List of notices",user); Object.keys(notices).forEach(n=>{ sendNotice("# name="+n+", interval="+notices[n].interval/1000+" sec, nextnotice="+notices[n].timeleft/1000+"sec, message= "+notices[n].message,user); }); } /**/ function showNotice(n) {sendNotice(notices[n].message,undefined,notices[n].fgcolor,notices[n].bgcolor,notices[n].weight);} /* ##################################################################################### # Call sendNotice with a delay (so messages are displayed in order) ##################################################################################### */ var lastsend=0; function sendNotice(notice,touser="",fgcolor="#000090",bgcolor="#ffffff",weight="bold",togroup="") { var now = new Date().getTime(); var wait = Math.max(lastsend+200-now,0); setTimeout(function(){cb.sendNotice(notice,touser,bgcolor,fgcolor,weight,togroup);},wait); lastsend=now+wait; } /* ##################################################################################### # Override cb.setting_choices parameters setup in modules ##################################################################################### */ function deleteSC(scn) { cb.settings_choices.forEach((sc,i)=>{ if (sc.name==scn) {cb.settings_choices.splice(i,1); return;} }); } /* ######################################################################################### # Stub function to be run on bot initialization -- to be overridden with custom bot code ######################################################################################### */ function botInit() {} /* #################### # MODULES #################### */ /* ##################################################################################### # Module: Help (version 20201213.2331) ##################################################################################### modules['help']={}; modules.help.modfn=help; function help(mode,c) { if (mode=="onMessage") {return 0;} else if (mode=="command") { c.cmds["help"]=1; if (c.cmd=='help') { cb.sendNotice('For help go to https://chaturbate.com/apps/app_details/'+botname,c.user); return 1; } } else if (mode=="init") { } return 0; } */ /* ##################################################################################### # Module: spamKill (version 20201213.2251) ##################################################################################### */ var verify=[],skstat="enabled"; function spamKill(mode,c) { if (mode=="onMessage") { if (skstat=="enabled") { if (!c.isgrey) {return 0;} if (c.isfan) {return 0;} if (c.ismod) {return 0;} else if (!verify[c.user]) { verify[c.user]=[]; verify[c.user]["1stmsg"]=c.msg.m; } else if (verify[c.user]["status"]=="confirmed") {return 0;} else if (verify[c.user]["status"]=="asked") { if (c.msg.m==verify[c.user]["number"]) { verify[c.user]["status"]="confirmed"; sendNotice(`You have been verified, thanks for helping us battle spam!`,c.user,"#008800"); c.msg.m=verify[c.user]["1stmsg"]+"\n"; return 0; } else {sendNotice(`Incorrect response`,c.user,"#ff0000");} } verify[c.user]["number"]= Math.floor(Math.random()*100); c.msg.m=`Please enter the number "${verify[c.user]["number"]}" to send your message. You will only need to do this once.`; c.msg.c="#0000ff"; c.msg['X-Spam'] = true; verify[c.user]["status"]="asked"; return 1; } } else if (mode=="command") { if (c.cmd=="spamkill") { c.cmds["spamkill"]=1; if (c.ismod||c.ismodel) { if (c.cmdparmct==0) {sendNotice(`SpamKill is ${skstat}`,c.user);return 1;} else if (c.cmdparmct==1&&(c.cmdparms[1]=="on"||c.cmdparms[1]=="off")) { if (c.cmdparms[1]=="on") {skstat="enabled";} else {skstat="disabled";} sendNotice(`SpamKill has been ${skstat}`,c.user); return 1; } } else {badCommand("You are not authorized to run spamKill commands",c); return 1;} } } return 0; } modules["spamKill"] = {modfn:spamKill, summary: "user-friendly module for blocking spambots", desc: "The goal of spamKill is to block spam while still being friendly to legitimate users.\n"+ "It does not use word filters that cause unnecessary blocks, and does not require users to solve\n"+ "capcha problems or retype messages that were intercepted. While this bot will not prevent all spam\n"+ "spam, it will block the most common spam messages generated by chatroom bots. It works as follows:\n"+ "When a grey user types a message in chat for the first time, they are greeted with the following message:\n"+ "> Please enter the number \"NN\" to send your message. You only need to do this once, thanks for helping battle spam!\n"+ "If the user enters the requested number, their message is sent, and they will the be able to chat freely without\n"+ "future prompts. If the requested number is not entered (and most bots will not), the message will not be sent and\n"+ "the user will continue to be prompted each time they enter an new message", commands: {'/spamkill': "Display spamKill status (enabled or disabled)", '/spamkill on': 'Enable spamKill (spamKill is enabled by default at startup)', '/spamkill off': 'Disable spamKill' } }; /* ##################################################################################### # Module: fanClubShoutout (version 20201213.2323) ##################################################################################### */ cb.settings_choices.push( {name:'fwelcome',type:'str',defaultValue:'Warlock [fan] has arrived in the room',label:'Message to appear when [fan] enters the room',required:false}, {name:'fmoji',type:'str',defaultValue:':warlock',label:'Name of the emoji to be displayed at the beginning of fan members chat messages (eg :crown)',required:false}, {name:'testfan',type:'str',defaultValue:'',label:'Username to treat as fan club member for testing',required:false} ); function fanClubShoutout(mode,c) { let fwelcome="",fmoji="",testfan=""; if (cb.settings.testfan) {testfan=cb.settings.testfan;} if (mode=="onMessage") { if (c.isfan || c.user==testfan) { if (cb.settings.fmoji) { fmoji=cb.settings.fmoji; if (fmoji.substr(0,1)!==':') {fmoji=':'+fmoji;} c.msg.m=fmoji+" "+c.msg.m; } } } else if (mode=="onEnter") { u=c; if (u.in_fanclub || u.user==testfan) { if (cb.settings.fwelcome) { sendNotice(":blankx\n:blankx "+cb.settings.fwelcome.replace('[fan]',u.user)+" :blankx\n:blankx","","#ffffff","#009900"); } } } return 0; } modules["fanClubShoutout"] = {modfn:fanClubShoutout, summary: "provides recognition for fan club members", desc: "When a fan club member enters the room, a message is displayed. When a fan club member\n"+ "types a message in chat, an emoji is displayed at the beginning of the message line\n"+ "The room entry message and the chat message emoji can be specified when the bot is started" }; /* ##################################################################################### # Module: Help (version 20201213.2314) ##################################################################################### */ hfgcol="#000000";hbgcol="#00ee00"; function Help(mode,c) { if (mode=="command") { if ((c.cmd=="help")||(c.cmd=="h")||(c.cmd=="?")) { c.cmds[c.cmd]=1; if (c.cmdparmct==0) { let h=`:blankx Help for Bot ${botname}`; if (typeof(bothelp)=="string") {bothelp.split("\n").forEach(l=>{h+=`\n :blankx ${l}`})}; if (Object.keys(modules).length>0) { h+="\n :blankx This Bot includes the following functions: \n"; Object.keys(modules).forEach(m=>{ h+=` :blankx > "${m}"`; if (modules[m].summary) {h+=` - ${modules[m].summary}`;} h+=` \n`; }); h+=" :blankx For help on one of these functions, type \"/help [function]\""; } sendNotice(h,c.user,hfgcol,hbgcol,"normal"); return 1; } else if (c.cmdparmct==1) { let m = c.cmdparms[1]; if (m!=='*') { for (const mod in modules) {if (m==mod.toLowerCase()) {m=mod;}}; if (!modules[m]) {badCommand(`Function "${m}" not found. Type "/help" for the list of functions in this Bot`,c); return 1;} let h1=` :blankx Help for function "${m}"`; if (modules[m].summary) {h1+=` (${modules[m].summary})`;} let h2=""; if (modules[m].desc) {modules[m].desc.split("\n").forEach(l=>{h2+=` :blankx ${l}\n`});} if (modules[m].commands && Object.keys(modules[m].commands).length) { h2+=" :blankx Commands: \n"; Object.keys(modules[m].commands).forEach(c=>{h2+=` :blankx > "${c}" - ${modules[m].commands[c]}\n`}); } if (h2=="") {sendNotice("No help found for function "+m,c.user,hfgcol,hbgcol,"normal");} else {sendNotice(`${h1}\n${h2}`,c.user,hfgcol,hbgcol,"normal");} return 1; } else { let h=`Custom bot for <a href="https://chaturbate.com/${roomname}" style="color:#8888ff;text-decoration:underline;">`+ `${roomname}</a>'s room. Current modules included are: ${modnames}<br>`; Object.keys(modules).forEach(m=>{ let mdesc=""; if (modules[m].summary) {mdesc=" - "+modules[m].summary;} h+=`<br><span style="font-style:italic;font-weight:bold;text-decoration:underline;color:#0000ff;">${m}</span><b>${mdesc}</b><br>`; if (modules[m].desc) {modules[m].desc.split("\n").forEach(l=>{h+=`${l}<br>`});} if (modules[m].commands && Object.keys(modules[m].commands).length) { h+=`<span style="text-decoration:underline;font-style:italic;font-weight:bold;color:#000000;">Commands</span><br>`; Object.keys(modules[m].commands).forEach(c=>{ h+=` > <span style="font-style:italic;color:#000000;font-weight:bold;">${c}</span>`+ ` ${modules[m].commands[c]}<br>`; }); } }); sendNotice(`Copy this code to the bot description: ${h}`,c.user,"","","normal"); } } } } return 0; } modules["Help"] = {modfn:Help, summary: "get help on Bot functions and commands", desc: "Get help by typing /help, /h, or /?", commands: {'/h': "Get help on the Bot, and a list of all functions in the bot", '/h [function]': 'Get help on one of the functions in the bot, including it\'s commands', '/h *': "Display an auto-genertaed html description of the bot, that can be cut and paste into the Bot's description screen" } }; /* ############ # BOT CODE ############ */ //debug=1; bothelp="Enjoy Jace's room!\njacebot was created by alanstuart_"; roomname="jacethesage"; /* ################################################ # AFTER MODULES HAVE BEEN PRODCESSED, RUN INIT # ################################################ */ init(); /* ################################################ # Copy the text below to the bot description # ################################################ Custom bot for <a href="https://chaturbate.com/jacethesage" style="color:#8888ff;text-decoration: underline;">jacethesage</a> room. Current modules included are:spamKill,fanClubShoutout,Help */
© Copyright Chaturbate 2011- 2024. All Rights Reserved.