Roll20 uses cookies to improve your experience on our site. Cookies enable you to enjoy certain features, social sharing functionality, and tailor message and display ads to your interests on our site and others. They also help us understand how our site is being used. By continuing to use our site, you consent to our use of cookies. Update your cookie preferences .
×
Create a free account

[Script Idea]: Test Mode - is this possible?

1618083990

Edited 1618084014
I had an idea last night based on something I've hacked together and I'm wondering if it would be possible for those of you who have much better scripting skills to improve this idea. I previously took a little scriptlet from The Aaron  and modified it to make it so I could send messages that wouldn't get sent to the Chat Archive.  I'm sure this basic script could be improved/streamlined on its own, but it works for what I need it to do: NoArchive Scriptlet: on('ready', () => {     const processInlinerolls = (msg) => {         if(_.has(msg,'inlinerolls')){             return _.chain(msg.inlinerolls)                 .reduce(function(m,v,k){                     let ti=_.reduce(v.results.rolls,function(m2,v2){                         if(_.has(v2,'table')){                             m2.push(_.reduce(v2.results,function(m3,v3){                                 m3.push(v3.tableItem.name);                                 return m3;                             },[]).join(', '));                         }                         return m2;                     },[]).join(', ');                     m['$[['+k+']]']= (ti.length && ti) || v.results.total || 0;                     return m;                 },{})                 .reduce(function(m,v,k){                     return m.replace(k,v);                 },msg.content)                 .value();         } else {             return msg.content;         }     };          let lastPlayerId;     on('chat:message', (msg) => {         if('api' !== msg.type ){             return;         }         let args = processInlinerolls(msg).split(/\s+/);         switch(args.shift()){             case '!noarchive':              case '!na':     { const who=(getObj('player',('API'===msg.playerid ? lastPlayerId : msg.playerid))||{get:()=>'API'}).get('_displayname'); let content = args.join(' '); if(_.has(msg,'rolltemplate') && _.isString(msg.rolltemplate) && msg.rolltemplate.length){ content = content.replace(/\{\{/,'&{template:'+msg.rolltemplate+'} {{'); } sendChat('(NoArchive)',`${content}`,null,{noarchive:true});                     log(`NoArchive content: ${content}`); }                 break;             case '!test':    { const who=(getObj('player',('API'===msg.playerid ? lastPlayerId : msg.playerid))||{get:()=>'API'}).get('_displayname'); let content = args.join(' '); if(_.has(msg,'rolltemplate') && _.isString(msg.rolltemplate) && msg.rolltemplate.length){ content = content.replace(/\{\{/,'&{template:'+msg.rolltemplate+'} {{'); } sendChat('(Test)',`${content}`,null,{noarchive:true});                     log(`Test content: ${content}`); }                 break;             default:                 if(/\s!noarchive\b/.test(msg.content)){                     lastPlayerId = msg.playerid;                 }                 break;         }     }); }); I use !noarchive, !na, or !test to send messages without them being archived. Great for testing things, as well as lots of macros for chat menus that I don't want cluttering up the archive later. 'Test Mode' Script Idea here: So my idea is: could a script basically intercept all commands and adjust them to add the '{noarchive:true}' option, so that the message is not sent to the chat archive?  I've seen requests previously for a Test Mode or way for GMs to test things without creating unintentional spoilers.  The /talktomyself feature works, unless you are using API scripts, which is a big limitation. So my thought is to have a script that can be toggled on and off: !TestMode --on !TestMode --off  While it's on, all messages from the GM are changed to not be archived.  It would be nice if there were a visual indication at the same time (like what you see with /talktomyself or the API Heartbeat script), or another idea would be a GM whispered chat message every so often that tells the GM that they are still in Test Mode if a persistent indicator isn't possible. What are the thoughts from you awesome script creators out there? Thanks for any ideas or feedback!
1618170153
timmaugh
Pro
API Scripter
What you are talking about is a meta-script. You want your script to intercept other API calls and tack on the noarchive flag before it reaches the chat... Based on the other meta scripting stuff I've done, I would suggest a two pronged approach: 1) to turn the whole operation on/off with a dedicated command line as you suggested, and 2) to turn it on for an individual message with an inline flag that gets parsed out... something like (following the syntax token structure I've used for my meta-stuff)... {& test} ... or... {& noarchive} . You let the script register using the shin-kicking mechanic to get to the head (well, head-ish) of the line, and it does the rest. Ooooorrrrr.... you build it to register to the Meta Toolbox I'm about to release, and then you can control when it should run compared to other meta scripts.
timmaugh said: What you are talking about is a meta-script. You want your script to intercept other API calls and tack on the noarchive flag before it reaches the chat... Yep! I was hoping that would be possible, and I thought I had seen something to that effect before.  Now that I look through some of your posts again it looks like that's one of the things that APILogic does, so that's good news! Based on the other meta scripting stuff I've done, I would suggest a two pronged approach: 1) to turn the whole operation on/off with a dedicated command line as you suggested, and 2) to turn it on for an individual message with an inline flag that gets parsed out... something like (following the syntax token structure I've used for my meta-stuff)...  {& test} ... or...  {& noarchive} . I've already got the individual message portion working with !na or !noarchive or !test (as I showed above).  But when I'm testing I don't want to have to type it for each message I'm putting into chat, and I'm also hoping that it'll be possible to intercept rolls from characters sheets and things as well, so if I'm setting up a new monster and I accidentally click on an attack, that it doesn't get saved into the chat archive for my players to find when they log in. You let the script register using the shin-kicking mechanic to get to the head (well, head-ish) of the line, and it does the rest. Ooooorrrrr.... you build it to register to the Meta Toolbox I'm about to release, and then you can control when it should run compared to other meta scripts. Sounds like you've got some more really cool stuff coming! I have the most basic javascript understanding, so it's all pretty much greek to me so far. :) I think a 'Test Mode' API would be super useful, but I have no idea how to actually code or implement it.  So my first step was to see if it was even possible at a fundamental level (it sounds like it is), and next is to see if any scripters here are interested in coding it if it's simple, or seeing if it's something I can hack together myself. Thanks!
1618196284
timmaugh
Pro
API Scripter
I should offer a couple of clarifications... 1) I had not tested whether you could flip the switch you want to flip of the message (turning it to "no archive = true" after the message has been sent)... but I have now. I don't see where the message options are exposed to the API, but I could be wrong about that. 2) if a straight meta-script won't work, there is a... more invasive... way of intercepting the API messages using a quirk of javascript, itself. 3) However, even with the more invasive way of trapping messages, you can only intercept API messages. Roll template messages originating from a sheet wouldn't be caught, nor would any that were intended for the chat output, directly (ie, sendChat('', 'Boontermintle waves his hands, but nothing happens.'). Not sure if that gets you as far as you were hoping to go...