Skip to content

Commit b8ef0df

Browse files
committed
Merge branch 'master' of https://github.com/Rapptz/discord.py into v2-martine
2 parents b80e8b0 + 460d188 commit b8ef0df

File tree

4 files changed

+69
-54
lines changed

4 files changed

+69
-54
lines changed

Diff for: discord/embeds.py

+40-34
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ def __len__(self) -> int:
4646
return len(self.__dict__)
4747

4848
def __repr__(self) -> str:
49-
inner = ', '.join((f'{k}={v!r}' for k, v in self.__dict__.items() if not k.startswith('_')))
49+
inner = ', '.join((f'{k}={getattr(self, k)!r}' for k in dir(self) if not k.startswith('_')))
5050
return f'EmbedProxy({inner})'
5151

5252
def __getattr__(self, attr: str) -> None:
@@ -56,6 +56,16 @@ def __eq__(self, other: object) -> bool:
5656
return isinstance(other, EmbedProxy) and self.__dict__ == other.__dict__
5757

5858

59+
class EmbedMediaProxy(EmbedProxy):
60+
def __init__(self, layer: Dict[str, Any]):
61+
super().__init__(layer)
62+
self._flags = self.__dict__.pop('flags', 0)
63+
64+
@property
65+
def flags(self) -> AttachmentFlags:
66+
return AttachmentFlags._from_value(self._flags or 0)
67+
68+
5969
if TYPE_CHECKING:
6070
from typing_extensions import Self
6171

@@ -77,12 +87,7 @@ class _EmbedMediaProxy(Protocol):
7787
proxy_url: Optional[str]
7888
height: Optional[int]
7989
width: Optional[int]
80-
flags: Optional[AttachmentFlags]
81-
82-
class _EmbedVideoProxy(Protocol):
83-
url: Optional[str]
84-
height: Optional[int]
85-
width: Optional[int]
90+
flags: AttachmentFlags
8691

8792
class _EmbedProviderProxy(Protocol):
8893
name: Optional[str]
@@ -148,10 +153,6 @@ class Embed:
148153
colour: Optional[Union[:class:`Colour`, :class:`int`]]
149154
The colour code of the embed. Aliased to ``color`` as well.
150155
This can be set during initialisation.
151-
flags: Optional[:class:`EmbedFlags`]
152-
The flags of this embed.
153-
154-
.. versionadded:: 2.5
155156
"""
156157

157158
__slots__ = (
@@ -168,7 +169,7 @@ class Embed:
168169
'_author',
169170
'_fields',
170171
'description',
171-
'flags',
172+
'_flags',
172173
)
173174

174175
def __init__(
@@ -188,7 +189,7 @@ def __init__(
188189
self.type: EmbedType = type
189190
self.url: Optional[str] = url
190191
self.description: Optional[str] = description
191-
self.flags: Optional[EmbedFlags] = None
192+
self._flags: int = 0
192193

193194
if self.title is not None:
194195
self.title = str(self.title)
@@ -223,6 +224,7 @@ def from_dict(cls, data: Mapping[str, Any]) -> Self:
223224
self.type = data.get('type', None)
224225
self.description = data.get('description', None)
225226
self.url = data.get('url', None)
227+
self._flags = data.get('flags', 0)
226228

227229
if self.title is not None:
228230
self.title = str(self.title)
@@ -253,11 +255,6 @@ def from_dict(cls, data: Mapping[str, Any]) -> Self:
253255
else:
254256
setattr(self, '_' + attr, value)
255257

256-
try:
257-
self.flags = EmbedFlags._from_value(data['flags'])
258-
except KeyError:
259-
pass
260-
261258
return self
262259

263260
def copy(self) -> Self:
@@ -318,8 +315,17 @@ def __eq__(self, other: Embed) -> bool:
318315
and self.image == other.image
319316
and self.provider == other.provider
320317
and self.video == other.video
318+
and self._flags == other._flags
321319
)
322320

321+
@property
322+
def flags(self) -> EmbedFlags:
323+
""":class:`EmbedFlags`: The flags of this embed.
324+
325+
.. versionadded:: 2.5
326+
"""
327+
return EmbedFlags._from_value(self._flags or 0)
328+
323329
@property
324330
def colour(self) -> Optional[Colour]:
325331
return getattr(self, '_colour', None)
@@ -408,19 +414,16 @@ def image(self) -> _EmbedMediaProxy:
408414
409415
Possible attributes you can access are:
410416
411-
- ``url``
412-
- ``proxy_url``
413-
- ``width``
414-
- ``height``
415-
- ``flags``
417+
- ``url`` for the image URL.
418+
- ``proxy_url`` for the proxied image URL.
419+
- ``width`` for the image width.
420+
- ``height`` for the image height.
421+
- ``flags`` for the image's attachment flags.
416422
417423
If the attribute has no value then ``None`` is returned.
418424
"""
419425
# Lying to the type checker for better developer UX.
420-
data = getattr(self, '_image', {})
421-
if 'flags' in data:
422-
data['flags'] = AttachmentFlags._from_value(data['flags'])
423-
return EmbedProxy(data) # type: ignore
426+
return EmbedMediaProxy(getattr(self, '_image', {})) # type: ignore
424427

