|
| 1 | +from typing import TYPE_CHECKING, Optional |
| 2 | + |
| 3 | +from ..route import Route, PAYLOAD_TYPE |
| 4 | +from interactions.models.internal.protocols import CanRequest |
| 5 | +from interactions.models.discord.snowflake import to_optional_snowflake, to_snowflake |
| 6 | +from interactions.client.utils.serializer import dict_filter_none |
| 7 | + |
| 8 | +if TYPE_CHECKING: |
| 9 | + from interactions.models.discord.snowflake import Snowflake_Type |
| 10 | + |
| 11 | +__all__ = ("EntitlementRequests",) |
| 12 | + |
| 13 | + |
| 14 | +class EntitlementRequests(CanRequest): |
| 15 | + async def get_entitlements( |
| 16 | + self, |
| 17 | + application_id: "Snowflake_Type", |
| 18 | + *, |
| 19 | + user_id: "Optional[Snowflake_Type]" = None, |
| 20 | + sku_ids: "Optional[list[Snowflake_Type]]" = None, |
| 21 | + before: "Optional[Snowflake_Type]" = None, |
| 22 | + after: "Optional[Snowflake_Type]" = None, |
| 23 | + limit: Optional[int] = 100, |
| 24 | + guild_id: "Optional[Snowflake_Type]" = None, |
| 25 | + exclude_ended: Optional[bool] = None, |
| 26 | + ) -> list[dict]: |
| 27 | + """ |
| 28 | + Get an application's entitlements. |
| 29 | +
|
| 30 | + Args: |
| 31 | + application_id: The ID of the application. |
| 32 | + user_id: The ID of the user to filter entitlements by. |
| 33 | + sku_ids: The IDs of the SKUs to filter entitlements by. |
| 34 | + before: Get entitlements before this ID. |
| 35 | + after: Get entitlements after this ID. |
| 36 | + limit: The maximum number of entitlements to return. Maximum is 100. |
| 37 | + guild_id: The ID of the guild to filter entitlements by. |
| 38 | + exclude_ended: Whether to exclude ended entitlements. |
| 39 | +
|
| 40 | + Returns: |
| 41 | + A dictionary containing the application's entitlements. |
| 42 | + """ |
| 43 | + params: PAYLOAD_TYPE = { |
| 44 | + "user_id": to_optional_snowflake(user_id), |
| 45 | + "sku_ids": [to_snowflake(sku_id) for sku_id in sku_ids] if sku_ids else None, |
| 46 | + "before": to_optional_snowflake(before), |
| 47 | + "after": to_optional_snowflake(after), |
| 48 | + "limit": limit, |
| 49 | + "guild_id": to_optional_snowflake(guild_id), |
| 50 | + "exclude_ended": exclude_ended, |
| 51 | + } |
| 52 | + params = dict_filter_none(params) |
| 53 | + |
| 54 | + return await self.request( |
| 55 | + Route("GET", "/applications/{application_id}/entitlements", application_id=application_id), params=params |
| 56 | + ) |
| 57 | + |
| 58 | + async def create_test_entitlement(self, payload: dict, application_id: "Snowflake_Type") -> dict: |
| 59 | + """ |
| 60 | + Create a test entitlement for an application. |
| 61 | +
|
| 62 | + Args: |
| 63 | + payload: The entitlement's data. |
| 64 | + application_id: The ID of the application. |
| 65 | +
|
| 66 | + Returns: |
| 67 | + A dictionary containing the test entitlement. |
| 68 | + """ |
| 69 | + return await self.request( |
| 70 | + Route("POST", "/applications/{application_id}/entitlements", application_id=application_id), payload=payload |
| 71 | + ) |
| 72 | + |
| 73 | + async def delete_test_entitlement(self, application_id: "Snowflake_Type", entitlement_id: "Snowflake_Type") -> None: |
| 74 | + """ |
| 75 | + Delete a test entitlement for an application. |
| 76 | +
|
| 77 | + Args: |
| 78 | + application_id: The ID of the application. |
| 79 | + entitlement_id: The ID of the entitlement. |
| 80 | + """ |
| 81 | + await self.request( |
| 82 | + Route( |
| 83 | + "DELETE", |
| 84 | + "/applications/{application_id}/entitlements/{entitlement_id}", |
| 85 | + application_id=application_id, |
| 86 | + entitlement_id=entitlement_id, |
| 87 | + ) |
| 88 | + ) |
0 commit comments