Skip to content

Commit af87860

Browse files
NeloBlivionpre-commit-ci[bot]plun1331Dorukyum
authored
feat: implement RoleFlags (#2487)
* implement roleflags * style(pre-commit): auto fixes from pre-commit.com hooks * cl * style(pre-commit): auto fixes from pre-commit.com hooks * Update discord/flags.py Signed-off-by: plun1331 <[email protected]> * Update CHANGELOG.md Co-authored-by: Dorukyum <[email protected]> Signed-off-by: UK <[email protected]> * fix docs * again? * better formatting * flags.py aktualisieren Signed-off-by: Dorukyum <[email protected]> * test formatting fix * resolve conflicts * revert --------- Signed-off-by: plun1331 <[email protected]> Signed-off-by: UK <[email protected]> Signed-off-by: Dorukyum <[email protected]> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: plun1331 <[email protected]> Co-authored-by: Dorukyum <[email protected]>
1 parent de117fe commit af87860

File tree

5 files changed

+70
-0
lines changed

5 files changed

+70
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ These changes are available on the `master` branch, but have not yet been releas
3737
- Added `MemberFlags`. ([#2489](https://github.com/Pycord-Development/pycord/pull/2489))
3838
- Added `bypass_verification` parameter to `Member.edit`.
3939
([#2489](https://github.com/Pycord-Development/pycord/pull/2489))
40+
- Added `RoleFlags`. ([#2487](https://github.com/Pycord-Development/pycord/pull/2487))
4041

4142
### Fixed
4243

discord/flags.py

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
"ApplicationFlags",
4040
"ChannelFlags",
4141
"SKUFlags",
42+
"RoleFlags",
4243
"MemberFlags",
4344
)
4445

@@ -1758,3 +1759,57 @@ def bypasses_verification(self):
17581759
def started_onboarding(self):
17591760
""":class:`bool`: Returns ``True`` if the member has started onboarding."""
17601761
return 1 << 3
1762+
1763+
1764+
@fill_with_flags()
1765+
class RoleFlags(BaseFlags):
1766+
r"""Wraps up the Discord Role flags.
1767+
1768+
.. container:: operations
1769+
1770+
.. describe:: x == y
1771+
1772+
Checks if two RoleFlags are equal.
1773+
.. describe:: x != y
1774+
1775+
Checks if two RoleFlags are not equal.
1776+
.. describe:: x + y
1777+
1778+
Adds two flags together. Equivalent to ``x | y``.
1779+
.. describe:: x - y
1780+
1781+
Subtracts two flags from each other.
1782+
.. describe:: x | y
1783+
1784+
Returns the union of two flags. Equivalent to ``x + y``.
1785+
.. describe:: x & y
1786+
1787+
Returns the intersection of two flags.
1788+
.. describe:: ~x
1789+
1790+
Returns the inverse of a flag.
1791+
.. describe:: hash(x)
1792+
1793+
Return the flag's hash.
1794+
.. describe:: iter(x)
1795+
1796+
Returns an iterator of ``(name, value)`` pairs. This allows it
1797+
to be, for example, constructed as a dict or a list of pairs.
1798+
Note that aliases are not shown.
1799+
1800+
.. versionadded:: 2.6
1801+
1802+
Attributes
1803+
-----------
1804+
value: :class:`int`
1805+
The raw value. This value is a bit array field of a 53-bit integer
1806+
representing the currently available flags. You should query
1807+
flags via the properties rather than using this raw value.
1808+
"""
1809+
1810+
__slots__ = ()
1811+
1812+
@flag_value
1813+
def in_prompt(self):
1814+
""":class:`bool`: Returns ``True`` if the role is selectable in one of the guild's :class:`~discord.OnboardingPrompt`."""
1815+
return 1 << 0

discord/role.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
from .asset import Asset
3131
from .colour import Colour
3232
from .errors import InvalidArgument
33+
from .flags import RoleFlags
3334
from .mixins import Hashable
3435
from .permissions import Permissions
3536
from .utils import MISSING, _bytes_to_base64_data, _get_as_snowflake, snowflake_time
@@ -177,6 +178,11 @@ class Role(Hashable):
177178
Only available to guilds that contain ``ROLE_ICONS`` in :attr:`Guild.features`.
178179
179180
.. versionadded:: 2.0
181+
182+
flags: :class:`RoleFlags`
183+
Extra attributes of the role.
184+
185+
.. versionadded:: 2.6
180186
"""
181187

182188
__slots__ = (
@@ -193,6 +199,7 @@ class Role(Hashable):
193199
"unicode_emoji",
194200
"_icon",
195201
"_state",
202+
"flags",
196203
)
197204

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

258266
try:

discord/types/role.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class Role(TypedDict):
3939
permissions: str
4040
managed: bool
4141
mentionable: bool
42+
flags: int
4243

4344

4445
class RoleTags(TypedDict, total=False):

docs/api/data_classes.rst

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,11 @@ Flags
171171
.. autoclass:: MemberFlags()
172172
:members:
173173

174+
.. attributetable:: RoleFlags
175+
176+
.. autoclass:: RoleFlags()
177+
:members:
178+
174179
Colour
175180
------
176181

0 commit comments

Comments
 (0)