Skip to content

Commit

Permalink
revert: remove sku/entitlement http methods, endpoints scheduled for …
Browse files Browse the repository at this point in the history
…removal
  • Loading branch information
shiftinv committed Oct 29, 2023
1 parent 2ba777e commit c80dbe2
Show file tree
Hide file tree
Showing 6 changed files with 7 additions and 356 deletions.
3 changes: 1 addition & 2 deletions changelog/1113.feature.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
Support application subscriptions (see the :ddocs:`official docs <monetization/overview>` for more info).
- New types: :class:`SKU`, :class:`Entitlement`
- New types: :class:`SKU`, :class:`Entitlement`.
- New :attr:`Interaction.entitlements` attribute, and :meth:`InteractionResponse.require_premium` response type.
- New events: :func:`on_entitlement_create`, :func:`on_entitlement_update`, :func:`on_entitlement_delete`.
- New :class:`Client` methods: :meth:`~Client.skus`, :meth:`~Client.entitlements`, :meth:`~Client.create_entitlement`.
136 changes: 2 additions & 134 deletions disnake/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@

import aiohttp

from . import abc, utils
from . import utils
from .activity import ActivityTypes, BaseActivity, create_activity
from .app_commands import (
APIMessageCommand,
Expand All @@ -46,7 +46,6 @@
from .backoff import ExponentialBackoff
from .channel import PartialMessageable, _threaded_channel_factory
from .emoji import Emoji
from .entitlement import Entitlement
from .enums import ApplicationCommandType, ChannelType, Event, Status
from .errors import (
ConnectionClosed,
Expand All @@ -63,10 +62,9 @@
from .http import HTTPClient
from .i18n import LocalizationProtocol, LocalizationStore
from .invite import Invite
from .iterators import EntitlementIterator, GuildIterator
from .iterators import GuildIterator
from .mentions import AllowedMentions
from .object import Object
from .sku import SKU
from .stage_instance import StageInstance
from .state import ConnectionState
from .sticker import GuildSticker, StandardSticker, StickerPack, _sticker_factory
Expand Down Expand Up @@ -2975,133 +2973,3 @@ async def edit_role_connection_metadata(
self.application_id, payload
)
return [ApplicationRoleConnectionMetadata._from_data(record) for record in data]

async def skus(self) -> List[SKU]:
"""|coro|
Retrieves the :class:`.SKU`\\s for the application.
To manage application subscription entitlements, you should use the SKU
with :attr:`.SKUType.subscription`.
.. versionadded:: 2.10
Raises
------
HTTPException
Retrieving the SKUs failed.
Returns
-------
List[:class:`.SKU`]
The list of SKUs.
"""
data = await self.http.get_skus(self.application_id)
return [SKU(data=d) for d in data]

def entitlements(
self,
*,
limit: Optional[int] = 100,
before: Optional[SnowflakeTime] = None,
after: Optional[SnowflakeTime] = None,
user: Optional[Snowflake] = None,
guild: Optional[Snowflake] = None,
skus: Optional[Sequence[Snowflake]] = None,
exclude_ended: bool = False,
oldest_first: bool = False,
) -> EntitlementIterator:
"""Retrieves an :class:`.AsyncIterator` that enables receiving entitlements for the application.
.. note::
This method is an API call. To get the entitlements of the invoking user/guild
in interactions, consider using :attr:`.Interaction.entitlements`.
Entries are returned in order from newest to oldest by default;
pass ``oldest_first=True`` to reverse the iteration order.
All parameters are optional.
.. versionadded:: 2.10
Parameters
----------
limit: Optional[:class:`int`]
The number of entitlements to retrieve.
If ``None``, retrieves every entitlement.
Note, however, that this would make it a slow operation.
Defaults to ``100``.
before: Union[:class:`.abc.Snowflake`, :class:`datetime.datetime`]
Retrieves entitlements created before this date or object.
If a datetime is provided, it is recommended to use a UTC aware datetime.
If the datetime is naive, it is assumed to be local time.
after: Union[:class:`.abc.Snowflake`, :class:`datetime.datetime`]
Retrieve entitlements created after this date or object.
If a datetime is provided, it is recommended to use a UTC aware datetime.
If the datetime is naive, it is assumed to be local time.
user: Optional[:class:`.abc.Snowflake`]
The user to retrieve entitlements for.
guild: Optional[:class:`.abc.Snowflake`]
The guild to retrieve entitlements for.
skus: Optional[Sequence[:class:`.abc.Snowflake`]]
The SKUs for which entitlements are retrieved.
exclude_ended: :class:`bool`
Whether to exclude ended/expired entitlements. Defaults to ``False``.
oldest_first: :class:`bool`
If set to ``True``, return entries in oldest->newest order. Defaults to ``False``.
Raises
------
HTTPException
Retrieving the entitlements failed.
Yields
------
:class:`.Entitlement`
The entitlements for the given parameters.
"""
return EntitlementIterator(
self.application_id,
state=self._connection,
limit=limit,
before=before,
after=after,
user_id=user.id if user is not None else None,
guild_id=guild.id if guild is not None else None,
sku_ids=[sku.id for sku in skus] if skus else None,
exclude_ended=exclude_ended,
oldest_first=oldest_first,
)

async def create_entitlement(
self, sku: Snowflake, owner: Union[abc.User, Guild]
) -> Entitlement:
"""|coro|
Creates a new test :class:`.Entitlement` for the given user or guild, with no expiry.
Parameters
----------
sku: :class:`.abc.Snowflake`
The :class:`.SKU` to grant the entitlement for.
owner: Union[:class:`.abc.User`, :class:`.Guild`]
The user or guild to grant the entitlement to.
Raises
------
HTTPException
Creating the entitlement failed.
Returns
-------
:class:`.Entitlement`
The newly created entitlement.
"""
data = await self.http.create_test_entitlement(
self.application_id,
sku_id=sku.id,
owner_id=owner.id,
owner_type=2 if isinstance(owner, abc.User) else 1,
)
return Entitlement(data=data, state=self._connection)
27 changes: 3 additions & 24 deletions disnake/entitlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@
class Entitlement(Hashable):
"""Represents an entitlement.
This is usually retrieved using :meth:`Client.entitlements`, from
:attr:`Interaction.entitlements` when using interactions, or provided by
events (e.g. :func:`on_entitlement_create`).
This is usually retrieved from :attr:`Interaction.entitlements` when using interactions,
or provided by events (e.g. :func:`on_entitlement_create`).
Note that some entitlements may have ended already; consider using
:meth:`is_active` to check whether a given entitlement is considered active at the current time,
or use ``exclude_ended=True`` when fetching entitlements using :meth:`Client.entitlements`.
You may create new entitlements for testing purposes using :meth:`Client.create_entitlement`.
:meth:`is_active` to check whether a given entitlement is considered active at the current time.
.. container:: operations
Expand Down Expand Up @@ -149,20 +145,3 @@ def is_active(self) -> bool:
return False

return True

async def delete(self) -> None:
"""|coro|
Deletes the entitlement.
This is only valid for test entitlements; you cannot use this to
delete entitlements that users purchased.
Raises
------
NotFound
The entitlement does not exist.
HTTPException
Deleting the entitlement failed.
"""
await self._state.http.delete_test_entitlement(self.application_id, self.id)
76 changes: 0 additions & 76 deletions disnake/http.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,6 @@
components,
embed,
emoji,
entitlement,
gateway,
guild,
guild_scheduled_event,
Expand All @@ -71,7 +70,6 @@
message,
onboarding,
role,
sku,
sticker,
template,
threads,
Expand Down Expand Up @@ -2276,80 +2274,6 @@ def delete_auto_moderation_rule(
def get_guild_onboarding(self, guild_id: Snowflake) -> Response[onboarding.Onboarding]:
return self.request(Route("GET", "/guilds/{guild_id}/onboarding", guild_id=guild_id))

# SKUs/Entitlements

def get_skus(self, application_id: Snowflake) -> Response[List[sku.SKU]]:
return self.request(
Route("GET", "/applications/{application_id}/skus", application_id=application_id)
)

def get_entitlements(
self,
application_id: Snowflake,
*,
# if both are specified, `after` takes priority and `before` gets ignored
before: Optional[Snowflake] = None,
after: Optional[Snowflake] = None,
limit: int = 100,
user_id: Optional[Snowflake] = None,
guild_id: Optional[Snowflake] = None,
sku_ids: Optional[SnowflakeList] = None,
exclude_ended: bool = False,
) -> Response[List[entitlement.Entitlement]]:
params: Dict[str, Any] = {
"limit": limit,
"exclude_ended": int(exclude_ended),
}
if before is not None:
params["before"] = before
if after is not None:
params["after"] = after
if user_id is not None:
params["user_id"] = user_id
if guild_id is not None:
params["guild_id"] = guild_id
if sku_ids:
params["sku_ids"] = ",".join(map(str, sku_ids))

r = Route(
"GET", "/applications/{application_id}/entitlements", application_id=application_id
)
return self.request(r, params=params)

def create_test_entitlement(
self,
application_id: Snowflake,
sku_id: Snowflake,
owner_id: Snowflake,
*,
owner_type: Literal[1, 2], # 1: guild, 2: user
) -> Response[entitlement.Entitlement]:
payload: Dict[str, Any] = {
"sku_id": sku_id,
"owner_id": owner_id,
"owner_type": owner_type,
}
return self.request(
Route(
"POST", "/applications/{application_id}/entitlements", application_id=application_id
),
json=payload,
)

def delete_test_entitlement(
self,
application_id: Snowflake,
entitlement_id: Snowflake,
) -> Response[None]:
return self.request(
Route(
"DELETE",
"/applications/{application_id}/entitlements/{entitlement_id}",
application_id=application_id,
entitlement_id=entitlement_id,
)
)

# Application commands (global)

def get_global_commands(
Expand Down
Loading

0 comments on commit c80dbe2

Please sign in to comment.