Last active
June 15, 2018 16:30
-
-
Save keithcurtis1/975f4286a0fc39eee37465f903faee48 to your computer and use it in GitHub Desktop.
This calls the Bio of a character, but sends it openly 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
//!cbio | |
//!cgmnotes | |
//!cbio-Some Line Beginning | |
//!cgmnotes-Some Line Beginning | |
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(/^!c(gmnotes|bio)/) && playerIsGM(msg.playerid) ){ | |
let match=msg.content.match(/^!c(gmnotes|bio)(?:-(.*))?$/), | |
where = match[1], | |
regex; | |
if(match && match[2]){ | |
regex = new RegExp(`^${match[2]}`,'i'); | |
} | |
_.chain(msg.selected) | |
.map( s => getObj('graphic',s._id)) | |
.reject(_.isUndefined) | |
.map( t => getObj('character', t.get('represents'))) | |
.reject(_.isUndefined) | |
.each( c => c.get(where, (val) => { | |
if(null !== val && 'null' !== val && val.length>0 ){ | |
if(regex){ | |
let lines=_.filter( | |
decodeUnicode(val).split(/(?:[\n\r]+|<br\/?>)/), | |
(l)=>regex.test(l.replace(/<[^>]*>/g,'')) | |
).join('\r'); | |
sendChat(c.get('name'),`/w gm ` + lines); | |
} else { | |
sendChat(c.get('name'),'/w gm &{template:5e-shaped}{{title=' + c.get('name') +'}} {{text='+ decodeUnicode(val)+'}}'); | |
} | |
} | |
})); | |
} | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment