Skip to content

feat(plugins): allow message introspection#6353

Merged
Mm2PL merged 27 commits intoChatterino:masterfrom
Nerixyz:feat/message-introspection
Dec 7, 2025
Merged

feat(plugins): allow message introspection#6353
Mm2PL merged 27 commits intoChatterino:masterfrom
Nerixyz:feat/message-introspection

Conversation

@Nerixyz
Copy link
Copy Markdown
Contributor

@Nerixyz Nerixyz commented Jul 22, 2025

Continuation of #5754. This allows users to introspect messages (i.e. look at the elements they're made up of).

The fields of messages are modifiable. Plugins can also add/remove elements. To allow Lua access to elements, they are wrapped in a custom iterator that keeps a reference to the original message. The fields of elements are mostly static right now. But it would be possible to allow modification.
A future feature could allow plugins to clone messages, which would then be modifiable again.

@Nerixyz Nerixyz force-pushed the feat/message-introspection branch from fdfa3c6 to 6140f6a Compare August 1, 2025 16:48
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

Comment thread tests/src/Plugins.cpp Outdated
Comment thread tests/src/Plugins.cpp Outdated
@Nerixyz Nerixyz marked this pull request as ready for review August 4, 2025 20:03
@Mm2PL Mm2PL self-requested a review August 4, 2025 21:25
Comment thread src/controllers/plugins/api/Message.cpp Outdated
Comment thread tests/src/Plugins.cpp Outdated
Comment thread tests/src/Plugins.cpp
Comment thread src/messages/MessageElement.hpp Outdated
Comment thread src/messages/MessageColor.cpp
Comment thread src/messages/MessageElement.hpp
Comment thread src/controllers/plugins/api/Message.hpp Outdated
@Nerixyz
Copy link
Copy Markdown
Contributor Author

Nerixyz commented Aug 9, 2025

I refactored the access for message elements. If a property for a message element doesn't exist, we now return nil instead of throwing. This is more consistent with non-existing properties (e.g. element.words on a badge will behave like element.foobar).

Copy link
Copy Markdown
Member

@pajlada pajlada left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just mini nit, otherwise looks good

Comment thread tests/src/Plugins.cpp Outdated
@pajlada
Copy link
Copy Markdown
Member

pajlada commented Aug 10, 2025

@Mm2PL feel free to merge this in when you've taken a look / tested it / you're happy with it

@Mm2PL Mm2PL self-requested a review August 10, 2025 11:09
Copy link
Copy Markdown
Collaborator

@Mm2PL Mm2PL left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks mostly good, just a couple nit picks. Please update the prose documentation to at least mention:

  • that introspection is now possible
  • that a concept of freezing a message exists
  • liquid messages may be modified

Comment thread src/controllers/plugins/api/Message.cpp Outdated
Comment thread src/controllers/plugins/api/Message.cpp Outdated
Comment thread src/controllers/plugins/api/Message.cpp Outdated
Comment thread src/controllers/plugins/api/Message.cpp Outdated
Comment thread src/controllers/plugins/api/Message.cpp Outdated
Comment thread src/controllers/plugins/api/Message.cpp Outdated
Comment thread src/controllers/plugins/api/Message.cpp Outdated
Comment thread src/controllers/plugins/api/Message.cpp Outdated
@Mm2PL Mm2PL enabled auto-merge (squash) December 7, 2025 14:17
Copy link
Copy Markdown
Contributor

@github-actions github-actions Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

clang-tidy made some suggestions

}
else
{
return visitOne<TReturn, Rest...>(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: use explicit 'this->' for member access [chatterino-explicit-this]

Suggested change
return visitOne<TReturn, Rest...>(
return this->visitOne<TReturn, Rest...>(

bool firstIteration = true;
for (Word &word : this->words_)
for (const auto &word : this->words_)
{
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

warning: c++11 range-loop might detach Qt container (QStringList) [clazy-range-loop-detach]

Suggested change
{
;
)std::as_const(this->words_)

Comment thread tests/src/Plugins.cpp
Comment thread tests/src/Plugins.cpp
Comment thread tests/src/Plugins.cpp
Comment thread tests/src/Plugins.cpp
Comment thread tests/src/Plugins.cpp
Comment thread tests/src/Plugins.cpp
Comment thread tests/src/Plugins.cpp
Comment thread tests/src/Plugins.cpp
@Mm2PL Mm2PL merged commit 74b4674 into Chatterino:master Dec 7, 2025
17 checks passed
@Mm2PL Mm2PL removed their assignment Dec 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants