Skip to content

Commit

Permalink
Fix nested embed flag hell
Browse files Browse the repository at this point in the history
  • Loading branch information
dolfies committed Mar 4, 2025
1 parent 973bb50 commit 8b5184a
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions discord/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,16 @@ def __eq__(self, other: object) -> bool:
return isinstance(other, EmbedProxy) and self.__dict__ == other.__dict__


class EmbedMediaProxy(EmbedProxy):
def __getattribute__(self, name: str) -> Any:
if name == 'flags':
try:
return AttachmentFlags._from_value(super().__getattribute__(name))
except AttributeError:
return AttachmentFlags._from_value(0)
return super().__getattribute__(name)


if TYPE_CHECKING:
from typing_extensions import Self

Check warning on line 70 in discord/embeds.py

View workflow job for this annotation

GitHub Actions / check 3.x

Import "typing_extensions" could not be resolved from source (reportMissingModuleSource)

Expand Down Expand Up @@ -413,9 +423,7 @@ def image(self) -> _EmbedMediaProxy:
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))
return EmbedProxy(data) # type: ignore
return EmbedMediaProxy(getattr(self, '_image', {})) # type: ignore

def set_image(self, *, url: Optional[Any]) -> Self:
"""Sets the image for the embed content.
Expand Down Expand Up @@ -458,9 +466,7 @@ def thumbnail(self) -> _EmbedMediaProxy:
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 EmbedMediaProxy(getattr(self, '_thumbnail', {})) # type: ignore

def set_thumbnail(self, *, url: Optional[Any]) -> Self:
"""Sets the thumbnail for the embed content.
Expand Down Expand Up @@ -503,9 +509,7 @@ def video(self) -> _EmbedMediaProxy:
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 EmbedMediaProxy(getattr(self, '_video', {})) # type: ignore

@property
def provider(self) -> _EmbedProviderProxy:
Expand Down

0 comments on commit 8b5184a

Please sign in to comment.