Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion discord/embeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@

from . import utils
from .colour import Colour
from .flags import AttachmentFlags, EmbedFlags

# fmt: off
__all__ = (
Expand Down Expand Up @@ -76,6 +77,7 @@ class _EmbedMediaProxy(Protocol):
proxy_url: Optional[str]
height: Optional[int]
width: Optional[int]
flags: Optional[AttachmentFlags]

class _EmbedVideoProxy(Protocol):
url: Optional[str]
Expand Down Expand Up @@ -146,6 +148,10 @@ class Embed:
colour: Optional[Union[:class:`Colour`, :class:`int`]]
The colour code of the embed. Aliased to ``color`` as well.
This can be set during initialisation.
flags: Optional[:class:`EmbedFlags`]
This embed flags.

.. versionadded:: 2.5
"""

__slots__ = (
Expand All @@ -162,6 +168,7 @@ class Embed:
'_author',
'_fields',
'description',
'flags',
)

def __init__(
Expand All @@ -181,6 +188,7 @@ def __init__(
self.type: EmbedType = type
self.url: Optional[str] = url
self.description: Optional[str] = description
self.flags: Optional[EmbedFlags] = None

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

try:
self.flags = EmbedFlags._from_value(data['flags'])
except KeyError:
pass

return self

def copy(self) -> Self:
Expand Down Expand Up @@ -399,11 +412,15 @@ def image(self) -> _EmbedMediaProxy:
- ``proxy_url``
- ``width``
- ``height``
- ``flags``

If the attribute has no value then ``None`` is returned.
"""
# Lying to the type checker for better developer UX.
return EmbedProxy(getattr(self, '_image', {})) # type: ignore
data = getattr(self, '_image', {})
if 'flags' in data:
data['flags'] = AttachmentFlags._from_value(data['flags'])
return EmbedProxy(data) # type: ignore

def set_image(self, *, url: Optional[Any]) -> Self:
"""Sets the image for the embed content.
Expand Down
80 changes: 80 additions & 0 deletions discord/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
'RoleFlags',
'AppInstallationType',
'SKUFlags',
'EmbedFlags',
)

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

@flag_value
def spoiler(self):
""":class:`bool`: Returns ``True`` if the attachment was marked as a spoiler."""
return 1 << 3

@flag_value
def contains_explicit_media(self):
""":class:`bool`: Returns ``True`` if the attachment was flagged as sensitive content."""
return 1 << 4

@flag_value
def animated(self):
""":class:`bool`: Returns ``True`` if the attachment is an animated image."""
return 1 << 5


@fill_with_flags()
class RoleFlags(BaseFlags):
Expand Down Expand Up @@ -2308,3 +2324,67 @@ def guild_subscription(self):
def user_subscription(self):
""":class:`bool`: Returns ``True`` if the SKU is a user subscription."""
return 1 << 8


@fill_with_flags()
class EmbedFlags(BaseFlags):
r"""Wraps up the Discord Embed flags

.. versionadded:: 2.5

.. container:: operations

.. describe:: x == y

Checks if two EmbedFlags are equal.

.. describe:: x != y

Checks if two EmbedFlags are not equal.

.. describe:: x | y, x |= y

Returns an EmbedFlags instance with all enabled flags from
both x and y.

.. describe:: x ^ y, x ^= y

Returns an EmbedFlags instance with only flags enabled on
only one of x or y, not on both.

.. describe:: ~x

Returns an EmbedFlags instance with all flags inverted from x.

.. describe:: hash(x)

Returns the flag's hash.

.. describe:: iter(x)

Returns an iterator of ``(name, value)`` pairs. This allows it
to be, for example, constructed as a dict or a list of pairs.
Note that aliases are not shown.

.. describe:: bool(b)

Returns whether any flag is set to ``True``.

Attributes
----------
value: :class:`int`
The raw value. You should query flags via the properties
rather than using this raw value.
"""

@flag_value
def contains_explicit_media(self):
""":class:`bool`: Returns ``True`` if the embed was flagged as sensitive content."""
return 1 << 4

@flag_value
def content_inventory_entry(self):
""":class:`bool`: Returns ``True`` if the embed is a reply to an activity card, and is no
longer displayed.
"""
return 1 << 5
2 changes: 2 additions & 0 deletions discord/types/embed.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class EmbedVideo(TypedDict, total=False):
proxy_url: str
height: int
width: int
flags: int


class EmbedImage(TypedDict, total=False):
Expand Down Expand Up @@ -88,3 +89,4 @@ class Embed(TypedDict, total=False):
provider: EmbedProvider
author: EmbedAuthor
fields: List[EmbedField]
flags: int
8 changes: 8 additions & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5708,6 +5708,14 @@ SKUFlags
.. autoclass:: SKUFlags()
:members:

EmbedFlags
~~~~~~~~~~

.. attributetable:: EmbedFlags

.. autoclass:: EmbedFlags()
:members:

ForumTag
~~~~~~~~~

Expand Down
Loading