From 8d035e1d6bd1ca585516334f2dbe02d8e9366c5e Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Mon, 1 Jul 2024 16:44:12 +0200 Subject: [PATCH 01/10] Fix premium buttons --- discord/ui/button.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/ui/button.py b/discord/ui/button.py index bdd49d21f8..5487fd6b73 100644 --- a/discord/ui/button.py +++ b/discord/ui/button.py @@ -117,7 +117,7 @@ def __init__( ) self._provided_custom_id = custom_id is not None - if url is None and custom_id is None: + if url is None and custom_id is None and sku_id is None: custom_id = os.urandom(16).hex() if url is not None: From e963b7c372488f263379c4785bdb66111e1a295d Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Mon, 1 Jul 2024 16:55:09 +0200 Subject: [PATCH 02/10] Fix EntitlementIterator call --- discord/client.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/discord/client.py b/discord/client.py index 0044272d59..63a4f40d55 100644 --- a/discord/client.py +++ b/discord/client.py @@ -2085,7 +2085,7 @@ async def fetch_entitlements( Returns ------- - List[:class:`.Entitlement`] + :class:`.EntitlementIterator` The application's entitlements. Raises @@ -2095,12 +2095,12 @@ async def fetch_entitlements( """ return EntitlementIterator( self._connection, - user_id=user.id, - sku_ids=[sku.id for sku in skus], + user_id=user.id if user else None, + sku_ids=[sku.id for sku in skus] if skus else None, before=before, after=after, limit=limit, - guild_id=guild.id, + guild_id=guild.id if guild else None, exclude_ended=exclude_ended, ) From 27bdb2db9716bfb1766458ff0ccda852761f0ad4 Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Mon, 1 Jul 2024 17:26:28 +0200 Subject: [PATCH 03/10] Test yarl bool --- discord/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/client.py b/discord/client.py index 63a4f40d55..7b29fb526a 100644 --- a/discord/client.py +++ b/discord/client.py @@ -2051,7 +2051,7 @@ async def fetch_entitlements( after: SnowflakeTime | None = None, limit: int | None = 100, guild: Snowflake | None = None, - exclude_ended: bool = False, + exclude_ended: bool | None = None, ) -> EntitlementIterator: """|coro| From e2ca50bd939743b772a2ac3b78bd13f77a096a47 Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Mon, 1 Jul 2024 17:57:05 +0200 Subject: [PATCH 04/10] Add TODO --- discord/client.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/discord/client.py b/discord/client.py index 7b29fb526a..8215207270 100644 --- a/discord/client.py +++ b/discord/client.py @@ -2051,7 +2051,7 @@ async def fetch_entitlements( after: SnowflakeTime | None = None, limit: int | None = 100, guild: Snowflake | None = None, - exclude_ended: bool | None = None, + exclude_ended: bool | None = None, # TODO this is only a temporary workarount, as yarl does not support bool ) -> EntitlementIterator: """|coro| From 8249e679348a2ee706eda7ef75819039bfc94c24 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 1 Jul 2024 16:11:11 +0000 Subject: [PATCH 05/10] style(pre-commit): auto fixes from pre-commit.com hooks --- discord/client.py | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/discord/client.py b/discord/client.py index 8215207270..aa4b9842a1 100644 --- a/discord/client.py +++ b/discord/client.py @@ -2051,7 +2051,9 @@ async def fetch_entitlements( after: SnowflakeTime | None = None, limit: int | None = 100, guild: Snowflake | None = None, - exclude_ended: bool | None = None, # TODO this is only a temporary workarount, as yarl does not support bool + exclude_ended: ( + bool | None + ) = None, # TODO this is only a temporary workarount, as yarl does not support bool ) -> EntitlementIterator: """|coro| From 65ebab3a4196a7d9509f2bc1c2c4d850a28ba9cb Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Mon, 1 Jul 2024 18:21:09 +0200 Subject: [PATCH 06/10] Cast `exclude_ended` to int --- discord/client.py | 4 +--- discord/iterators.py | 2 +- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/discord/client.py b/discord/client.py index aa4b9842a1..63a4f40d55 100644 --- a/discord/client.py +++ b/discord/client.py @@ -2051,9 +2051,7 @@ async def fetch_entitlements( after: SnowflakeTime | None = None, limit: int | None = 100, guild: Snowflake | None = None, - exclude_ended: ( - bool | None - ) = None, # TODO this is only a temporary workarount, as yarl does not support bool + exclude_ended: bool = False, ) -> EntitlementIterator: """|coro| diff --git a/discord/iterators.py b/discord/iterators.py index 2f863ddb9d..4a29adfd16 100644 --- a/discord/iterators.py +++ b/discord/iterators.py @@ -1055,7 +1055,7 @@ async def fill_entitlements(self): user_id=self.user_id, guild_id=self.guild_id, sku_ids=self.sku_ids, - exclude_ended=self.exclude_ended, + exclude_ended=int(self.exclude_ended), ) if not data: From 6e1714a4c0184f46641fc75d1c90671f18cefbff Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Mon, 1 Jul 2024 19:53:26 +0200 Subject: [PATCH 07/10] Fix cast --- discord/http.py | 2 +- discord/iterators.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/discord/http.py b/discord/http.py index e3d6e7dcc9..b29b35d4b2 100644 --- a/discord/http.py +++ b/discord/http.py @@ -2980,7 +2980,7 @@ def list_entitlements( if guild_id is not None: params["guild_id"] = guild_id if exclude_ended is not None: - params["exclude_ended"] = exclude_ended + params["exclude_ended"] = int(exclude_ended) r = Route( "GET", diff --git a/discord/iterators.py b/discord/iterators.py index 4a29adfd16..2f863ddb9d 100644 --- a/discord/iterators.py +++ b/discord/iterators.py @@ -1055,7 +1055,7 @@ async def fill_entitlements(self): user_id=self.user_id, guild_id=self.guild_id, sku_ids=self.sku_ids, - exclude_ended=int(self.exclude_ended), + exclude_ended=self.exclude_ended, ) if not data: From a53cbabc452c6bcb35dbbf24d32d4c997d21504f Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Mon, 1 Jul 2024 23:24:02 +0200 Subject: [PATCH 08/10] Adjust fetch_entitlements to match other iterators --- discord/client.py | 26 +++++++++++++++++++------- discord/guild.py | 23 +++++++++++++---------- discord/user.py | 16 +++++++--------- 3 files changed, 39 insertions(+), 26 deletions(-) diff --git a/discord/client.py b/discord/client.py index 63a4f40d55..ca19230a85 100644 --- a/discord/client.py +++ b/discord/client.py @@ -2043,7 +2043,7 @@ async def fetch_skus(self) -> list[SKU]: data = await self._connection.http.list_skus(self.application_id) return [SKU(data=s) for s in data] - async def fetch_entitlements( + def entitlements( self, user: Snowflake | None = None, skus: list[Snowflake] | None = None, @@ -2053,9 +2053,7 @@ async def fetch_entitlements( guild: Snowflake | None = None, exclude_ended: bool = False, ) -> EntitlementIterator: - """|coro| - - Fetches the bot's entitlements. + """Returns an :class:`.AsyncIterator` that enables fetching the application's entitlements. .. versionadded:: 2.5 @@ -2083,15 +2081,29 @@ async def fetch_entitlements( Whether to limit the fetched entitlements to those that have not ended. Defaults to ``False``. - Returns - ------- - :class:`.EntitlementIterator` + Yields + ------ + :class:`.Entitlement` The application's entitlements. Raises ------ :exc:`HTTPException` Retrieving the entitlements failed. + + Examples + -------- + + Usage :: + + async for entitlement in client.entitlements(): + print(entitlement.user_id) + + Flattening into a list :: + + entitlements = await user.entitlements().flatten() + + All parameters are optional. """ return EntitlementIterator( self._connection, diff --git a/discord/guild.py b/discord/guild.py index 515d7e43af..f1bbe14aa2 100644 --- a/discord/guild.py +++ b/discord/guild.py @@ -68,7 +68,12 @@ from .flags import SystemChannelFlags from .integrations import Integration, _integration_factory from .invite import Invite -from .iterators import AuditLogIterator, BanIterator, MemberIterator +from .iterators import ( + AuditLogIterator, + BanIterator, + EntitlementIterator, + MemberIterator, +) from .member import Member, VoiceState from .mixins import Hashable from .monetization import Entitlement @@ -4071,7 +4076,7 @@ async def create_test_entitlement(self, sku: Snowflake) -> Entitlement: data = await self._state.http.create_test_entitlement(self.id, payload) return Entitlement(data=data, state=self._state) - async def fetch_entitlements( + def entitlements( self, skus: list[Snowflake] | None = None, before: SnowflakeTime | None = None, @@ -4079,11 +4084,9 @@ async def fetch_entitlements( limit: int | None = 100, exclude_ended: bool = False, ) -> EntitlementIterator: - """|coro| + """Returns an :class:`.AsyncIterator` that enables fetching the guild's entitlements. - Fetches this guild's entitlements. - - This is identical to :meth:`Client.fetch_entitlements` with the ``guild`` parameter. + This is identical to :meth:`Client.entitlements` with the ``guild`` parameter. .. versionadded:: 2.6 @@ -4107,9 +4110,9 @@ async def fetch_entitlements( Whether to limit the fetched entitlements to those that have not ended. Defaults to ``False``. - Returns - ------- - List[:class:`.Entitlement`] + Yields + ------ + :class:`.Entitlement` The application's entitlements. Raises @@ -4119,7 +4122,7 @@ async def fetch_entitlements( """ return EntitlementIterator( self._state, - sku_ids=[sku.id for sku in skus], + sku_ids=[sku.id for sku in skus] if skus else None, before=before, after=after, limit=limit, diff --git a/discord/user.py b/discord/user.py index 5c2f41feb1..d986a018f5 100644 --- a/discord/user.py +++ b/discord/user.py @@ -639,7 +639,7 @@ async def create_test_entitlement(self, sku: discord.abc.Snowflake) -> Entitleme data = await self._state.http.create_test_entitlement(self.id, payload) return Entitlement(data=data, state=self._state) - async def fetch_entitlements( + def entitlements( self, skus: list[Snowflake] | None = None, before: SnowflakeTime | None = None, @@ -647,11 +647,9 @@ async def fetch_entitlements( limit: int | None = 100, exclude_ended: bool = False, ) -> EntitlementIterator: - """|coro| - - Fetches this user's entitlements. + """Returns an :class:`.AsyncIterator` that enables fetching the user's entitlements. - This is identical to :meth:`Client.fetch_entitlements` with the ``user`` parameter. + This is identical to :meth:`Client.entitlements` with the ``user`` parameter. .. versionadded:: 2.6 @@ -675,9 +673,9 @@ async def fetch_entitlements( Whether to limit the fetched entitlements to those that have not ended. Defaults to ``False``. - Returns - ------- - List[:class:`.Entitlement`] + Yields + ------ + :class:`.Entitlement` The application's entitlements. Raises @@ -687,7 +685,7 @@ async def fetch_entitlements( """ return EntitlementIterator( self._state, - sku_ids=[sku.id for sku in skus], + sku_ids=[sku.id for sku in skus] if skus else None, before=before, after=after, limit=limit, From 4119281edbdca57da6cf4bb340857b25b31d7cc2 Mon Sep 17 00:00:00 2001 From: Timo <35654063+tibue99@users.noreply.github.com> Date: Tue, 2 Jul 2024 15:34:19 +0200 Subject: [PATCH 09/10] Add changelog --- CHANGELOG.md | 7 +++++-- discord/client.py | 2 +- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 3bf7cd67cb..ac39fee522 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,7 +29,7 @@ These changes are available on the `master` branch, but have not yet been releas - Added `stacklevel` param to `utils.warn_deprecated` and `utils.deprecated`. ([#2450](https://github.com/Pycord-Development/pycord/pull/2450)) - Added support for user-installable applications. - ([#2409](https://github.com/Pycord-Development/pycord/pull/2409) + ([#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 `Attachment.title`. @@ -93,7 +93,10 @@ These changes are available on the `master` branch, but have not yet been releas `ApplicationCommand.contexts`. ([#2409](https://github.com/Pycord-Development/pycord/pull/2409)) - `Message.interaction` is now deprecated in favor of `Message.interaction_metadata`. - ([#2409](https://github.com/Pycord-Development/pycord/pull/2409) + ([#2409](https://github.com/Pycord-Development/pycord/pull/2409)) +- Replaced `client.fetch_entitlements` with `client.entitlements`, which returns an + `EntitlementIterator`. + ([#2490](https://github.com/Pycord-Development/pycord/pull/2490)) ### Removed diff --git a/discord/client.py b/discord/client.py index ca19230a85..4cfaef59cf 100644 --- a/discord/client.py +++ b/discord/client.py @@ -2055,7 +2055,7 @@ def entitlements( ) -> EntitlementIterator: """Returns an :class:`.AsyncIterator` that enables fetching the application's entitlements. - .. versionadded:: 2.5 + .. versionadded:: 2.6 Parameters ---------- From 37958fbdc3185404faba0fe51951aef9b9282314 Mon Sep 17 00:00:00 2001 From: plun1331 Date: Wed, 3 Jul 2024 13:40:16 -0700 Subject: [PATCH 10/10] Update CHANGELOG.md Signed-off-by: plun1331 --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index ac39fee522..6ec3411622 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -94,7 +94,7 @@ These changes are available on the `master` branch, but have not yet been releas ([#2409](https://github.com/Pycord-Development/pycord/pull/2409)) - `Message.interaction` is now deprecated in favor of `Message.interaction_metadata`. ([#2409](https://github.com/Pycord-Development/pycord/pull/2409)) -- Replaced `client.fetch_entitlements` with `client.entitlements`, which returns an +- Replaced `Client.fetch_entitlements` with `Client.entitlements`, which returns an `EntitlementIterator`. ([#2490](https://github.com/Pycord-Development/pycord/pull/2490))