Browse Source

Add support for role flags

pull/9505/head
Soheab_ 2 years ago
committed by GitHub
parent
commit
135e57c81f
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
  1. 64
      discord/flags.py
  2. 11
      discord/role.py
  3. 1
      discord/types/role.py
  4. 8
      docs/api.rst

64
discord/flags.py

@ -59,6 +59,7 @@ __all__ = (
'AutoModPresets',
'MemberFlags',
'AttachmentFlags',
'RoleFlags',
)
BF = TypeVar('BF', bound='BaseFlags')
@ -1898,3 +1899,66 @@ class AttachmentFlags(BaseFlags):
def remix(self):
""":class:`bool`: Returns ``True`` if the attachment has been edited using the remix feature."""
return 1 << 2
@fill_with_flags()
class RoleFlags(BaseFlags):
r"""Wraps up the Discord Role flags
.. versionadded:: 2.4
.. container:: operations
.. describe:: x == y
Checks if two RoleFlags are equal.
.. describe:: x != y
Checks if two RoleFlags are not equal.
.. describe:: x | y, x |= y
Returns a RoleFlags instance with all enabled flags from
both x and y.
.. describe:: x & y, x &= y
Returns a RoleFlags instance with only flags enabled on
both x and y.
.. describe:: x ^ y, x ^= y
Returns a RoleFlags instance with only flags enabled on
only one of x or y, not on both.
.. describe:: ~x
Returns a RoleFlags 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``.
Attributes
-----------
value: :class:`int`
The raw value. You should query flags via the properties
rather than using this raw value.
"""
@flag_value
def in_prompt(self):
""":class:`bool`: Returns ``True`` if the role can be selected by members in an onboarding prompt."""
return 1 << 0

11
discord/role.py

@ -30,6 +30,7 @@ from .permissions import Permissions
from .colour import Colour
from .mixins import Hashable
from .utils import snowflake_time, _bytes_to_base64_data, _get_as_snowflake, MISSING
from .flags import RoleFlags
__all__ = (
'RoleTags',
@ -219,6 +220,7 @@ class Role(Hashable):
'hoist',
'guild',
'tags',
'_flags',
'_state',
)
@ -281,6 +283,7 @@ class Role(Hashable):
self.managed: bool = data.get('managed', False)
self.mentionable: bool = data.get('mentionable', False)
self.tags: Optional[RoleTags]
self._flags: int = data.get('flags', 0)
try:
self.tags = RoleTags(data['tags'])
@ -379,6 +382,14 @@ class Role(Hashable):
role_id = self.id
return [member for member in all_members if member._roles.has(role_id)]
@property
def flags(self) -> RoleFlags:
""":class:`RoleFlags`: Returns the role's flags.
.. versionadded:: 2.4
"""
return RoleFlags._from_value(self._flags)
async def _move(self, position: int, reason: Optional[str]) -> None:
if position <= 0:
raise ValueError("Cannot move role to position 0 or below")

1
discord/types/role.py

@ -39,6 +39,7 @@ class Role(TypedDict):
permissions: str
managed: bool
mentionable: bool
flags: int
icon: NotRequired[Optional[str]]
unicode_emoji: NotRequired[Optional[str]]
tags: NotRequired[RoleTags]

8
docs/api.rst

@ -4990,6 +4990,14 @@ AttachmentFlags
.. autoclass:: AttachmentFlags
:members:
RoleFlags
~~~~~~~~~~
.. attributetable:: RoleFlags
.. autoclass:: RoleFlags
:members:
ForumTag
~~~~~~~~~

Loading…
Cancel
Save