From e90c1e94cdd2fc9af7ef04dbd51d97060c9b3821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alex=20N=C3=B8rgaard?= Date: Wed, 26 Mar 2025 20:42:50 +0000 Subject: [PATCH] Revert "Make embed flags required and add them to all media fields" This reverts commit cab4732b7ea8008ace32f9bd6285f7d4b3a99299. --- discord/embeds.py | 64 ++++++++++++++++++++---------------------- discord/types/embed.py | 22 ++++++++++++--- 2 files changed, 49 insertions(+), 37 deletions(-) diff --git a/discord/embeds.py b/discord/embeds.py index b35582b9f..4be644688 100644 --- a/discord/embeds.py +++ b/discord/embeds.py @@ -77,7 +77,12 @@ if TYPE_CHECKING: proxy_url: Optional[str] height: Optional[int] width: Optional[int] - flags: AttachmentFlags + flags: Optional[AttachmentFlags] + + class _EmbedVideoProxy(Protocol): + url: Optional[str] + height: Optional[int] + width: Optional[int] class _EmbedProviderProxy(Protocol): name: Optional[str] @@ -143,6 +148,10 @@ class Embed: colour: Optional[Union[:class:`Colour`, :class:`int`]] The colour code of the embed. Aliased to ``color`` as well. This can be set during initialisation. + flags: Optional[:class:`EmbedFlags`] + The flags of this embed. + + .. versionadded:: 2.5 """ __slots__ = ( @@ -159,7 +168,7 @@ class Embed: '_author', '_fields', 'description', - '_flags', + 'flags', ) def __init__( @@ -179,7 +188,7 @@ class Embed: self.type: EmbedType = type self.url: Optional[str] = url self.description: Optional[str] = description - self._flags: int = 0 + self.flags: Optional[EmbedFlags] = None if self.title is not None: self.title = str(self.title) @@ -214,7 +223,6 @@ class Embed: self.type = data.get('type', None) self.description = data.get('description', None) self.url = data.get('url', None) - self._flags = data.get('flags', 0) if self.title is not None: self.title = str(self.title) @@ -245,6 +253,11 @@ class Embed: else: setattr(self, '_' + attr, value) + try: + self.flags = EmbedFlags._from_value(data['flags']) + except KeyError: + pass + return self def copy(self) -> Self: @@ -305,17 +318,8 @@ class Embed: and self.image == other.image and self.provider == other.provider and self.video == other.video - and self._flags == other._flags ) - @property - def flags(self) -> EmbedFlags: - """:class:`EmbedFlags`: The flags of this embed. - - .. versionadded:: 2.5 - """ - return EmbedFlags._from_value(self._flags or 0) - @property def colour(self) -> Optional[Colour]: return getattr(self, '_colour', None) @@ -404,17 +408,18 @@ class Embed: Possible attributes you can access are: - - ``url`` for the image URL. - - ``proxy_url`` for the proxied image URL. - - ``width`` for the image width. - - ``height`` for the image height. - - ``flags`` for the image's attachment flags. + - ``url`` + - ``proxy_url`` + - ``width`` + - ``height`` + - ``flags`` If the attribute has no value then ``None`` is returned. """ # Lying to the type checker for better developer UX. data = getattr(self, '_image', {}) - data['flags'] = AttachmentFlags._from_value(data.get('flags', 0)) + if 'flags' in data: + data['flags'] = AttachmentFlags._from_value(data['flags']) return EmbedProxy(data) # type: ignore def set_image(self, *, url: Optional[Any]) -> Self: @@ -449,18 +454,15 @@ class Embed: Possible attributes you can access are: - - ``url`` for the thumbnail URL. - - ``proxy_url`` for the proxied thumbnail URL. - - ``width`` for the thumbnail width. - - ``height`` for the thumbnail height. - - ``flags`` for the thumbnail's attachment flags. + - ``url`` + - ``proxy_url`` + - ``width`` + - ``height`` If the attribute has no value then ``None`` is returned. """ # Lying to the type checker for better developer UX. - data = getattr(self, '_thumbnail', {}) - data['flags'] = AttachmentFlags._from_value(data.get('flags', 0)) - return EmbedProxy(data) # type: ignore + return EmbedProxy(getattr(self, '_thumbnail', {})) # type: ignore def set_thumbnail(self, *, url: Optional[Any]) -> Self: """Sets the thumbnail for the embed content. @@ -489,23 +491,19 @@ class Embed: return self @property - def video(self) -> _EmbedMediaProxy: + def video(self) -> _EmbedVideoProxy: """Returns an ``EmbedProxy`` denoting the video contents. Possible attributes include: - ``url`` for the video URL. - - ``proxy_url`` for the proxied video URL. - ``height`` for the video height. - ``width`` for the video width. - - ``flags`` for the video's attachment flags. If the attribute has no value then ``None`` is returned. """ # Lying to the type checker for better developer UX. - data = getattr(self, '_video', {}) - data['flags'] = AttachmentFlags._from_value(data.get('flags', 0)) - return EmbedProxy(data) # type: ignore + return EmbedProxy(getattr(self, '_video', {})) # type: ignore @property def provider(self) -> _EmbedProviderProxy: diff --git a/discord/types/embed.py b/discord/types/embed.py index a18912f6e..f8354a3f3 100644 --- a/discord/types/embed.py +++ b/discord/types/embed.py @@ -38,14 +38,28 @@ class EmbedField(TypedDict): inline: NotRequired[bool] -class EmbedMedia(TypedDict, total=False): +class EmbedThumbnail(TypedDict, total=False): url: Required[str] proxy_url: str height: int width: int + + +class EmbedVideo(TypedDict, total=False): + url: str + proxy_url: str + height: int + width: int flags: int +class EmbedImage(TypedDict, total=False): + url: Required[str] + proxy_url: str + height: int + width: int + + class EmbedProvider(TypedDict, total=False): name: str url: str @@ -69,9 +83,9 @@ class Embed(TypedDict, total=False): timestamp: str color: int footer: EmbedFooter - image: EmbedMedia - thumbnail: EmbedMedia - video: EmbedMedia + image: EmbedImage + thumbnail: EmbedThumbnail + video: EmbedVideo provider: EmbedProvider author: EmbedAuthor fields: List[EmbedField]