Skip to content

🚧 Initial Discord message components v2 implementation#1294

Merged
valzargaming merged 29 commits intomasterfrom
components-v2
Apr 24, 2025
Merged

🚧 Initial Discord message components v2 implementation#1294
valzargaming merged 29 commits intomasterfrom
components-v2

Conversation

@Log1x
Copy link
Copy Markdown
Member

@Log1x Log1x commented Feb 21, 2025

🚧 Work in progress.

Completely blind & untested. Should be able to try it later today.

Edit: everything appears to be functional.

Screenshot

Comment thread src/Discord/Builders/MessageBuilder.php Outdated
Comment thread src/Discord/Builders/Components/UnfurledMediaItem.php Outdated
@valzargaming
Copy link
Copy Markdown
Member

The v2 contract was an excellent idea, and something I'd like to see in other parts of the library. It would certainly cut down on a lost of instances of checking against hardcoded types like this.

Comment thread src/Discord/Builders/MessageBuilder.php Outdated
Comment thread src/Discord/Parts/Channel/Message.php Outdated
Comment thread src/Discord/Builders/MessageBuilder.php Outdated
Copy link
Copy Markdown
Contributor

@SQKo SQKo left a comment

Choose a reason for hiding this comment

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

Please also adjust the class implements Components\xx to have the namespace imported per my previous suggestion

Comment thread src/Discord/Builders/Components/UnfurledMediaItem.php Outdated
public function setUrl(string $url): self
{
$this->url = $url;

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.

Implement validation of $url like in Embed::ensureValidUrl()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do we know if it's the same spec? We could just copy-paste the function here and do the same thing.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I've confirmed it's exactly the same except for File, in which case only attachment is allowed.

Comment thread src/Discord/Builders/Components/Thumbnail.php Outdated
Comment thread src/Discord/Builders/Components/Separator.php Outdated
Comment thread src/Discord/Builders/Components/Section.php Outdated
Comment thread src/Discord/Builders/Components/Section.php Outdated
Comment thread src/Discord/Builders/Components/MediaGalleryItem.php Outdated
Comment thread src/Discord/Builders/Components/Container.php
@SQKo
Copy link
Copy Markdown
Contributor

SQKo commented Feb 23, 2025

According to the spec, using the components v2 may disable content and embeds, it would be good to warn the users in the MessageBuilder to avoid confusion

Also seems this PR has not supported webhooks yet

Comment thread src/Discord/Builders/MessageBuilder.php
Comment thread src/Discord/Builders/Components/UnfurledMediaItem.php Outdated
Comment thread src/Discord/Builders/Components/Section.php Outdated
valzargaming and others added 13 commits February 25, 2025 08:16
Co-authored-by: SQKo <87897282+SQKo@users.noreply.github.com>
Co-authored-by: SQKo <87897282+SQKo@users.noreply.github.com>
Co-authored-by: SQKo <87897282+SQKo@users.noreply.github.com>
Co-authored-by: SQKo <87897282+SQKo@users.noreply.github.com>
Co-authored-by: SQKo <87897282+SQKo@users.noreply.github.com>
Co-authored-by: SQKo <87897282+SQKo@users.noreply.github.com>
PHPDoc specifies the current restrictions on Thumbnail and Button, but the datatype should be left open as Component for now as this list of possible returns may be subject to change.
Co-authored-by: SQKo <87897282+SQKo@users.noreply.github.com>
Comment thread src/Discord/Builders/MessageBuilder.php Outdated
@Log1x Log1x marked this pull request as ready for review March 23, 2025 04:28
valzargaming
valzargaming previously approved these changes Apr 9, 2025
@valzargaming valzargaming merged commit b8d41da into master Apr 24, 2025
2 checks passed
@valzargaming valzargaming deleted the components-v2 branch June 1, 2025 06:32
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.

4 participants