Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: implement RoleFlags #2487

Merged
merged 15 commits into from
Jul 1, 2024
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ These changes are available on the `master` branch, but have not yet been releas
([#2409](https://github.com/Pycord-Development/pycord/pull/2409)
- Added support for one-time purchases for Discord monetization.
([#2438](https://github.com/Pycord-Development/pycord/pull/2438))
- Added `RoleFlags` ([#2487](https://github.com/Pycord-Development/pycord/pull/2487))
NeloBlivion marked this conversation as resolved.
Show resolved Hide resolved

### Fixed

Expand Down
42 changes: 42 additions & 0 deletions discord/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
"ApplicationFlags",
"ChannelFlags",
"SKUFlags",
"RoleFlags",
)

FV = TypeVar("FV", bound="flag_value")
Expand Down Expand Up @@ -1684,3 +1685,44 @@ 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 RoleFlags(BaseFlags):
r"""Wraps up the Discord Role flags.
See :class:`SystemChannelFlags`.
.. container:: operations
.. describe:: x == y
Checks if two flags are equal.
.. describe:: x != y
Checks if two flags are not equal.
.. describe:: x + y
Adds two flags together. Equivalent to ``x | y``.
.. describe:: x - y
Subtracts two flags from each other.
.. describe:: x | y
Returns the union of two flags. Equivalent to ``x + y``.
.. describe:: x & y
Returns the intersection of two flags.
.. describe:: ~x
Returns the inverse of a flag.
.. 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.
.. versionadded:: 2.6
Attributes
-----------
value: :class:`int`
The raw value. This value is a bit array field of a 53-bit integer
representing the currently available flags. You should query
flags via the properties rather than using this raw value.
"""

__slots__ = ()

@flag_value
def in_prompt(self):
""":class:`bool`: Returns ``True`` if the role is selectable in one of the guild's :attr:.`~discord.OnboardingPrompt`s"""
return 1 << 0
8 changes: 8 additions & 0 deletions discord/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
from .asset import Asset
from .colour import Colour
from .errors import InvalidArgument
from .flags import RoleFlags
from .mixins import Hashable
from .permissions import Permissions
from .utils import MISSING, _bytes_to_base64_data, _get_as_snowflake, snowflake_time
Expand Down Expand Up @@ -177,6 +178,11 @@ class Role(Hashable):
Only available to guilds that contain ``ROLE_ICONS`` in :attr:`Guild.features`.

.. versionadded:: 2.0

flags: :class:`RoleFlags`
Extra attributes of the role.

.. versionadded:: 2.6
"""

__slots__ = (
Expand All @@ -193,6 +199,7 @@ class Role(Hashable):
"unicode_emoji",
"_icon",
"_state",
"flags",
)

def __init__(self, *, guild: Guild, state: ConnectionState, data: RolePayload):
Expand Down Expand Up @@ -253,6 +260,7 @@ def _update(self, data: RolePayload):
self.mentionable: bool = data.get("mentionable", False)
self._icon: str | None = data.get("icon")
self.unicode_emoji: str | None = data.get("unicode_emoji")
self.flags: RoleFlags = RoleFlags._from_value(data.get("flags", 0))
self.tags: RoleTags | None

try:
Expand Down
1 change: 1 addition & 0 deletions discord/types/role.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Role(TypedDict):
permissions: str
managed: bool
mentionable: bool
flags: int


class RoleTags(TypedDict, total=False):
Expand Down
5 changes: 5 additions & 0 deletions docs/api/data_classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ Flags
.. autoclass:: SKUFlags()
:members:

.. attributetable:: RoleFlags

.. autoclass:: RoleFlags()
:members:

Colour
------

Expand Down
Loading