Skip to content

feat: update entitlements with new properties and functions #1692

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions interactions/api/http/http_requests/entitlements.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
)
10 changes: 10 additions & 0 deletions interactions/client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion interactions/models/discord/entitlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
15 changes: 15 additions & 0 deletions interactions/models/discord/enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Loading