Skip to content

Instantly share code, notes, and snippets.

@keithcurtis1
Created March 29, 2021 15:03
Show Gist options
  • Save keithcurtis1/c45d64bdd7c16ce890f76bdca773ac2c to your computer and use it in GitHub Desktop.
Save keithcurtis1/c45d64bdd7c16ce890f76bdca773ac2c to your computer and use it in GitHub Desktop.
Creates dialog boxes with token images for Roll20 *!dialog [token_id] --[message]*
on('ready',()=>{
on('chat:message',(msg)=>{
if('api' === msg.type && /^!dialog/i.test(msg.content)){
let p = getObj('player',msg.playerid);
let theMessage = "";
const openBox = "<div style='border: 0px none; margin-top: 10px; border-radius: 35px 6px 6px 6px; box-shadow: 2px 2px 4px 2px #000; min-height:60px; display: block; padding:5px; text-align: left; white-space: pre-wrap;'>";
const closeBox = "</div>";
const buttonStyle = "'background-color: transparent; align:right; font-size: 0.8em; line-height:1.2; font-family: sans-serif; font-style: normal; font-weight: normal; padding: 0px;color: #ce0f69;display: inline-block;border: none; !important'";
function imageFormat(imgsrc){
return `<img style = 'max-height: 70px; float:left; margin:-15px 5px 5px -15px' src = '${imgsrc}'>`;
}
function messageFormat(theMessage){
return `<p style = 'font-size: 1.4em; line-height:1.2; font-family: serif; font-style: italic; font-weight: 700; color: #4C3F1E; margin: 5px;'>${theMessage}</p>`;
}
function dialog(tokenImage, theMessage) {
return '<a style = ' + buttonStyle + ' href="' + link + '">' + name + '</a>';
}
if(p){
let a = msg.content.split(/\s+/);
if(a.length>1) {
let t = findObjs({
type: 'graphic',
id: a[1]
})[0];
if (msg.content.split(" --")[1]) {
theMessage = msg.content.split(" --")[1];
}
else {
theMessage = "says nothing."
}
//clean up the message
theMessage = theMessage
.replace(/(\[.*?\])(\(.*?\))+/g, "$2$1")
.replace(/(\()+/g, "<a style =" + buttonStyle + " href = '")
.replace(/(\)\[)+/g, "'>")
.replace(/(\])+/g, "</a>")
.replace(/\/n/g, "<BR>")
.replace(/Q{/g, '?{')
.replace(/A{/g, '&#64;{');
if(t){
let tokenImage = t.get('imgsrc');
let tokenName = t.get('name');
sendChat(tokenName,"" +openBox + imageFormat(tokenImage) + messageFormat(theMessage) + closeBox);
} else {
sendChat('',`/w gm No character found for ID <b>${a[1]}</b>!`);
}
} else {
sendChat('',`/w GM Other messageSwitching to self.`);
}
}
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment