Browse Source

Add support for attachment flags

pull/10109/head
Soheab_ 2 years ago
committed by dolfies
parent
commit
908a1a1bdb
  1. 65
      discord/flags.py
  2. 10
      discord/message.py
  3. 1
      discord/types/message.py
  4. 23
      docs/api.rst

65
discord/flags.py

@ -74,6 +74,7 @@ __all__ = (
'MemberFlags', 'MemberFlags',
'ReadStateFlags', 'ReadStateFlags',
'InviteFlags', 'InviteFlags',
'AttachmentFlags',
) )
BF = TypeVar('BF', bound='BaseFlags') BF = TypeVar('BF', bound='BaseFlags')
@ -2618,3 +2619,67 @@ class InviteFlags(BaseFlags):
def guest(self): def guest(self):
""":class:`bool`: Returns ``True`` if the invite is a guest invite. Guest invites grant temporary membership for the purposes of joining a voice channel.""" """:class:`bool`: Returns ``True`` if the invite is a guest invite. Guest invites grant temporary membership for the purposes of joining a voice channel."""
return 1 << 0 return 1 << 0
@fill_with_flags()
class AttachmentFlags(BaseFlags):
r"""Wraps up the Discord Attachment flags
.. container:: operations
.. describe:: x == y
Checks if two AttachmentFlags are equal.
.. describe:: x != y
Checks if two AttachmentFlags are not equal.
.. describe:: x | y, x |= y
Returns a AttachmentFlags instance with all enabled flags from
both x and y.
.. describe:: x & y, x &= y
Returns a AttachmentFlags instance with only flags enabled on
both x and y.
.. describe:: x ^ y, x ^= y
Returns a AttachmentFlags instance with only flags enabled on
only one of x or y, not on both.
.. describe:: ~x
Returns a AttachmentFlags instance with all flags inverted from x.
.. describe:: hash(x)
Return 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``.
.. versionadded:: 2.1
Attributes
-----------
value: :class:`int`
The raw value. You should query flags via the properties
rather than using this raw value.
"""
@flag_value
def clip(self):
""":class:`bool`: Returns ``True`` if the attachment is a clip."""
return 1 << 0
@flag_value
def thumbnail(self):
""":class:`bool`: Returns ``True`` if the attachment is a media channel thumbnail."""
return 1 << 1
@flag_value
def remix(self):
""":class:`bool`: Returns ``True`` if the attachment has been edited using the remix feature."""
return 1 << 2

10
discord/message.py

@ -56,7 +56,7 @@ from .errors import HTTPException
from .components import _component_factory from .components import _component_factory
from .embeds import Embed from .embeds import Embed
from .member import Member from .member import Member
from .flags import MessageFlags from .flags import MessageFlags, AttachmentFlags
from .file import File from .file import File
from .utils import escape_mentions, MISSING from .utils import escape_mentions, MISSING
from .http import handle_message_parameters from .http import handle_message_parameters
@ -215,6 +215,7 @@ class Attachment(Hashable):
'ephemeral', 'ephemeral',
'duration', 'duration',
'waveform', 'waveform',
'_flags',
) )
def __init__(self, *, data: AttachmentPayload, state: ConnectionState): def __init__(self, *, data: AttachmentPayload, state: ConnectionState):
@ -234,6 +235,13 @@ class Attachment(Hashable):
waveform = data.get('waveform') waveform = data.get('waveform')
self.waveform: Optional[bytes] = utils._base64_to_bytes(waveform) if waveform is not None else None self.waveform: Optional[bytes] = utils._base64_to_bytes(waveform) if waveform is not None else None
self._flags: int = data.get('flags', 0)
@property
def flags(self) -> AttachmentFlags:
""":class:`AttachmentFlags`: The attachment's flags."""
return AttachmentFlags._from_value(self._flags)
def is_spoiler(self) -> bool: def is_spoiler(self) -> bool:
""":class:`bool`: Whether this attachment contains a spoiler.""" """:class:`bool`: Whether this attachment contains a spoiler."""
return self.filename.startswith('SPOILER_') return self.filename.startswith('SPOILER_')

1
discord/types/message.py

@ -72,6 +72,7 @@ class Attachment(TypedDict):
ephemeral: NotRequired[bool] ephemeral: NotRequired[bool]
duration_secs: NotRequired[float] duration_secs: NotRequired[float]
waveform: NotRequired[str] waveform: NotRequired[str]
flags: NotRequired[int]
MessageActivityType = Literal[1, 2, 3, 5] MessageActivityType = Literal[1, 2, 3, 5]

23
docs/api.rst

@ -7849,9 +7849,9 @@ Flags
.. autoclass:: ApplicationDiscoveryFlags() .. autoclass:: ApplicationDiscoveryFlags()
:members: :members:
.. attributetable:: LibraryApplicationFlags .. attributetable:: AttachmentFlags
.. autoclass:: LibraryApplicationFlags() .. autoclass:: AttachmentFlags()
:members: :members:
.. attributetable:: ChannelFlags .. attributetable:: ChannelFlags
@ -7859,11 +7859,6 @@ Flags
.. autoclass:: ChannelFlags() .. autoclass:: ChannelFlags()
:members: :members:
.. attributetable:: SystemChannelFlags
.. autoclass:: SystemChannelFlags()
:members:
.. attributetable:: FriendSourceFlags .. attributetable:: FriendSourceFlags
.. autoclass:: FriendSourceFlags() .. autoclass:: FriendSourceFlags()
@ -7889,11 +7884,21 @@ Flags
.. autoclass:: InviteFlags() .. autoclass:: InviteFlags()
:members: :members:
.. attributetable:: LibraryApplicationFlags
.. autoclass:: LibraryApplicationFlags()
:members:
.. attributetable:: MemberFlags .. attributetable:: MemberFlags
.. autoclass:: MemberFlags() .. autoclass:: MemberFlags()
:members: :members:
.. attributetable:: MemberCacheFlags
.. autoclass:: MemberCacheFlags()
:members:
.. attributetable:: MessageFlags .. attributetable:: MessageFlags
.. autoclass:: MessageFlags() .. autoclass:: MessageFlags()
@ -7950,9 +7955,9 @@ Flags
.. autoclass:: SKUFlags() .. autoclass:: SKUFlags()
:members: :members:
.. attributetable:: MemberCacheFlags .. attributetable:: SystemChannelFlags
.. autoclass:: MemberCacheFlags() .. autoclass:: SystemChannelFlags()
:members: :members:

Loading…
Cancel
Save