Created
June 12, 2018 06:41
-
-
Save keithcurtis1/139848e1832fd9fba4efc90c14ee1a60 to your computer and use it in GitHub Desktop.
This pulls the GM notes from a token on Roll20 and whispers them to the chat
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
on('ready',function(){ | |
'use strict'; | |
const decodeUnicode = (str) => str.replace(/%u[0-9a-fA-F]{2,4}/g,(m)=>String.fromCharCode(parseInt(m.slice(2),16))); | |
on('chat:message',function(msg){ | |
if('api' === msg.type && msg.content.match(/^!gmnote/) && playerIsGM(msg.playerid) ){ | |
let match=msg.content.match(/^!gmnote-(.*)$/), | |
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(decodeUnicode(o.get('gmnotes'))).split(/(?:[\n\r]+|<br\/?>)/),(l)=>regex.test(l)).join('\r'); | |
sendChat(o.get('name'),`/w gm ` + lines); | |
} else { | |
sendChat(o.get('name'),'/w gm &{template:5e-shaped}{{title=' + o.get('name') +'}} {{text='+ decodeURIComponent(decodeUnicode(o.get('gmnotes')))+'\n[Bio to GM](!cbio) | [to Players](!pcbio) | [Character Notes](!cnote)'+'}}'); | |
} | |
}); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment