mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-01 07:40:07 +00:00
Make embed flags required and add them to all media fields
This commit is contained in:
parent
de5720e659
commit
cab4732b7e
@ -77,12 +77,7 @@ if TYPE_CHECKING:
|
|||||||
proxy_url: Optional[str]
|
proxy_url: Optional[str]
|
||||||
height: Optional[int]
|
height: Optional[int]
|
||||||
width: Optional[int]
|
width: Optional[int]
|
||||||
flags: Optional[AttachmentFlags]
|
flags: AttachmentFlags
|
||||||
|
|
||||||
class _EmbedVideoProxy(Protocol):
|
|
||||||
url: Optional[str]
|
|
||||||
height: Optional[int]
|
|
||||||
width: Optional[int]
|
|
||||||
|
|
||||||
class _EmbedProviderProxy(Protocol):
|
class _EmbedProviderProxy(Protocol):
|
||||||
name: Optional[str]
|
name: Optional[str]
|
||||||
@ -148,10 +143,6 @@ class Embed:
|
|||||||
colour: Optional[Union[:class:`Colour`, :class:`int`]]
|
colour: Optional[Union[:class:`Colour`, :class:`int`]]
|
||||||
The colour code of the embed. Aliased to ``color`` as well.
|
The colour code of the embed. Aliased to ``color`` as well.
|
||||||
This can be set during initialisation.
|
This can be set during initialisation.
|
||||||
flags: Optional[:class:`EmbedFlags`]
|
|
||||||
The flags of this embed.
|
|
||||||
|
|
||||||
.. versionadded:: 2.5
|
|
||||||
"""
|
"""
|
||||||
|
|
||||||
__slots__ = (
|
__slots__ = (
|
||||||
@ -168,7 +159,7 @@ class Embed:
|
|||||||
'_author',
|
'_author',
|
||||||
'_fields',
|
'_fields',
|
||||||
'description',
|
'description',
|
||||||
'flags',
|
'_flags',
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -188,7 +179,7 @@ class Embed:
|
|||||||
self.type: EmbedType = type
|
self.type: EmbedType = type
|
||||||
self.url: Optional[str] = url
|
self.url: Optional[str] = url
|
||||||
self.description: Optional[str] = description
|
self.description: Optional[str] = description
|
||||||
self.flags: Optional[EmbedFlags] = None
|
self._flags: int = 0
|
||||||
|
|
||||||
if self.title is not None:
|
if self.title is not None:
|
||||||
self.title = str(self.title)
|
self.title = str(self.title)
|
||||||
@ -223,6 +214,7 @@ class Embed:
|
|||||||
self.type = data.get('type', None)
|
self.type = data.get('type', None)
|
||||||
self.description = data.get('description', None)
|
self.description = data.get('description', None)
|
||||||
self.url = data.get('url', None)
|
self.url = data.get('url', None)
|
||||||
|
self._flags = data.get('flags', 0)
|
||||||
|
|
||||||
if self.title is not None:
|
if self.title is not None:
|
||||||
self.title = str(self.title)
|
self.title = str(self.title)
|
||||||
@ -253,11 +245,6 @@ class Embed:
|
|||||||
else:
|
else:
|
||||||
setattr(self, '_' + attr, value)
|
setattr(self, '_' + attr, value)
|
||||||
|
|
||||||
try:
|
|
||||||
self.flags = EmbedFlags._from_value(data['flags'])
|
|
||||||
except KeyError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def copy(self) -> Self:
|
def copy(self) -> Self:
|
||||||
@ -318,8 +305,17 @@ class Embed:
|
|||||||
and self.image == other.image
|
and self.image == other.image
|
||||||
and self.provider == other.provider
|
and self.provider == other.provider
|
||||||
and self.video == other.video
|
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
|
@property
|
||||||
def colour(self) -> Optional[Colour]:
|
def colour(self) -> Optional[Colour]:
|
||||||
return getattr(self, '_colour', None)
|
return getattr(self, '_colour', None)
|
||||||
@ -408,18 +404,17 @@ class Embed:
|
|||||||
|
|
||||||
Possible attributes you can access are:
|
Possible attributes you can access are:
|
||||||
|
|
||||||
- ``url``
|
- ``url`` for the image URL.
|
||||||
- ``proxy_url``
|
- ``proxy_url`` for the proxied image URL.
|
||||||
- ``width``
|
- ``width`` for the image width.
|
||||||
- ``height``
|
- ``height`` for the image height.
|
||||||
- ``flags``
|
- ``flags`` for the image's attachment flags.
|
||||||
|
|
||||||
If the attribute has no value then ``None`` is returned.
|
If the attribute has no value then ``None`` is returned.
|
||||||
"""
|
"""
|
||||||
# Lying to the type checker for better developer UX.
|
# Lying to the type checker for better developer UX.
|
||||||
data = getattr(self, '_image', {})
|
data = getattr(self, '_image', {})
|
||||||
if 'flags' in data:
|
data['flags'] = AttachmentFlags._from_value(data.get('flags', 0))
|
||||||
data['flags'] = AttachmentFlags._from_value(data['flags'])
|
|
||||||
return EmbedProxy(data) # type: ignore
|
return EmbedProxy(data) # type: ignore
|
||||||
|
|
||||||
def set_image(self, *, url: Optional[Any]) -> Self:
|
def set_image(self, *, url: Optional[Any]) -> Self:
|
||||||
@ -454,15 +449,18 @@ class Embed:
|
|||||||
|
|
||||||
Possible attributes you can access are:
|
Possible attributes you can access are:
|
||||||
|
|
||||||
- ``url``
|
- ``url`` for the thumbnail URL.
|
||||||
- ``proxy_url``
|
- ``proxy_url`` for the proxied thumbnail URL.
|
||||||
- ``width``
|
- ``width`` for the thumbnail width.
|
||||||
- ``height``
|
- ``height`` for the thumbnail height.
|
||||||
|
- ``flags`` for the thumbnail's attachment flags.
|
||||||
|
|
||||||
If the attribute has no value then ``None`` is returned.
|
If the attribute has no value then ``None`` is returned.
|
||||||
"""
|
"""
|
||||||
# Lying to the type checker for better developer UX.
|
# Lying to the type checker for better developer UX.
|
||||||
return EmbedProxy(getattr(self, '_thumbnail', {})) # type: ignore
|
data = getattr(self, '_thumbnail', {})
|
||||||
|
data['flags'] = AttachmentFlags._from_value(data.get('flags', 0))
|
||||||
|
return EmbedProxy(data) # type: ignore
|
||||||
|
|
||||||
def set_thumbnail(self, *, url: Optional[Any]) -> Self:
|
def set_thumbnail(self, *, url: Optional[Any]) -> Self:
|
||||||
"""Sets the thumbnail for the embed content.
|
"""Sets the thumbnail for the embed content.
|
||||||
@ -491,19 +489,23 @@ class Embed:
|
|||||||
return self
|
return self
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def video(self) -> _EmbedVideoProxy:
|
def video(self) -> _EmbedMediaProxy:
|
||||||
"""Returns an ``EmbedProxy`` denoting the video contents.
|
"""Returns an ``EmbedProxy`` denoting the video contents.
|
||||||
|
|
||||||
Possible attributes include:
|
Possible attributes include:
|
||||||
|
|
||||||
- ``url`` for the video URL.
|
- ``url`` for the video URL.
|
||||||
|
- ``proxy_url`` for the proxied video URL.
|
||||||
- ``height`` for the video height.
|
- ``height`` for the video height.
|
||||||
- ``width`` for the video width.
|
- ``width`` for the video width.
|
||||||
|
- ``flags`` for the video's attachment flags.
|
||||||
|
|
||||||
If the attribute has no value then ``None`` is returned.
|
If the attribute has no value then ``None`` is returned.
|
||||||
"""
|
"""
|
||||||
# Lying to the type checker for better developer UX.
|
# Lying to the type checker for better developer UX.
|
||||||
return EmbedProxy(getattr(self, '_video', {})) # type: ignore
|
data = getattr(self, '_video', {})
|
||||||
|
data['flags'] = AttachmentFlags._from_value(data.get('flags', 0))
|
||||||
|
return EmbedProxy(data) # type: ignore
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def provider(self) -> _EmbedProviderProxy:
|
def provider(self) -> _EmbedProviderProxy:
|
||||||
|
@ -38,28 +38,14 @@ class EmbedField(TypedDict):
|
|||||||
inline: NotRequired[bool]
|
inline: NotRequired[bool]
|
||||||
|
|
||||||
|
|
||||||
class EmbedThumbnail(TypedDict, total=False):
|
class EmbedMedia(TypedDict, total=False):
|
||||||
url: Required[str]
|
url: Required[str]
|
||||||
proxy_url: str
|
proxy_url: str
|
||||||
height: int
|
height: int
|
||||||
width: int
|
width: int
|
||||||
|
|
||||||
|
|
||||||
class EmbedVideo(TypedDict, total=False):
|
|
||||||
url: str
|
|
||||||
proxy_url: str
|
|
||||||
height: int
|
|
||||||
width: int
|
|
||||||
flags: int
|
flags: int
|
||||||
|
|
||||||
|
|
||||||
class EmbedImage(TypedDict, total=False):
|
|
||||||
url: Required[str]
|
|
||||||
proxy_url: str
|
|
||||||
height: int
|
|
||||||
width: int
|
|
||||||
|
|
||||||
|
|
||||||
class EmbedProvider(TypedDict, total=False):
|
class EmbedProvider(TypedDict, total=False):
|
||||||
name: str
|
name: str
|
||||||
url: str
|
url: str
|
||||||
@ -83,9 +69,9 @@ class Embed(TypedDict, total=False):
|
|||||||
timestamp: str
|
timestamp: str
|
||||||
color: int
|
color: int
|
||||||
footer: EmbedFooter
|
footer: EmbedFooter
|
||||||
image: EmbedImage
|
image: EmbedMedia
|
||||||
thumbnail: EmbedThumbnail
|
thumbnail: EmbedMedia
|
||||||
video: EmbedVideo
|
video: EmbedMedia
|
||||||
provider: EmbedProvider
|
provider: EmbedProvider
|
||||||
author: EmbedAuthor
|
author: EmbedAuthor
|
||||||
fields: List[EmbedField]
|
fields: List[EmbedField]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user