Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Components V2! #2196

Open
wants to merge 34 commits into
base: master
Choose a base branch
from
Open

Conversation

mplatypus
Copy link
Contributor

Summary

Adds support for components V2!

Checklist

  • I have run nox and all the pipelines have passed.
  • I have made unittests according to the code I have added/modified/deleted.

Related issues

mplatypus and others added 28 commits February 26, 2025 23:58
… collected before it can be fully implemented.
Signed-off-by: Platy <contact@mplaty.com>
…ents now contain the id object, along with the builders supporting the ID object.
…ata, and be more easily built, along with fixing an error with the MessageFileBuilder.
@@ -172,6 +172,9 @@ class MessageFlag(enums.Flag):
IS_VOICE_MESSAGE = 1 << 13
"""This message is a voice message."""

IS_COMPONENTS_V2 = 1 << 15
Copy link
Member

Choose a reason for hiding this comment

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

Could we automatically detect and set it when making the request instead of having users set it?

This flag is an unfortunate implementation decision that cannot be removed (as stated by devs), so we could at least remove it for the user

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We can, but there is a few components that are both v1 and v2 supportive, like the action row, and I believe they act different if you use the flag vs not use it. We could make it so any components that require the V2 flag, automatically adds it, but I would still leave the option for the end user to add it as well.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, that was my idea, force it when a components v2 is used

Comment on lines +410 to +429
proxy_resource: typing.Optional[files.Resource[files.AsyncReader]] = attrs.field(default=None, repr=False)
"""The proxied version of the resource, or [`None`][] if not present.

!!! note
This field cannot be set by bots or webhooks while sending an embed
and will be ignored during serialization. Expect this to be
populated on any received embed attached to a message event.
"""

width: undefined.UndefinedNoneOr[int] = attrs.field(repr=True)
"""The width of media item."""

height: undefined.UndefinedNoneOr[int] = attrs.field(repr=True)
"""The height of the media item."""

content_type: undefined.UndefinedNoneOr[str] = attrs.field(repr=True)
"""The content type of the media item."""

loading_state: undefined.UndefinedNoneOr[MediaLoadingType] = attrs.field(repr=True)
"""The loading state of the media item."""
Copy link
Member

Choose a reason for hiding this comment

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

These should never be allowed to be undefined, and in some cases, None

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The proxy_resource seems fine imo, unless it should be undefined.UndefinedOr[...] otherwise, should the rest just be typing.Optional[...]?

Comment on lines +491 to +495
description: typing.Optional[str] = attrs.field()
"""The description of the thumbnail."""

spoiler: typing.Optional[bool] = attrs.field()
"""If the thumbnail has a spoiler."""
Copy link
Member

Choose a reason for hiding this comment

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

Never None

"""The description of the thumbnail."""

spoiler: typing.Optional[bool] = attrs.field()
"""If the thumbnail has a spoiler."""
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"""If the thumbnail has a spoiler."""
"""Whether the thumbnail is marked as a spoiler."""

Comment on lines +477 to +482
components: typing.Sequence[TextDisplayComponent] = attrs.field()
"""The sections components."""

accessory: typing.Union[ButtonComponent, ThumbnailComponent] = attrs.field()
"""The sections accessory."""

Copy link
Member

Choose a reason for hiding this comment

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

Update to use the new typehints

"""The description of the gallery item."""

spoiler: bool = attrs.field()
"""If the gallery item has a spoiler."""
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"""If the gallery item has a spoiler."""
"""Whether the gallery item is marked as a spoiler."""

Comment on lines +554 to +558
accent_color: undefined.UndefinedNoneOr[colors.Color] = attrs.field()
"""The accent colour for the container.

If undefined, no accent color is set.
"""
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
accent_color: undefined.UndefinedNoneOr[colors.Color] = attrs.field()
"""The accent colour for the container.
If undefined, no accent color is set.
"""
accent_color: typing.Optional[colors.Color] = attrs.field()
"""The accent colour for the container."""

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The accent colour has three states, hidden = omitted (makes the message look like its got a box around it and thats it), default = None (the default colour value and then a colour) so wouldn't the original make more sense?

@davfsa
Copy link
Member

davfsa commented Mar 10, 2025

spoiler fields should also be renamed to is_spoiler in the models

mplatypus and others added 3 commits March 10, 2025 20:17
Co-authored-by: davfsa <davfsa@gmail.com>
Signed-off-by: Platy <mplatypus54@gmail.com>
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.

2 participants