#the content field of the chat message

1 messages ยท Page 1 of 1 (latest)

cerulean siren
#

It's for PBTA

"<section class="pbta-chat-card">
  <div class="cell cell--chat">
    <div class="chat-title row flexrow">
      
      <h2 class="cell__title">Strength</h2>
    </div>
      <div class="row"><em>Strength (+1)</em></div>
    
    
    
      <div class="row result partial">
        <div class="result-label">Partial success</div>
      </div>
    <div class="roll partial"><div class="dice-roll">
    <div class="dice-result">
        <div class="dice-formula">2d6 + 1 + 0</div>
        <div class="dice-tooltip">
    <section class="tooltip-part">
        <div class="dice">
            <header class="part-header flexrow">
                <span class="part-formula">2d6</span>
                
                <span class="part-total">8</span>
            </header>
            <ol class="dice-rolls">
                <li class="roll die d6">5</li>
                <li class="roll die d6">3</li>
            </ol>
        </div>
    </section>
</div>

        <h4 class="dice-total">9</h4>
    </div>
</div>
</div>
  </div>
</section>"```
#

That's the content of the "content" field in the data

oblique stream
#

at this point, its too late

#

as the html has been generated for the roll

cerulean siren
#

Damn - this is in preCreate too

oblique stream
#

you need to find a place before this html is generated OR come in after the chat message has been created, extract any roll data it has in its flags, create a new roll from that data, modify the roll, evaluate the roll, and store it back in the chatmessage's flags

cerulean siren
#

With CONFIG.debug.hooks I don't see any other hooks being called when I roll the "item" unfortunately

#

I don't see any roll data in the flags of either preCreate or CreateChatMessage - the only roll data is in that HTML

oblique stream
#

indeed, so you might have to parse the HTML directly after the chat message is rendered

#

which requires a world script to keep it in sync for all clients

cerulean siren
#

Yeah I have that part as a world script already and can do it on render of the chat card - but how would I update that card?

#
let searchString = `<div class="dice-formula">2d6 + 1 + 0</div>`;

let replaceString = `<div class="dice-formula">2d6 + 1 + ${mastery}</div>;`;```
#

IE: here was what I was thinking - I just don't know how to "apply" this so that the chat card is updated

oblique stream
#

you update the chat message's "content" field with the new HTML string

cerulean siren
#

So if I do this ```content = content.replace(searchString, replaceString);


How would I apply that to the chat card?
cerulean siren
#

I can see my content has the right content, but the chat card isn't updating in chat

oblique stream
#

a normal update

#

updateSource just modifies the local data and does not trigger update hooks

cerulean siren
oblique stream
#

what hook are you using?

cerulean siren
#

renderChatMessage

#
 
 let actorId = data.speaker.actor;
 let actor = game.actors.get(actorId);
 let content = data.content;
 let rolltype;
if (content.includes("Strength")) rolltype='str';
if (content.includes("Agility")) rolltype="agi";
if (content.includes("Influence")) rolltype="inf";
if (content.includes("Wits")) rolltype="wit";
if (content.includes("Arcane")) rolltype="arc";
if (content.includes("Luck")) rolltype="luk";

let actorStat = actor.system.stats[rolltype];
let mastery = actor.system.attrTop.hold.value;
let searchString = `<div class="dice-formula">2d6 + 1 + 0</div>`;
let replaceString = `<div class="dice-formula">2d6 + 1 + ${mastery}</div>;`;
content = content.replace(searchString, replaceString);
let searchString2 = `</em></div>`;
let replaceString2 = ` Mastery (+${mastery})</em></div>`;
content = content.replace(searchString2, replaceString2);
rolltotal = content.substr(content.indexOf('"dice-total">')+1, 1);

let searchString3 = `<h4 class="dice-total">4</h4>`;
let replaceString3 = `<div class="dice-formula">2d6 + 1 + ${mastery}</div>;`;


let chatMessage = game.messages.get(data._id);

chatMessage.update({ content: content });
//if (actorStat.toggle)
//{
    
//}

});```
oblique stream
#

you may need to add some info to the optional argument of update so your hook can look at it and say "wait, this is my update, dont do anything"

cerulean siren
#

I was hoping isroll would be enabled for the original roll but its not

oblique stream
cerulean siren
#

Is adding the flags to the chat message the same?

#

I did this chatMessage.update({ content: content, ishookupdated: true }); but ishookupdated doesn't exist when I go look for it

oblique stream
#

not flagging the chatmessage, adding information to the update process so we know its "us" doing it

cerulean siren
#

Yeah that's what I tried to do with the ishookupdated - is that not the right way?

oblique stream
#

no, because that would cause another render hook and that is causing the infinite loop

cerulean siren
#

I'm confused haha

At the top of my hook I was going to check if the chat message had ishookupdated and if it did then not to run the code

cerulean siren
oblique stream
#

yes, but as an object (your snippet is invalid syntax)

cerulean siren
#

Is that correct?

oblique stream
#

nods, yea

cerulean siren
oblique stream
#

it will be present in the preUpdateChatMessage and updateChatMessage hooks

cerulean siren
oblique stream
#

create the renderChatMessage hook as a Hooks.once when your preUpdateChatMessage hook detects (or doesnt detect) your options flag

cerulean siren
oblique stream
#

im not 100% sure without digging into the code flow myself, but you definitely have the right idea

#

either a hook needs to fire, or needs to not fire, based on data received during preUpdate

cerulean siren
#

content appears to update, but flags doesn't show the flag I'm trying to add

oblique stream
#

my use of "options flag" may have been misleading

#

i dont think you need to actually set a flag on the chatmessage document

#

just that second options object with "ishookflag" should propogate throughout all chat message updating hooks

cerulean siren
#

It does but I don't know how to trigger the original update (since the update hooks won't be triggered)

#

IE: How do I trigger my function to update the chat message when the update chat message hook won't be called yet

#

If I put it under RenderChatMessage I can't grab that option so I don't know if it's been done

oblique stream
#

you will be using preCreate to detect if you need to operate on this chat message, i think

cerulean siren
#

preCreateChatMessage? It will have that option?

oblique stream
#

that's where you would likely set the option -- you add any info to the creation options that your later hooks need to make their decisions. Something that says "Hey, this is a roll message that needs or may need to be modified".

#

then, when the later hooks "take action" and update the chat message, they will add an option to the update that says "hey, this message has been handled, dont take any further action" to any of your hooks

cerulean siren
oblique stream
#

in the hook, you receive several arguments, the...second, or third (i forget) is the current options argument

#

simply say options.ishookflag = true

#

once you know its a message you want to handle

cerulean siren
#

Oh ok!

cerulean siren
#

Result (Mastery part is added)

cerulean siren
oblique stream
#

๐Ÿ™Œ ๐Ÿฅณ so happy to hear it!

#

this is a deceptively complex topic and solving it has 100% increased your Foundry skill set