Skip to content

Commit 8aea2c7

Browse files
authored
feat: update entitlements with new properties and functions (#1692)
1 parent 457ac02 commit 8aea2c7

File tree

4 files changed

+46
-1
lines changed

4 files changed

+46
-1
lines changed

interactions/api/http/http_requests/entitlements.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,3 +89,21 @@ async def delete_test_entitlement(self, application_id: "Snowflake_Type", entitl
8989
entitlement_id=entitlement_id,
9090
)
9191
)
92+
93+
async def consume_entitlement(self, application_id: "Snowflake_Type", entitlement_id: "Snowflake_Type") -> None:
94+
"""
95+
For One-Time Purchase consumable SKUs, marks a given entitlement for the user as consumed.
96+
97+
Args:
98+
application_id: The ID of the application.
99+
entitlement_id: The ID of the entitlement.
100+
101+
"""
102+
await self.request(
103+
Route(
104+
"POST",
105+
"/applications/{application_id}/entitlements/{entitlement_id}/consume",
106+
application_id=application_id,
107+
entitlement_id=entitlement_id,
108+
)
109+
)

interactions/client/client.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2572,6 +2572,16 @@ async def delete_test_entitlement(self, entitlement_id: "Snowflake_Type") -> Non
25722572
"""
25732573
await self.http.delete_test_entitlement(self.app.id, to_snowflake(entitlement_id))
25742574

2575+
async def consume_entitlement(self, entitlement_id: "Snowflake_Type") -> None:
2576+
"""
2577+
For One-Time Purchase consumable SKUs, marks a given entitlement for the user as consumed.
2578+
2579+
Args:
2580+
entitlement_id: The ID of the entitlement to consume.
2581+
2582+
"""
2583+
await self.http.consume_entitlement(self.app.id, entitlement_id)
2584+
25752585
def mention_command(self, name: str, scope: int = 0) -> str:
25762586
"""
25772587
Returns a string that would mention the interaction specified.

interactions/models/discord/entitlement.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,10 @@ class Entitlement(DiscordObject):
2424
"""ID of the parent application."""
2525
type: EntitlementType = attrs.field(repr=False, converter=EntitlementType)
2626
"""The type of entitlement."""
27-
deleted: bool = attrs.field(repr=False, converter=bool)
27+
deleted: bool = attrs.field(repr=False)
2828
"""Whether the entitlement is deleted."""
29+
consumed: bool = attrs.field(repr=False, default=False)
30+
"""For consumable items, whether or not the entitlement has been consumed"""
2931
subscription_id: Optional[Snowflake_Type] = attrs.field(repr=False, converter=to_optional_snowflake, default=None)
3032
"""The ID of the subscription plan. Not present when using test entitlements."""
3133
starts_at: Optional[Timestamp] = attrs.field(repr=False, converter=optional_c(timestamp_converter), default=None)

interactions/models/discord/enums.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1101,4 +1101,19 @@ def converter(cls, value: Optional[int]) -> "ForumSortOrder":
11011101
class EntitlementType(CursedIntEnum):
11021102
"""The type of entitlement."""
11031103

1104+
PURCHASE = 1
1105+
"""Entitlement was purchased by user"""
1106+
PREMIUM_SUBSCRIPTION = 2
1107+
"""Entitlement for Discord Nitro subscription"""
1108+
DEVELOPER_GIFT = 3
1109+
"""Entitlement was gifted by developer"""
1110+
TEST_MODE_PURCHASE = 4
1111+
"""Entitlement was purchased by a dev in application test mode"""
1112+
FREE_PURCHASE = 5
1113+
"""Entitlement was granted when the SKU was free"""
1114+
USER_GIFT = 6
1115+
"""Entitlement was gifted by another user"""
1116+
PREMIUM_PURCHASE = 7
1117+
"""Entitlement was claimed by user for free as a Nitro Subscriber"""
11041118
APPLICATION_SUBSCRIPTION = 8
1119+
"""Entitlement was purchased as an app subscription"""

0 commit comments

Comments
 (0)