From 04aee32b8adcf6958977816e59a37115863ca1f8 Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Sun, 30 Jun 2024 20:45:40 +0100 Subject: [PATCH 01/13] implement roleflags --- discord/flags.py | 42 +++++++++++++++++++++++++++++++++++++++ discord/role.py | 8 ++++++++ discord/types/role.py | 1 + docs/api/data_classes.rst | 5 +++++ 4 files changed, 56 insertions(+) diff --git a/discord/flags.py b/discord/flags.py index 37fd8baa24..c6e7f540f4 100644 --- a/discord/flags.py +++ b/discord/flags.py @@ -39,6 +39,7 @@ "ApplicationFlags", "ChannelFlags", "SKUFlags", + "RoleFlags", ) FV = TypeVar("FV", bound="flag_value") @@ -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.5 + 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 \ No newline at end of file diff --git a/discord/role.py b/discord/role.py index 4012d29cb5..1907606e9d 100644 --- a/discord/role.py +++ b/discord/role.py @@ -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 @@ -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__ = ( @@ -193,6 +199,7 @@ class Role(Hashable): "unicode_emoji", "_icon", "_state", + "flags", ) def __init__(self, *, guild: Guild, state: ConnectionState, data: RolePayload): @@ -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: diff --git a/discord/types/role.py b/discord/types/role.py index 8996e7e21d..d387d38b77 100644 --- a/discord/types/role.py +++ b/discord/types/role.py @@ -39,6 +39,7 @@ class Role(TypedDict): permissions: str managed: bool mentionable: bool + flags: int class RoleTags(TypedDict, total=False): diff --git a/docs/api/data_classes.rst b/docs/api/data_classes.rst index f0508ac09b..9131b25da2 100644 --- a/docs/api/data_classes.rst +++ b/docs/api/data_classes.rst @@ -166,6 +166,11 @@ Flags .. autoclass:: SKUFlags() :members: +.. attributetable:: RoleFlags + +.. autoclass:: RoleFlags() + :members: + Colour ------ From cb6687b677b535486deb2a7822547e90825505de Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 30 Jun 2024 19:48:45 +0000 Subject: [PATCH 02/13] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/flags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/flags.py b/discord/flags.py index c6e7f540f4..cf4d79f569 100644 --- a/discord/flags.py +++ b/discord/flags.py @@ -1725,4 +1725,4 @@ class RoleFlags(BaseFlags): @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 \ No newline at end of file + return 1 << 0 From 198d1312e5f8fda1f62b53dcf0e33bbf0fe189fd Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Sun, 30 Jun 2024 20:49:18 +0100 Subject: [PATCH 03/13] cl --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 04e709d410..0130c69043 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,8 @@ 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)) ### Fixed From bb3fee9359b8d89c210ed8e600b5560825c5e9da Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Sun, 30 Jun 2024 19:49:36 +0000 Subject: [PATCH 04/13] style(pre-commit): auto fixes from pre-commit.com hooks --- CHANGELOG.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 0130c69043..a3e70b6d38 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,8 +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)) +- Added `RoleFlags` ([#2487](https://github.com/Pycord-Development/pycord/pull/2487)) ### Fixed From 359a7ef85248d431f5a4de45087a5f619f0b6dfb Mon Sep 17 00:00:00 2001 From: plun1331 Date: Sun, 30 Jun 2024 13:34:33 -0700 Subject: [PATCH 05/13] Update discord/flags.py Signed-off-by: plun1331 --- discord/flags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/flags.py b/discord/flags.py index cf4d79f569..883562f3f6 100644 --- a/discord/flags.py +++ b/discord/flags.py @@ -1711,7 +1711,7 @@ class RoleFlags(BaseFlags): .. 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.5 + .. versionadded:: 2.6 Attributes ----------- value: :class:`int` From f0cfb8edc3853db8e1904590a28ae54f1ed438f3 Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Sun, 30 Jun 2024 22:06:50 +0100 Subject: [PATCH 06/13] Update CHANGELOG.md Co-authored-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Signed-off-by: UK <41271523+NeloBlivion@users.noreply.github.com> --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a3e70b6d38..df1ad9fe0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,7 +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)) +- Added `RoleFlags`. ([#2487](https://github.com/Pycord-Development/pycord/pull/2487)) ### Fixed From 8f124d7e0bf201c42764d69033413e1cbe1c8a23 Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Sun, 30 Jun 2024 22:07:57 +0100 Subject: [PATCH 07/13] fix docs --- discord/flags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/flags.py b/discord/flags.py index 883562f3f6..7f434bfdcd 100644 --- a/discord/flags.py +++ b/discord/flags.py @@ -1724,5 +1724,5 @@ class RoleFlags(BaseFlags): @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""" + """:class:`bool`: Returns ``True`` if the role is selectable in one of the guild's :class:`~discord.OnboardingPrompt`s""" return 1 << 0 From da1d232efb190c140278dc7597f3e79225474095 Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Sun, 30 Jun 2024 22:14:13 +0100 Subject: [PATCH 08/13] again? --- discord/flags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/flags.py b/discord/flags.py index 7f434bfdcd..6684ab0dbc 100644 --- a/discord/flags.py +++ b/discord/flags.py @@ -1724,5 +1724,5 @@ class RoleFlags(BaseFlags): @flag_value def in_prompt(self): - """:class:`bool`: Returns ``True`` if the role is selectable in one of the guild's :class:`~discord.OnboardingPrompt`s""" + """:class:`bool`: Returns ``True`` if the role is selectable in one of the guild's :class:`~discord.OnboardingPrompt`""" return 1 << 0 From c1417ee03e19f12c44f7b543238fcd1b71110848 Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Sun, 30 Jun 2024 23:51:39 +0100 Subject: [PATCH 09/13] better formatting --- discord/flags.py | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/discord/flags.py b/discord/flags.py index 6684ab0dbc..4de45f315b 100644 --- a/discord/flags.py +++ b/discord/flags.py @@ -1690,28 +1690,41 @@ def user_subscription(self): @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. + + Checks if two RoleFlags are equal. .. describe:: x != y - Checks if two flags are not equal. + + Checks if two RoleFlags 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. + + 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. + + 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. + .. versionadded:: 2.6 + Attributes ----------- value: :class:`int` From 73020624fc8b4b8fde8bf3918992dc1ac5d44778 Mon Sep 17 00:00:00 2001 From: Dorukyum <53639936+Dorukyum@users.noreply.github.com> Date: Mon, 1 Jul 2024 02:16:05 +0300 Subject: [PATCH 10/13] flags.py aktualisieren Signed-off-by: Dorukyum <53639936+Dorukyum@users.noreply.github.com> --- discord/flags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/flags.py b/discord/flags.py index 4de45f315b..90a8fbb9ca 100644 --- a/discord/flags.py +++ b/discord/flags.py @@ -1737,5 +1737,5 @@ class RoleFlags(BaseFlags): @flag_value def in_prompt(self): - """:class:`bool`: Returns ``True`` if the role is selectable in one of the guild's :class:`~discord.OnboardingPrompt`""" + """:class:`bool`: Returns ``True`` if the role is selectable in one of the guild's :class:`~discord.OnboardingPrompt`s.""" return 1 << 0 From 083e71fb90eadd2e10f814d650af0687e7d45909 Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Mon, 1 Jul 2024 02:41:43 +0100 Subject: [PATCH 11/13] test formatting fix --- discord/flags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/flags.py b/discord/flags.py index 90a8fbb9ca..7627da4fed 100644 --- a/discord/flags.py +++ b/discord/flags.py @@ -1737,5 +1737,5 @@ class RoleFlags(BaseFlags): @flag_value def in_prompt(self): - """:class:`bool`: Returns ``True`` if the role is selectable in one of the guild's :class:`~discord.OnboardingPrompt`s.""" + """:class:`bool`: Returns ``True`` if the role is selectable in one of the guild's :class:`discord.OnboardingPrompt`s.""" return 1 << 0 From ef0e931e9ecbdc21253bc29b1b499baacc7e9c3d Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Mon, 1 Jul 2024 02:46:13 +0100 Subject: [PATCH 12/13] resolve conflicts --- CHANGELOG.md | 3 ++ discord/flags.py | 73 +++++++++++++++++++++++++++++++++++++++ docs/api/data_classes.rst | 5 +++ 3 files changed, 81 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index a72f643f62..3bae94f5ae 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,9 @@ These changes are available on the `master` branch, but have not yet been releas ([#2438](https://github.com/Pycord-Development/pycord/pull/2438)) - Added `Attachment.title`. ([#2486](https://github.com/Pycord-Development/pycord/pull/2486)) +- Added `MemberFlags`. ([#2489](https://github.com/Pycord-Development/pycord/pull/2489)) +- Added `bypass_verification` parameter to `Member.edit`. + ([#2489](https://github.com/Pycord-Development/pycord/pull/2489)) - Added `RoleFlags`. ([#2487](https://github.com/Pycord-Development/pycord/pull/2487)) ### Fixed diff --git a/discord/flags.py b/discord/flags.py index 7627da4fed..62fed29a7c 100644 --- a/discord/flags.py +++ b/discord/flags.py @@ -1687,6 +1687,79 @@ def user_subscription(self): return 1 << 8 +@fill_with_flags() +class MemberFlags(BaseFlags): + r"""Wraps up the Discord Member flags. + + .. container:: operations + + .. describe:: x == y + + Checks if two MemberFlags are equal. + .. describe:: x != y + + Checks if two MemberFlags 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. + Note that aliases are not shown. + + .. versionadded:: 2.6 + + Attributes + ----------- + value: :class:`int` + The raw value. You should query flags via the properties + rather than using this raw value. + """ + + __slots__ = () + + @flag_value + def did_rejoin(self): + """:class:`bool`: Returns ``True`` if the member left and rejoined the guild.""" + return 1 << 0 + + @flag_value + def completed_onboarding(self): + """:class:`bool`: Returns ``True`` if the member has completed onboarding.""" + return 1 << 1 + + @flag_value + def bypasses_verification(self): + """:class:`bool`: Returns ``True`` if the member is exempt from verification requirements. + + .. note:: + + This can be edited through :func:`~discord.Member.edit`. + """ + return 1 << 2 + + @flag_value + def started_onboarding(self): + """:class:`bool`: Returns ``True`` if the member has started onboarding.""" + return 1 << 3 + + @fill_with_flags() class RoleFlags(BaseFlags): r"""Wraps up the Discord Role flags. diff --git a/docs/api/data_classes.rst b/docs/api/data_classes.rst index 9131b25da2..272b21e74b 100644 --- a/docs/api/data_classes.rst +++ b/docs/api/data_classes.rst @@ -166,6 +166,11 @@ Flags .. autoclass:: SKUFlags() :members: +.. attributetable:: MemberFlags + +.. autoclass:: MemberFlags() + :members: + .. attributetable:: RoleFlags .. autoclass:: RoleFlags() From 0c196d6c90c364535b660108b5c1d67254330c65 Mon Sep 17 00:00:00 2001 From: UK <41271523+NeloBlivion@users.noreply.github.com> Date: Mon, 1 Jul 2024 02:48:57 +0100 Subject: [PATCH 13/13] revert --- discord/flags.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/flags.py b/discord/flags.py index 5ac67b8b7e..8a1ac8fd7e 100644 --- a/discord/flags.py +++ b/discord/flags.py @@ -1811,5 +1811,5 @@ class RoleFlags(BaseFlags): @flag_value def in_prompt(self): - """:class:`bool`: Returns ``True`` if the role is selectable in one of the guild's :class:`discord.OnboardingPrompt`s.""" + """:class:`bool`: Returns ``True`` if the role is selectable in one of the guild's :class:`~discord.OnboardingPrompt`.""" return 1 << 0