From c831a71d41cba686a8d0493cff0592367e4bfa84 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 13 Oct 2024 15:31:31 +0200 Subject: [PATCH 1/5] :memo: Better doc. of role tags --- discord/role.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/discord/role.py b/discord/role.py index 1907606e9d..b403416704 100644 --- a/discord/role.py +++ b/discord/role.py @@ -167,8 +167,7 @@ class Role(Hashable): operators on the role objects themselves. managed: :class:`bool` - Indicates if the role is managed by the guild through some form of - integrations such as Twitch. + Indicates if the role is managed by the guild. This is true if :meth:`Role.is_integration`, :meth:`Role.is_premium_subscriber`, or :meth:`Role.is_bot_managed` is ``True``. mentionable: :class:`bool` Indicates if the role can be mentioned by users. tags: Optional[:class:`RoleTags`] @@ -287,7 +286,8 @@ def is_premium_subscriber(self) -> bool: return self.tags is not None and self.tags.is_premium_subscriber() def is_integration(self) -> bool: - """Whether the role is managed by an integration. + """Whether the role is managed by the guild through some form of + integrations such as Twitch. .. versionadded:: 1.6 """ From b2896a533c34f90ef2255a6ed17a88a325213530 Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 13 Oct 2024 17:32:10 +0200 Subject: [PATCH 2/5] =?UTF-8?q?=E2=9C=A8=20Add=20new=20role=20tags=20and?= =?UTF-8?q?=20methods?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- discord/role.py | 69 ++++++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 63 insertions(+), 6 deletions(-) diff --git a/discord/role.py b/discord/role.py index b403416704..58925f6502 100644 --- a/discord/role.py +++ b/discord/role.py @@ -68,22 +68,37 @@ class RoleTags: The bot's user ID that manages this role. integration_id: Optional[:class:`int`] The integration ID that manages the role. + subscription_listing_id: Optional[:class:`int`] + The subscription SKU and listing ID of the role. + + .. versionadded:: 2.7 """ __slots__ = ( "bot_id", "integration_id", + "subscription_listing_id", "_premium_subscriber", + "_available_for_purchase", + "_guild_connections", ) def __init__(self, data: RoleTagPayload): self.bot_id: int | None = _get_as_snowflake(data, "bot_id") self.integration_id: int | None = _get_as_snowflake(data, "integration_id") - # NOTE: The API returns "null" for this if it's valid, which corresponds to None. + self.subscription_listing_id: int | None = _get_as_snowflake( + data, "subscription_listing_id" + ) + # NOTE: The API returns "null" for this if the following tags True, and doesn't return them at all if False. + # However, "null" corresponds to None. # This is different from other fields where "null" means "not there". # So in this case, a value of None is the same as True. # Which means we would need a different sentinel. self._premium_subscriber: Any | None = data.get("premium_subscriber", MISSING) + self._available_for_purchase: Any | None = data.get( + "available_for_purchase", MISSING + ) + self._guild_connections: Any | None = data.get("guild_connections", MISSING) def is_bot_managed(self) -> bool: """Whether the role is associated with a bot.""" @@ -94,13 +109,35 @@ def is_premium_subscriber(self) -> bool: return self._premium_subscriber is None def is_integration(self) -> bool: - """Whether the role is managed by an integration.""" + """Whether the guild manages the role through some form of + integrations such as Twitch or trough guild subscriptions. + """ return self.integration_id is not None + def is_available_for_purchase(self) -> bool: + """Whether the role is available for purchase. + + Returns ``True`` if the role is available for purchase, + ``False`` if it is not or if the role is not linked to a guild subscription. + + .. versionadded:: 2.7 + """ + return self._available_for_purchase is None + + def is_guild_connections_role(self) -> bool: + """Whether the role is a guild connections role. + + .. versionadded:: 2.7 + """ + return self._guild_connections is None + def __repr__(self) -> str: return ( f"" + f"subscription_listing_id={self.subscription_listing_id} " + f"premium_subscriber={self.is_premium_subscriber()} " + f"available_for_purchase={self.is_available_for_purchase()} " + f"guild_connections={self.is_guild_connections_role()}>" ) @@ -167,7 +204,10 @@ class Role(Hashable): operators on the role objects themselves. managed: :class:`bool` - Indicates if the role is managed by the guild. This is true if :meth:`Role.is_integration`, :meth:`Role.is_premium_subscriber`, or :meth:`Role.is_bot_managed` is ``True``. + Indicates if the role is managed by the guild. + This is true if any of :meth:`Role.is_integration`, :meth:`Role.is_premium_subscriber`, + :meth:`Role.is_bot_managed` or :meth:`Role.is_guild_connections_role` + are ``True``. mentionable: :class:`bool` Indicates if the role can be mentioned by users. tags: Optional[:class:`RoleTags`] @@ -286,8 +326,8 @@ def is_premium_subscriber(self) -> bool: return self.tags is not None and self.tags.is_premium_subscriber() def is_integration(self) -> bool: - """Whether the role is managed by the guild through some form of - integrations such as Twitch. + """Whether the guild manages the role through some form of + integrations such as Twitch or trough guild subscriptions. .. versionadded:: 1.6 """ @@ -305,6 +345,23 @@ def is_assignable(self) -> bool: and (me.top_role > self or me.id == self.guild.owner_id) ) + def is_available_for_purchase(self) -> bool: + """Whether the role is available for purchase. + + Returns ``True`` if the role is available for purchase, + ``False`` if it is not or if the role is not linked to a guild subscription. + + .. versionadded:: 2.7 + """ + return self.tags is not None and self.tags.is_available_for_purchase() + + def is_guild_connections_role(self) -> bool: + """Whether the role is a guild connections role. + + .. versionadded:: 2.7 + """ + return self.tags is not None and self.tags.is_guild_connections_role() + @property def permissions(self) -> Permissions: """Returns the role's permissions.""" From f4f1f2e41df41b6528db2144d999a2657c2c021d Mon Sep 17 00:00:00 2001 From: Paillat Date: Sun, 13 Oct 2024 18:00:11 +0200 Subject: [PATCH 3/5] :memo: Changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index d77dee89d3..51ae7c6ac3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,6 +30,9 @@ These changes are available on the `master` branch, but have not yet been releas ([#2587](https://github.com/Pycord-Development/pycord/pull/2587/)) - Added optional `filter` parameter to `utils.basic_autocomplete()`. ([#2590](https://github.com/Pycord-Development/pycord/pull/2590)) +- Added new role tags `subscription_listing_id`, `guild_connections` and + `available_for_purchase`. + ([#2606](https://github.com/Pycord-Development/pycord/pull/2606)) ### Fixed From f8193609f470fa77d963331a6d5ce048b9650423 Mon Sep 17 00:00:00 2001 From: Paillat Date: Thu, 12 Dec 2024 13:42:30 +0100 Subject: [PATCH 4/5] :pencil2: Fix writing --- CHANGELOG.md | 2 +- discord/role.py | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 4381266aa1..7957e48ca8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,7 +30,7 @@ These changes are available on the `master` branch, but have not yet been releas ([#2587](https://github.com/Pycord-Development/pycord/pull/2587/)) - Added optional `filter` parameter to `utils.basic_autocomplete()`. ([#2590](https://github.com/Pycord-Development/pycord/pull/2590)) -- Added new role tags `subscription_listing_id`, `guild_connections` and +- Added new role tags `subscription_listing_id`, `guild_connections`, and `available_for_purchase`. ([#2606](https://github.com/Pycord-Development/pycord/pull/2606)) - Added missing `with_counts` parameter to `fetch_guilds` method. diff --git a/discord/role.py b/discord/role.py index 58925f6502..ceb6cf93ec 100644 --- a/discord/role.py +++ b/discord/role.py @@ -118,7 +118,7 @@ def is_available_for_purchase(self) -> bool: """Whether the role is available for purchase. Returns ``True`` if the role is available for purchase, - ``False`` if it is not or if the role is not linked to a guild subscription. + ``False`` if it is not available for purchase or if the role is not linked to a guild subscription. .. versionadded:: 2.7 """ @@ -207,7 +207,7 @@ class Role(Hashable): Indicates if the role is managed by the guild. This is true if any of :meth:`Role.is_integration`, :meth:`Role.is_premium_subscriber`, :meth:`Role.is_bot_managed` or :meth:`Role.is_guild_connections_role` - are ``True``. + is ``True``. mentionable: :class:`bool` Indicates if the role can be mentioned by users. tags: Optional[:class:`RoleTags`] @@ -349,7 +349,7 @@ def is_available_for_purchase(self) -> bool: """Whether the role is available for purchase. Returns ``True`` if the role is available for purchase, - ``False`` if it is not or if the role is not linked to a guild subscription. + ``False`` if it is not available for purchase or if the role is not linked to a guild subscription. .. versionadded:: 2.7 """ From 24c2ec8bc7689ef9c45d56ac25966c5df02271c1 Mon Sep 17 00:00:00 2001 From: Paillat Date: Wed, 18 Dec 2024 15:20:09 +0100 Subject: [PATCH 5/5] :pencil2: Fix writing 2 --- CHANGELOG.md | 2 +- discord/role.py | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7957e48ca8..bc3f13f2ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -30,7 +30,7 @@ These changes are available on the `master` branch, but have not yet been releas ([#2587](https://github.com/Pycord-Development/pycord/pull/2587/)) - Added optional `filter` parameter to `utils.basic_autocomplete()`. ([#2590](https://github.com/Pycord-Development/pycord/pull/2590)) -- Added new role tags `subscription_listing_id`, `guild_connections`, and +- Added the following role tags: `subscription_listing_id`, `guild_connections`, and `available_for_purchase`. ([#2606](https://github.com/Pycord-Development/pycord/pull/2606)) - Added missing `with_counts` parameter to `fetch_guilds` method. diff --git a/discord/role.py b/discord/role.py index ceb6cf93ec..64846b4c93 100644 --- a/discord/role.py +++ b/discord/role.py @@ -110,14 +110,14 @@ def is_premium_subscriber(self) -> bool: def is_integration(self) -> bool: """Whether the guild manages the role through some form of - integrations such as Twitch or trough guild subscriptions. + integrations such as Twitch or through guild subscriptions. """ return self.integration_id is not None def is_available_for_purchase(self) -> bool: """Whether the role is available for purchase. - Returns ``True`` if the role is available for purchase, + Returns ``True`` if the role is available for purchase, and ``False`` if it is not available for purchase or if the role is not linked to a guild subscription. .. versionadded:: 2.7 @@ -327,7 +327,7 @@ def is_premium_subscriber(self) -> bool: def is_integration(self) -> bool: """Whether the guild manages the role through some form of - integrations such as Twitch or trough guild subscriptions. + integrations such as Twitch or through guild subscriptions. .. versionadded:: 1.6 """ @@ -348,7 +348,7 @@ def is_assignable(self) -> bool: def is_available_for_purchase(self) -> bool: """Whether the role is available for purchase. - Returns ``True`` if the role is available for purchase, + Returns ``True`` if the role is available for purchase, and ``False`` if it is not available for purchase or if the role is not linked to a guild subscription. .. versionadded:: 2.7