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

GM Note script and 2 GMs

Hello everyone, I was using the nice script that I found in the forum here to put notes on my Map tokens and have them in chat if i type in the command. Now in a new campaign we have 2 GMs and the script stops sending messages as soon as the 2nd GM connects as GM. Any idea on how to fix this?       on('ready',function(){           'use strict';                  on('chat:message',function(msg){               if('api' === msg.type && msg.content.match(/^!wgmnote/) && playerIsGM(msg.playerid) ){                   let match=msg.content.match(/^!wgmnote-(.*)$/),                       regex;                   if(match && match[1]){                       regex = new RegExp(`^${match[1]}`,'i');                   }                                                          _.chain(msg.selected)                       .map( s => getObj('graphic',s._id))                       .reject(_.isUndefined)                       .reject((o)=>o.get('gmnotes').length===0)                       .each( o => {                           if(regex){                               let lines=_.filter(decodeURIComponent(o.get('gmnotes')).split(/(?:[\n\r]+|<br\/?>)/),(l)=>regex.test(l)).join('\r');                              sendChat(o.get('name'),'/w gm '+ decodeURIComponent(o.get('wgmnotes')));                           } else {                               sendChat(o.get('name'),'/w gm '+ decodeURIComponent(o.get('gmnotes')));                           }                       });               }           });       });
1525302129
The Aaron
Pro
API Scripter
Hmm.  That is strange.  It should go to all gms.   Do you want to PM me an invite and GM me and I'll come take a look?
1525308805

Edited 1525308864
I sent you an invite. Sometimes it works but only ONCE. Then I would need to restart/save the script to get it to work one more time. So weird. URIError: URI malformed URIError: URI malformed at decodeURIComponent (<anonymous>) at _.chain.map.reject.reject.each.o (apiscript.js:567:64) at Function._.each._.forEach (/home/node/d20-api-server/node_modules/underscore/underscore.js:153:9) at _.(anonymous function) [as each] (/home/node/d20-api-server/node_modules/underscore/underscore.js:1496:34) at apiscript.js:563:24 at eval (eval at <anonymous> (/home/node/d20-api-server/api.js:151:1), <anonymous>:65:16) at Object.publish (eval at <anonymous> (/home/node/d20-api-server/api.js:151:1), <anonymous>:70:8) at /home/node/d20-api-server/api.js:1634:12 at /home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:93:560 at hc (/home/node/d20-api-server/node_modules/firebase/lib/firebase-node.js:39:147)
1525310488
The Aaron
Pro
API Scripter
Ah, that's probably related to the encoding of the content, rather than just the script.  Do you have any special characters in there?  I need to revisit that...
1525312116
The Aaron
Pro
API Scripter
Ok.  The issue was UTF-16 characters are not decoded properly by decodeURIComponent().  As it turns out, I had been thinking these were encoded using encodeURIComponent() whereas they were actually encoded using escape().  Switching to unescape() fixes the issue:   on('ready',function(){           'use strict';                  on('chat:message',function(msg){               if('api' === msg.type && msg.content.match(/^!wgmnote/) && playerIsGM(msg.playerid) ){                   let match=msg.content.match(/^!wgmnote-(.*)$/),                       regex;                   if(match && match[1]){                       regex = new RegExp(`^${match[1]}`,'i');                   }                                                          _.chain(msg.selected)                       .map( s => getObj('graphic',s._id))                       .reject(_.isUndefined)                       .reject((o)=>o.get('gmnotes').length===0)                       .each( o => {                           if(regex){                               let lines=_.filter( unescape (o.get('gmnotes')).split(/(?:[\n\r]+|<br\/?>)/),(l)=>regex.test(l)).join('\r');                              sendChat(o.get('name'),'/w gm '+ decodeURIComponent(o.get('wgmnotes')));                           } else {                               sendChat(o.get('name'),'/w gm '+ unescape (o.get('gmnotes')));                           }                       });               }           });       }) I've already updated your game to fix this.
1525312687
The Aaron
Pro
API Scripter
Here's a revised version that lets you use either !wgmnote to whisper or !gmnote to speak outright.  And of course, you can use !wgmnote-something or !gmnote-something to show just the lines that start with "something": on('ready',()=>{     const blockElements = [         'p', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'ol', 'ul', 'pre', 'address',         'blockquote', 'dl', 'div', 'fieldset', 'form', 'hr', 'noscript', 'table','br'     ];     const rStart=new RegExp(`<\\s*(?:${blockElements.join('|')})\\b[^>]*>`,'ig');     const rEnd=new RegExp(`<\\s*\\/\\s*(?:${blockElements.join('|')})\\b[^>]*>`,'ig');     const getLines = (str) =>          (rStart.test(str)             ? str                 .replace(/[\n\r]+/g,' ')                 .replace(rStart,"\r$&")                 .replace(rEnd,"$&\r")                 .split(/[\n\r]+/)             : str                 .split(/(?:[\n\r]+|<br\/?>)/)             )             .map((s)=>s.trim())             .filter((s)=>s.length)             ;     const cmdRegex = /^!(w?)gmnote(?:-(.*))?$/i;     on('chat:message',(msg) => {         if('api' === msg.type && cmdRegex.test(msg.content) && playerIsGM(msg.playerid) ){             let match=msg.content.match(cmdRegex),                 output = match[1].length ? '/w gm ' : '',                 regex;             if(match[2]){                 regex = new RegExp(`^${match[2]}`,'i');             }                                              _.chain(msg.selected)                 .map( s => getObj('graphic',s._id))                 .reject(_.isUndefined)                 .reject((o)=>o.get('gmnotes').length===0)                 .each( o => {                     if(regex){                         let lines = _.filter(                             getLines(unescape(o.get('gmnotes'))),                             (l) => regex.test(l.replace(/<[^>]*>/g,''))                         ).join('<br>');                         sendChat(o.get('name'), `${output}${lines}`);                     } else {                         sendChat(o.get('name'), `${output}${unescape(o.get('gmnotes')).replace(/(?:[\n\r]+|<br\/?>)/g,'<br>')}`);                     }                 });         }     }); }); I left this one in your game aswell.
1525319923
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Aaron, you should consolidate that into the character notes script you wrote last week. You could have one API notes script to rule them all. !tnote --sends token gm note to chat !wtnote --whispers token gm note to chat !cnote --sends character gm note to chat !wcnote --whispers character gm note to chat !bio --sends character bio to chat !wbio --whispers character bio to chat or something along those lines.
wait character note script? where
1525322921
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Right  here .
I love you, this made my life sooo much easier! :D
1525349862
The Aaron
Pro
API Scripter
Yeah, probably so. The character notes are encoded differently than the token ones. Still a good idea. 
1525355512
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
It sounds like a really useful tool. The best kind, one which allows you to solve many different types of problems.
1525355659
The Aaron
Pro
API Scripter
Hey.. are you calling me a tool?  =D
1525355889
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
No sir, you are like unto our noble ancestors homo habilis, or australopithecus: a tool maker !
1525357106
The Aaron
Pro
API Scripter
HAHAHAHAHAHAHA!