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

Can the API intercept and cancel chats that don't begin with ! ?

I wrote a script that processes rolls in chats to hide the modifiers of those rolls from players.  This script is working great with messages that begin with a bang "!".  But I need to run this script on every roll made by players in my game.   What I would really like is a way that I could intercept and process all chat messages with rolls so that players would only see my modified version of the roll instead of the default one.  I can use onChat to detect and respond to all chat messages.  But I don't see a way to prevent non-api messages, those without a bang, from being shown to players.  Am I missing something. If it can't be done, I can work around it by modifying EVERY roll in my campaign.  But that's going to be a lot of work and I'm afraid that I will miss something.  I would much rather let the script do the work for me.
1653254553
keithcurtis
Forum Champion
Marketplace Creator
API Scripter
Is this for an existing sheet? The Shaped sheet for D&D has a feature for its roll templates to add an inline style of "display: none;" to each part of the template. GMs can then use a stylus style to reveal those portions only to them. What I'm saying is, if this is for a custom sheet, you could try adopting that approach.
1653265440

Edited 1653265601
Oosh
Sheet Author
API Scripter
The short answer is "no". The API sandbox responds to a normal chat message being published to firebase, in exactly the same way as a player's browser does. Firebase alerts all subscribed clients that there's a new message, and nothing short of mangling Roll20 code can stop that. You'd also be disabling all general chat messages for players even if you did find a way to do that. Keith's suggestion is one way around it, but as he said it requires that you're using a custom sheet (or a sheet you can modify) so you can use some CSS trickery to hide the output. The chat messages are still being appended to the pages HTML in their entirety, and a blank entry will pop up in the chat bar since you can't hide the chat message wrapper - it's out of bounds for character sheet CSS. If it's a custom sheet though, custom roll parsing can prevent a roll from being sent to chat if conditions aren't met (no spell slots remaining, or whatever). That's all code that runs before anything gets published to firebase. For an existing sheet, client-side code is the only other way to intercept the roll between character sheet and firebase. This would need to be installed & run by every player (and obviously it also needs to be coded - no small feat).
Thank you both for your speedy replies.  I was afraid that the API wouldn't be able to do what I needed.  But before I went through all the pain of modifying every roll on the character sheet, I wanted to make sure that it wouldn't be wasted effort.