425428
def set_image(self, *, url: Optional[Any]) -> Self:
426429
"""Sets the image for the embed content.
@@ -454,15 +457,16 @@ def thumbnail(self) -> _EmbedMediaProxy:
454457
455458
Possible attributes you can access are:
456459
457-
- ``url``
458-
- ``proxy_url``
459-
- ``width``
460-
- ``height``
460+
- ``url`` for the thumbnail URL.
461+
- ``proxy_url`` for the proxied thumbnail URL.
462+
- ``width`` for the thumbnail width.
463+
- ``height`` for the thumbnail height.
464+
- ``flags`` for the thumbnail's attachment flags.
461465
462466
If the attribute has no value then ``None`` is returned.
463467
"""
464468
# Lying to the type checker for better developer UX.
465-
return EmbedProxy(getattr(self, '_thumbnail', {})) # type: ignore
469+
return EmbedMediaProxy(getattr(self, '_thumbnail', {})) # type: ignore
466470

467471
def set_thumbnail(self, *, url: Optional[Any]) -> Self:
468472
"""Sets the thumbnail for the embed content.
@@ -491,19 +495,21 @@ def set_thumbnail(self, *, url: Optional[Any]) -> Self:
491495
return self
492496

493497
@property
494-
def video(self) -> _EmbedVideoProxy:
498+
def video(self) -> _EmbedMediaProxy:
495499
"""Returns an ``EmbedProxy`` denoting the video contents.
496500
497501
Possible attributes include:
498502
499503
- ``url`` for the video URL.
504+
- ``proxy_url`` for the proxied video URL.
500505
- ``height`` for the video height.
501506
- ``width`` for the video width.
507+
- ``flags`` for the video's attachment flags.
502508
503509
If the attribute has no value then ``None`` is returned.
504510
"""
505511
# Lying to the type checker for better developer UX.
506-
return EmbedProxy(getattr(self, '_video', {})) # type: ignore
512+
return EmbedMediaProxy(getattr(self, '_video', {})) # type: ignore
507513

508514
@property
509515
def provider(self) -> _EmbedProviderProxy:

Diff for: discord/types/embed.py

+4-18
Original file line numberDiff line numberDiff line change
@@ -38,28 +38,14 @@ class EmbedField(TypedDict):
3838
inline: NotRequired[bool]
3939

4040

41-
class EmbedThumbnail(TypedDict, total=False):
41+
class EmbedMedia(TypedDict, total=False):
4242
url: Required[str]
4343
proxy_url: str
4444
height: int
4545
width: int
46-
47-
48-
class EmbedVideo(TypedDict, total=False):
49-
url: str
50-
proxy_url: str
51-
height: int
52-
width: int
5346
flags: int
5447

5548

56-
class EmbedImage(TypedDict, total=False):
57-
url: Required[str]
58-
proxy_url: str
59-
height: int
60-
width: int
61-
62-
6349
class EmbedProvider(TypedDict, total=False):
6450
name: str
6551
url: str
@@ -83,9 +69,9 @@ class Embed(TypedDict, total=False):
8369
timestamp: str
8470
color: int
8571
footer: EmbedFooter
86-
image: EmbedImage
87-
thumbnail: EmbedThumbnail
88-
video: EmbedVideo
72+
image: EmbedMedia
73+
thumbnail: EmbedMedia
74+
video: EmbedMedia
8975
provider: EmbedProvider
9076
author: EmbedAuthor
9177
fields: List[EmbedField]

Diff for: docs/api.rst

+1-1
Original file line numberDiff line numberDiff line change
@@ -2418,7 +2418,7 @@ of :class:`enum.Enum`.
24182418
When this is the action, the type of :attr:`~AuditLogEntry.extra` is
24192419
set to an unspecified proxy object with two attributes:
24202420

2421-
- ``channel``: A :class:`TextChannel` or :class:`Object` with the channel ID where the members were moved.
2421+
- ``channel``: An :class:`abc.Connectable` or :class:`Object` with the channel ID where the members were moved.
24222422
- ``count``: An integer specifying how many members were moved.
24232423

24242424
.. versionadded:: 1.3

Diff for: docs/whats_new.rst

+24-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,30 @@ Changelog
1111
This page keeps a detailed human friendly rendering of what's new and changed
1212
in specific versions.
1313

14+
.. _vp2p5p2:
15+
16+
v2.5.2
17+
-------
18+
19+
Bug Fixes
20+
~~~~~~~~~~
21+
22+
- Fix a serialization issue when sending embeds (:issue:`10126`)
23+
24+
.. _vp2p5p1:
25+
26+
v2.5.1
27+
-------
28+
29+
Bug Fixes
30+
~~~~~~~~~~
31+
32+
- Fix :attr:`InteractionCallbackResponse.resource` having incorrect state (:issue:`10107`)
33+
- Create :class:`ScheduledEvent` on cache miss for :func:`on_scheduled_event_delete` (:issue:`10113`)
34+
- Add defaults for :class:`Message` creation preventing some crashes (:issue:`10115`)
35+
- Fix :meth:`Attachment.is_spoiler` and :meth:`Attachment.is_voice_message` being incorrect (:issue:`10122`)
36+
37+
1438
.. _vp2p5p0:
1539

1640
v2.5.0
@@ -63,7 +87,6 @@ New Features
6387

6488
- Add :attr:`PartialWebhookChannel.mention` attribute (:issue:`10101`)
6589
- Add support for sending stateless views for :class:`SyncWebhook` or webhooks with no state (:issue:`10089`)
66-
- Add
6790
- Add richer :meth:`Role.move` interface (:issue:`10100`)
6891
- Add support for :class:`EmbedFlags` via :attr:`Embed.flags` (:issue:`10085`)
6992
- Add new flags for :class:`AttachmentFlags` (:issue:`10085`)

0 commit comments

Comments
 (0)