Skip to content

Commit 8a95c01

Browse files
DA-344Rapptz
andauthored
Add support for embed flags and update attachment flags
Co-authored-by: Danny <1695103+Rapptz@users.noreply.github.com>
1 parent 76eb126 commit 8a95c01

File tree

4 files changed

+117
-1
lines changed

4 files changed

+117
-1
lines changed

discord/embeds.py

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929

3030
from . import utils
3131
from .colour import Colour
32+
from .flags import AttachmentFlags, EmbedFlags
3233

3334
# fmt: off
3435
__all__ = (
@@ -76,6 +77,7 @@ class _EmbedMediaProxy(Protocol):
7677
proxy_url: Optional[str]
7778
height: Optional[int]
7879
width: Optional[int]
80+
flags: Optional[AttachmentFlags]
7981

8082
class _EmbedVideoProxy(Protocol):
8183
url: Optional[str]
@@ -146,6 +148,10 @@ class Embed:
146148
colour: Optional[Union[:class:`Colour`, :class:`int`]]
147149
The colour code of the embed. Aliased to ``color`` as well.
148150
This can be set during initialisation.
151+
flags: Optional[:class:`EmbedFlags`]
152+
The flags of this embed.
153+
154+
.. versionadded:: 2.5
149155
"""
150156

151157
__slots__ = (
@@ -162,6 +168,7 @@ class Embed:
162168
'_author',
163169
'_fields',
164170
'description',
171+
'flags',
165172
)
166173

167174
def __init__(
@@ -181,6 +188,7 @@ def __init__(
181188
self.type: EmbedType = type
182189
self.url: Optional[str] = url
183190
self.description: Optional[str] = description
191+
self.flags: Optional[EmbedFlags] = None
184192

185193
if self.title is not None:
186194
self.title = str(self.title)
@@ -245,6 +253,11 @@ def from_dict(cls, data: Mapping[str, Any]) -> Self:
245253
else:
246254
setattr(self, '_' + attr, value)
247255

256+
try:
257+
self.flags = EmbedFlags._from_value(data['flags'])
258+
except KeyError:
259+
pass
260+
248261
return self
249262

250263
def copy(self) -> Self:
@@ -399,11 +412,15 @@ def image(self) -> _EmbedMediaProxy:
399412
- ``proxy_url``
400413
- ``width``
401414
- ``height``
415+
- ``flags``
402416
403417
If the attribute has no value then ``None`` is returned.
404418
"""
405419
# Lying to the type checker for better developer UX.
406-
return EmbedProxy(getattr(self, '_image', {})) # type: ignore
420+
data = getattr(self, '_image', {})
421+
if 'flags' in data:
422+
data['flags'] = AttachmentFlags._from_value(data['flags'])
423+
return EmbedProxy(data) # type: ignore
407424

408425
def set_image(self, *, url: Optional[Any]) -> Self:
409426
"""Sets the image for the embed content.

discord/flags.py

Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@
6363
'RoleFlags',
6464
'AppInstallationType',
6565
'SKUFlags',
66+
'EmbedFlags',
6667
)
6768

6869
BF = TypeVar('BF', bound='BaseFlags')
@@ -2173,6 +2174,30 @@ def remix(self):
21732174
""":class:`bool`: Returns ``True`` if the attachment has been edited using the remix feature."""
21742175
return 1 << 2
21752176

2177+
@flag_value
2178+
def spoiler(self):
2179+
""":class:`bool`: Returns ``True`` if the attachment was marked as a spoiler.
2180+
2181+
.. versionadded:: 2.5
2182+
"""
2183+
return 1 << 3
2184+
2185+
@flag_value
2186+
def contains_explicit_media(self):
2187+
""":class:`bool`: Returns ``True`` if the attachment was flagged as sensitive content.
2188+
2189+
.. versionadded:: 2.5
2190+
"""
2191+
return 1 << 4
2192+
2193+
@flag_value
2194+
def animated(self):
2195+
""":class:`bool`: Returns ``True`` if the attachment is an animated image.
2196+
2197+
.. versionadded:: 2.5
2198+
"""
2199+
return 1 << 5
2200+
21762201

21772202
@fill_with_flags()
21782203
class RoleFlags(BaseFlags):
@@ -2308,3 +2333,67 @@ def guild_subscription(self):
23082333
def user_subscription(self):
23092334
""":class:`bool`: Returns ``True`` if the SKU is a user subscription."""
23102335
return 1 << 8
2336+
2337+
2338+
@fill_with_flags()
2339+
class EmbedFlags(BaseFlags):
2340+
r"""Wraps up the Discord Embed flags
2341+
2342+
.. versionadded:: 2.5
2343+
2344+
.. container:: operations
2345+
2346+
.. describe:: x == y
2347+
2348+
Checks if two EmbedFlags are equal.
2349+
2350+
.. describe:: x != y
2351+
2352+
Checks if two EmbedFlags are not equal.
2353+
2354+
.. describe:: x | y, x |= y
2355+
2356+
Returns an EmbedFlags instance with all enabled flags from
2357+
both x and y.
2358+
2359+
.. describe:: x ^ y, x ^= y
2360+
2361+
Returns an EmbedFlags instance with only flags enabled on
2362+
only one of x or y, not on both.
2363+
2364+
.. describe:: ~x
2365+
2366+
Returns an EmbedFlags instance with all flags inverted from x.
2367+
2368+
.. describe:: hash(x)
2369+
2370+
Returns the flag's hash.
2371+
2372+
.. describe:: iter(x)
2373+
2374+
Returns an iterator of ``(name, value)`` pairs. This allows it
2375+
to be, for example, constructed as a dict or a list of pairs.
2376+
Note that aliases are not shown.
2377+
2378+
.. describe:: bool(b)
2379+
2380+
Returns whether any flag is set to ``True``.
2381+
2382+
Attributes
2383+
----------
2384+
value: :class:`int`
2385+
The raw value. You should query flags via the properties
2386+
rather than using this raw value.
2387+
"""
2388+
2389+
@flag_value
2390+
def contains_explicit_media(self):
2391+
""":class:`bool`: Returns ``True`` if the embed was flagged as sensitive content."""
2392+
return 1 << 4
2393+
2394+
@flag_value
2395+
def content_inventory_entry(self):
2396+
""":class:`bool`: Returns ``True`` if the embed is a reply to an activity card, and is no
2397+
longer displayed.
2398+
"""
2399+
return 1 << 5

discord/types/embed.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ class EmbedVideo(TypedDict, total=False):
5050
proxy_url: str
5151
height: int
5252
width: int
53+
flags: int
5354

5455

5556
class EmbedImage(TypedDict, total=False):
@@ -88,3 +89,4 @@ class Embed(TypedDict, total=False):
8889
provider: EmbedProvider
8990
author: EmbedAuthor
9091
fields: List[EmbedField]
92+
flags: int

docs/api.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5708,6 +5708,14 @@ SKUFlags
57085708
.. autoclass:: SKUFlags()
57095709
:members:
57105710

5711+
EmbedFlags
5712+
~~~~~~~~~~
5713+
5714+
.. attributetable:: EmbedFlags
5715+
5716+
.. autoclass:: EmbedFlags()
5717+
:members:
5718+
57115719
ForumTag
57125720
~~~~~~~~~
57135721

0 commit comments

Comments
 (0)