mirror of
https://github.com/Rapptz/discord.py.git
synced 2025-07-11 04:17:58 +00:00
Add support for embed flags and update attachment flags
Co-authored-by: Danny <1695103+Rapptz@users.noreply.github.com>
This commit is contained in:
parent
76eb126664
commit
8a95c0190c
@ -29,6 +29,7 @@ from typing import Any, Dict, List, Mapping, Optional, Protocol, TYPE_CHECKING,
|
|||||||
|
|
||||||
from . import utils
|
from . import utils
|
||||||
from .colour import Colour
|
from .colour import Colour
|
||||||
|
from .flags import AttachmentFlags, EmbedFlags
|
||||||
|
|
||||||
# fmt: off
|
# fmt: off
|
||||||
__all__ = (
|
__all__ = (
|
||||||
@ -76,6 +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]
|
||||||
|
|
||||||
class _EmbedVideoProxy(Protocol):
|
class _EmbedVideoProxy(Protocol):
|
||||||
url: Optional[str]
|
url: Optional[str]
|
||||||
@ -146,6 +148,10 @@ 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__ = (
|
||||||
@ -162,6 +168,7 @@ class Embed:
|
|||||||
'_author',
|
'_author',
|
||||||
'_fields',
|
'_fields',
|
||||||
'description',
|
'description',
|
||||||
|
'flags',
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -181,6 +188,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
|
||||||
|
|
||||||
if self.title is not None:
|
if self.title is not None:
|
||||||
self.title = str(self.title)
|
self.title = str(self.title)
|
||||||
@ -245,6 +253,11 @@ 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:
|
||||||
@ -399,11 +412,15 @@ class Embed:
|
|||||||
- ``proxy_url``
|
- ``proxy_url``
|
||||||
- ``width``
|
- ``width``
|
||||||
- ``height``
|
- ``height``
|
||||||
|
- ``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, '_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:
|
def set_image(self, *, url: Optional[Any]) -> Self:
|
||||||
"""Sets the image for the embed content.
|
"""Sets the image for the embed content.
|
||||||
|
@ -63,6 +63,7 @@ __all__ = (
|
|||||||
'RoleFlags',
|
'RoleFlags',
|
||||||
'AppInstallationType',
|
'AppInstallationType',
|
||||||
'SKUFlags',
|
'SKUFlags',
|
||||||
|
'EmbedFlags',
|
||||||
)
|
)
|
||||||
|
|
||||||
BF = TypeVar('BF', bound='BaseFlags')
|
BF = TypeVar('BF', bound='BaseFlags')
|
||||||
@ -2173,6 +2174,30 @@ class AttachmentFlags(BaseFlags):
|
|||||||
""":class:`bool`: Returns ``True`` if the attachment has been edited using the remix feature."""
|
""":class:`bool`: Returns ``True`` if the attachment has been edited using the remix feature."""
|
||||||
return 1 << 2
|
return 1 << 2
|
||||||
|
|
||||||
|
@flag_value
|
||||||
|
def spoiler(self):
|
||||||
|
""":class:`bool`: Returns ``True`` if the attachment was marked as a spoiler.
|
||||||
|
|
||||||
|
.. versionadded:: 2.5
|
||||||
|
"""
|
||||||
|
return 1 << 3
|
||||||
|
|
||||||
|
@flag_value
|
||||||
|
def contains_explicit_media(self):
|
||||||
|
""":class:`bool`: Returns ``True`` if the attachment was flagged as sensitive content.
|
||||||
|
|
||||||
|
.. versionadded:: 2.5
|
||||||
|
"""
|
||||||
|
return 1 << 4
|
||||||
|
|
||||||
|
@flag_value
|
||||||
|
def animated(self):
|
||||||
|
""":class:`bool`: Returns ``True`` if the attachment is an animated image.
|
||||||
|
|
||||||
|
.. versionadded:: 2.5
|
||||||
|
"""
|
||||||
|
return 1 << 5
|
||||||
|
|
||||||
|
|
||||||
@fill_with_flags()
|
@fill_with_flags()
|
||||||
class RoleFlags(BaseFlags):
|
class RoleFlags(BaseFlags):
|
||||||
@ -2308,3 +2333,67 @@ class SKUFlags(BaseFlags):
|
|||||||
def user_subscription(self):
|
def user_subscription(self):
|
||||||
""":class:`bool`: Returns ``True`` if the SKU is a user subscription."""
|
""":class:`bool`: Returns ``True`` if the SKU is a user subscription."""
|
||||||
return 1 << 8
|
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
|
||||||
|
@ -50,6 +50,7 @@ class EmbedVideo(TypedDict, total=False):
|
|||||||
proxy_url: str
|
proxy_url: str
|
||||||
height: int
|
height: int
|
||||||
width: int
|
width: int
|
||||||
|
flags: int
|
||||||
|
|
||||||
|
|
||||||
class EmbedImage(TypedDict, total=False):
|
class EmbedImage(TypedDict, total=False):
|
||||||
@ -88,3 +89,4 @@ class Embed(TypedDict, total=False):
|
|||||||
provider: EmbedProvider
|
provider: EmbedProvider
|
||||||
author: EmbedAuthor
|
author: EmbedAuthor
|
||||||
fields: List[EmbedField]
|
fields: List[EmbedField]
|
||||||
|
flags: int
|
||||||
|
@ -5708,6 +5708,14 @@ SKUFlags
|
|||||||
.. autoclass:: SKUFlags()
|
.. autoclass:: SKUFlags()
|
||||||
:members:
|
:members:
|
||||||
|
|
||||||
|
EmbedFlags
|
||||||
|
~~~~~~~~~~
|
||||||
|
|
||||||
|
.. attributetable:: EmbedFlags
|
||||||
|
|
||||||
|
.. autoclass:: EmbedFlags()
|
||||||
|
:members:
|
||||||
|
|
||||||
ForumTag
|
ForumTag
|
||||||
~~~~~~~~~
|
~~~~~~~~~
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user