@@ -46,7 +46,7 @@ def __len__(self) -> int:
46
46
return len (self .__dict__ )
47
47
48
48
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 ('_' )))
50
50
return f'EmbedProxy({ inner } )'
51
51
52
52
def __getattr__ (self , attr : str ) -> None :
@@ -56,6 +56,16 @@ def __eq__(self, other: object) -> bool:
56
56
return isinstance (other , EmbedProxy ) and self .__dict__ == other .__dict__
57
57
58
58
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
+
59
69
if TYPE_CHECKING :
60
70
from typing_extensions import Self
61
71
@@ -77,12 +87,7 @@ class _EmbedMediaProxy(Protocol):
77
87
proxy_url : Optional [str ]
78
88
height : Optional [int ]
79
89
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
86
91
87
92
class _EmbedProviderProxy (Protocol ):
88
93
name : Optional [str ]
@@ -148,10 +153,6 @@ class Embed:
148
153
colour: Optional[Union[:class:`Colour`, :class:`int`]]
149
154
The colour code of the embed. Aliased to ``color`` as well.
150
155
This can be set during initialisation.
151
- flags: Optional[:class:`EmbedFlags`]
152
- The flags of this embed.
153
-
154
- .. versionadded:: 2.5
155
156
"""
156
157
157
158
__slots__ = (
@@ -168,7 +169,7 @@ class Embed:
168
169
'_author' ,
169
170
'_fields' ,
170
171
'description' ,
171
- 'flags ' ,
172
+ '_flags ' ,
172
173
)
173
174
174
175
def __init__ (
@@ -188,7 +189,7 @@ def __init__(
188
189
self .type : EmbedType = type
189
190
self .url : Optional [str ] = url
190
191
self .description : Optional [str ] = description
191
- self .flags : Optional [ EmbedFlags ] = None
192
+ self ._flags : int = 0
192
193
193
194
if self .title is not None :
194
195
self .title = str (self .title )
@@ -223,6 +224,7 @@ def from_dict(cls, data: Mapping[str, Any]) -> Self:
223
224
self .type = data .get ('type' , None )
224
225
self .description = data .get ('description' , None )
225
226
self .url = data .get ('url' , None )
227
+ self ._flags = data .get ('flags' , 0 )
226
228
227
229
if self .title is not None :
228
230
self .title = str (self .title )
@@ -253,11 +255,6 @@ def from_dict(cls, data: Mapping[str, Any]) -> Self:
253
255
else :
254
256
setattr (self , '_' + attr , value )
255
257
256
- try :
257
- self .flags = EmbedFlags ._from_value (data ['flags' ])
258
- except KeyError :
259
- pass
260
-
261
258
return self
262
259
263
260
def copy (self ) -> Self :
@@ -318,8 +315,17 @@ def __eq__(self, other: Embed) -> bool:
318
315
and self .image == other .image
319
316
and self .provider == other .provider
320
317
and self .video == other .video
318
+ and self ._flags == other ._flags
321
319
)
322
320
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
+
323
329
@property
324
330
def colour (self ) -> Optional [Colour ]:
325
331
return getattr (self , '_colour' , None )
@@ -408,19 +414,16 @@ def image(self) -> _EmbedMediaProxy:
408
414
409
415
Possible attributes you can access are:
410
416
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.
416
422
417
423
If the attribute has no value then ``None`` is returned.
418
424
"""
419
425
# 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
424
427
425
428
def set_image (self , * , url : Optional [Any ]) -> Self :
426
429
"""Sets the image for the embed content.
@@ -454,15 +457,16 @@ def thumbnail(self) -> _EmbedMediaProxy:
454
457
455
458
Possible attributes you can access are:
456
459
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.
461
465
462
466
If the attribute has no value then ``None`` is returned.
463
467
"""
464
468
# 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
466
470
467
471
def set_thumbnail (self , * , url : Optional [Any ]) -> Self :
468
472
"""Sets the thumbnail for the embed content.
@@ -491,19 +495,21 @@ def set_thumbnail(self, *, url: Optional[Any]) -> Self:
491
495
return self
492
496
493
497
@property
494
- def video (self ) -> _EmbedVideoProxy :
498
+ def video (self ) -> _EmbedMediaProxy :
495
499
"""Returns an ``EmbedProxy`` denoting the video contents.
496
500
497
501
Possible attributes include:
498
502
499
503
- ``url`` for the video URL.
504
+ - ``proxy_url`` for the proxied video URL.
500
505
- ``height`` for the video height.
501
506
- ``width`` for the video width.
507
+ - ``flags`` for the video's attachment flags.
502
508
503
509
If the attribute has no value then ``None`` is returned.
504
510
"""
505
511
# 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
507
513
508
514
@property
509
515
def provider (self ) -> _EmbedProviderProxy :
0 commit comments