From f9c4554c8045f841122070f4f5d03d661e6738c5 Mon Sep 17 00:00:00 2001 From: AstreaTSS <25420078+AstreaTSS@users.noreply.github.com> Date: Fri, 7 Jun 2024 18:14:20 -0400 Subject: [PATCH] feat: update entitlements with new properties and functions --- .../api/http/http_requests/entitlements.py | 18 ++++++++++++++++++ interactions/client/client.py | 10 ++++++++++ interactions/models/discord/entitlement.py | 4 +++- interactions/models/discord/enums.py | 15 +++++++++++++++ 4 files changed, 46 insertions(+), 1 deletion(-) diff --git a/interactions/api/http/http_requests/entitlements.py b/interactions/api/http/http_requests/entitlements.py index 632a4909a..9b6796ba1 100644 --- a/interactions/api/http/http_requests/entitlements.py +++ b/interactions/api/http/http_requests/entitlements.py @@ -89,3 +89,21 @@ async def delete_test_entitlement(self, application_id: "Snowflake_Type", entitl entitlement_id=entitlement_id, ) ) + + async def consume_entitlement(self, application_id: "Snowflake_Type", entitlement_id: "Snowflake_Type") -> None: + """ + For One-Time Purchase consumable SKUs, marks a given entitlement for the user as consumed. + + Args: + application_id: The ID of the application. + entitlement_id: The ID of the entitlement. + + """ + await self.request( + Route( + "POST", + "/applications/{application_id}/entitlements/{entitlement_id}/consume", + application_id=application_id, + entitlement_id=entitlement_id, + ) + ) diff --git a/interactions/client/client.py b/interactions/client/client.py index 47a631f08..ff00b3642 100644 --- a/interactions/client/client.py +++ b/interactions/client/client.py @@ -2572,6 +2572,16 @@ async def delete_test_entitlement(self, entitlement_id: "Snowflake_Type") -> Non """ await self.http.delete_test_entitlement(self.app.id, to_snowflake(entitlement_id)) + async def consume_entitlement(self, entitlement_id: "Snowflake_Type") -> None: + """ + For One-Time Purchase consumable SKUs, marks a given entitlement for the user as consumed. + + Args: + entitlement_id: The ID of the entitlement to consume. + + """ + await self.http.consume_entitlement(self.app.id, entitlement_id) + def mention_command(self, name: str, scope: int = 0) -> str: """ Returns a string that would mention the interaction specified. diff --git a/interactions/models/discord/entitlement.py b/interactions/models/discord/entitlement.py index bb14ba52f..d4af90fef 100644 --- a/interactions/models/discord/entitlement.py +++ b/interactions/models/discord/entitlement.py @@ -24,8 +24,10 @@ class Entitlement(DiscordObject): """ID of the parent application.""" type: EntitlementType = attrs.field(repr=False, converter=EntitlementType) """The type of entitlement.""" - deleted: bool = attrs.field(repr=False, converter=bool) + deleted: bool = attrs.field(repr=False) """Whether the entitlement is deleted.""" + consumed: bool = attrs.field(repr=False, default=False) + """For consumable items, whether or not the entitlement has been consumed""" subscription_id: Optional[Snowflake_Type] = attrs.field(repr=False, converter=to_optional_snowflake, default=None) """The ID of the subscription plan. Not present when using test entitlements.""" starts_at: Optional[Timestamp] = attrs.field(repr=False, converter=optional_c(timestamp_converter), default=None) diff --git a/interactions/models/discord/enums.py b/interactions/models/discord/enums.py index ca5330c85..8e70dc0ca 100644 --- a/interactions/models/discord/enums.py +++ b/interactions/models/discord/enums.py @@ -1099,4 +1099,19 @@ def converter(cls, value: Optional[int]) -> "ForumSortOrder": class EntitlementType(CursedIntEnum): """The type of entitlement.""" + PURCHASE = 1 + """Entitlement was purchased by user""" + PREMIUM_SUBSCRIPTION = 2 + """Entitlement for Discord Nitro subscription""" + DEVELOPER_GIFT = 3 + """Entitlement was gifted by developer""" + TEST_MODE_PURCHASE = 4 + """Entitlement was purchased by a dev in application test mode""" + FREE_PURCHASE = 5 + """Entitlement was granted when the SKU was free""" + USER_GIFT = 6 + """Entitlement was gifted by another user""" + PREMIUM_PURCHASE = 7 + """Entitlement was claimed by user for free as a Nitro Subscriber""" APPLICATION_SUBSCRIPTION = 8 + """Entitlement was purchased as an app subscription"""