Skip to content

Commit

Permalink
Merge branch 'master' into feat/py313
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftinv authored Dec 29, 2024
2 parents d3eeb67 + 18535bb commit 7a2fd31
Show file tree
Hide file tree
Showing 74 changed files with 1,915 additions and 1,822 deletions.
4 changes: 2 additions & 2 deletions changelog/1113.feature.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Support application subscriptions and one-time purchases (see the :ddocs:`official docs <monetization/overview>` for more info).
- New types: :class:`SKU`, :class:`Entitlement`.
- New types: :class:`SKU`, :class:`Entitlement`, :class:`Subscription`.
- 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 events: :func:`on_entitlement_create`, :func:`on_entitlement_update`, :func:`on_entitlement_delete`, :func:`on_subscription_create`, :func:`on_subscription_update` and :func:`on_subscription_delete`.
- New :class:`Client` methods: :meth:`~Client.skus`, :meth:`~Client.entitlements`, :meth:`~Client.fetch_entitlement`, :meth:`~Client.create_entitlement`.
1 change: 1 addition & 0 deletions changelog/1173.feature.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,4 @@ Add support for user-installed commands. See :ref:`app_command_contexts` for fur
- |commands| Add ``install_types`` and ``contexts`` parameters to application command decorators.
- |commands| Add :func:`~ext.commands.install_types` and :func:`~ext.commands.contexts` decorators.
- |commands| Using the :class:`GuildCommandInteraction` annotation now sets :attr:`~ApplicationCommand.install_types` and :attr:`~ApplicationCommand.contexts`, instead of :attr:`~ApplicationCommand.dm_permission`.
- |commands| Add ``default_install_types`` and ``default_contexts`` parameters to :class:`~ext.commands.Bot`.
4 changes: 2 additions & 2 deletions changelog/1186.feature.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Support application subscriptions and one-time purchases (see the :ddocs:`official docs <monetization/overview>` for more info).
- New types: :class:`SKU`, :class:`Entitlement`.
- New types: :class:`SKU`, :class:`Entitlement`, :class:`Subscription`.
- 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 events: :func:`on_entitlement_create`, :func:`on_entitlement_update`, :func:`on_entitlement_delete`, :func:`on_subscription_create`, :func:`on_subscription_update` and :func:`on_subscription_delete`.
- New :class:`Client` methods: :meth:`~Client.skus`, :meth:`~Client.entitlements`, :meth:`~Client.fetch_entitlement`, :meth:`~Client.create_entitlement`.
1 change: 1 addition & 0 deletions changelog/1190.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
The ``cls`` parameter of UI component decorators (such as :func:`ui.button`) now accepts any matching callable, in addition to item subclasses.
1 change: 1 addition & 0 deletions changelog/1243.misc.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Move enum member documentation into docstrings.
4 changes: 2 additions & 2 deletions changelog/1249.feature.rst
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Support application subscriptions and one-time purchases (see the :ddocs:`official docs <monetization/overview>` for more info).
- New types: :class:`SKU`, :class:`Entitlement`.
- New types: :class:`SKU`, :class:`Entitlement`, :class:`Subscription`.
- 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 events: :func:`on_entitlement_create`, :func:`on_entitlement_update`, :func:`on_entitlement_delete`, :func:`on_subscription_create`, :func:`on_subscription_update` and :func:`on_subscription_delete`.
- New :class:`Client` methods: :meth:`~Client.skus`, :meth:`~Client.entitlements`, :meth:`~Client.fetch_entitlement`, :meth:`~Client.create_entitlement`.
5 changes: 5 additions & 0 deletions changelog/1257.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Support application subscriptions and one-time purchases (see the :ddocs:`official docs <monetization/overview>` for more info).
- New types: :class:`SKU`, :class:`Entitlement`, :class:`Subscription`.
- 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`, :func:`on_subscription_create`, :func:`on_subscription_update` and :func:`on_subscription_delete`.
- New :class:`Client` methods: :meth:`~Client.skus`, :meth:`~Client.entitlements`, :meth:`~Client.fetch_entitlement`, :meth:`~Client.create_entitlement`.
14 changes: 14 additions & 0 deletions changelog/1261.feature.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Add support for user-installed commands. See :ref:`app_command_contexts` for further details.
- Add :attr:`ApplicationCommand.install_types` and :attr:`ApplicationCommand.contexts` fields,
with respective :class:`ApplicationInstallTypes` and :class:`InteractionContextTypes` flag types.
- :class:`Interaction` changes:
- Add :attr:`Interaction.context` field, reflecting the context in which the interaction occurred.
- Add :attr:`Interaction.authorizing_integration_owners` field and :class:`AuthorizingIntegrationOwners` class, containing details about the application installation.
- :attr:`Interaction.app_permissions` is now always provided by Discord.
- Add :attr:`Message.interaction_metadata` and :class:`InteractionMetadata` type, containing metadata for the interaction associated with a message.
- Add ``integration_type`` parameter to :func:`utils.oauth_url`.
- Add :attr:`AppInfo.guild_install_type_config` and :attr:`AppInfo.user_install_type_config` fields.
- |commands| Add ``install_types`` and ``contexts`` parameters to application command decorators.
- |commands| Add :func:`~ext.commands.install_types` and :func:`~ext.commands.contexts` decorators.
- |commands| Using the :class:`GuildCommandInteraction` annotation now sets :attr:`~ApplicationCommand.install_types` and :attr:`~ApplicationCommand.contexts`, instead of :attr:`~ApplicationCommand.dm_permission`.
- |commands| Add ``default_install_types`` and ``default_contexts`` parameters to :class:`~ext.commands.Bot`.
1 change: 1 addition & 0 deletions changelog/1264.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Escape forward slashes in HTTP route parameters.
1 change: 1 addition & 0 deletions changelog/914.bugfix.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix :class:`ui.Modal` timeout issues with long-running callbacks, and multiple modals with the same user and ``custom_id``.
1 change: 1 addition & 0 deletions disnake/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
from .soundboard import *
from .stage_instance import *
from .sticker import *
from .subscription import *
from .team import *
from .template import *
from .threads import *
Expand Down
37 changes: 34 additions & 3 deletions disnake/app_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -547,6 +547,13 @@ def __init__(
self.install_types: Optional[ApplicationInstallTypes] = install_types
self.contexts: Optional[InteractionContextTypes] = contexts

# TODO(3.0): refactor
# These are for ext.commands defaults. It's quite ugly to do it this way,
# but since __eq__ and to_dict functionality is encapsulated here and can't be moved trivially,
# it'll do until the presumably soon-ish refactor of the entire commands framework.
self._default_install_types: Optional[ApplicationInstallTypes] = None
self._default_contexts: Optional[InteractionContextTypes] = None

self._always_synced: bool = False

# reset `default_permission` if set before
Expand Down Expand Up @@ -614,6 +621,9 @@ def __str__(self) -> str:
return self.name

def __eq__(self, other) -> bool:
if not isinstance(other, ApplicationCommand):
return False

if not (
self.type == other.type
and self.name == other.name
Expand All @@ -634,8 +644,10 @@ def __eq__(self, other) -> bool:
# `contexts` takes priority over `dm_permission`;
# ignore `dm_permission` if `contexts` is set,
# since the API returns both even when only `contexts` was provided
if self.contexts is not None or other.contexts is not None:
if self.contexts != other.contexts:
self_contexts = self._contexts_with_default
other_contexts = other._contexts_with_default
if self_contexts is not None or other_contexts is not None:
if self_contexts != other_contexts:
return False
else:
# this is a bit awkward; `None` is equivalent to `True` in this case
Expand All @@ -648,6 +660,9 @@ def __eq__(self, other) -> bool:
def _install_types_with_default(self) -> Optional[ApplicationInstallTypes]:
# if this is an api-provided command object, keep things as-is
if self.install_types is None and not isinstance(self, _APIApplicationCommandMixin):
if self._default_install_types is not None:
return self._default_install_types

# The purpose of this default is to avoid re-syncing after the updating to the new version,
# at least as long as the user hasn't enabled user installs in the dev portal
# (i.e. if they haven't, the api defaults to this value as well).
Expand All @@ -658,6 +673,20 @@ def _install_types_with_default(self) -> Optional[ApplicationInstallTypes]:

return self.install_types

@property
def _contexts_with_default(self) -> Optional[InteractionContextTypes]:
# (basically the same logic as `_install_types_with_default`, but without a fallback)
if (
self.contexts is None
and not isinstance(self, _APIApplicationCommandMixin)
and self._default_contexts is not None
# only use default if legacy `dm_permission` wasn't set
and self._dm_permission is None
):
return self._default_contexts

return self.contexts

def to_dict(self) -> EditApplicationCommandPayload:
data: EditApplicationCommandPayload = {
"type": try_enum_to_int(self.type),
Expand All @@ -678,7 +707,9 @@ def to_dict(self) -> EditApplicationCommandPayload:
)
data["integration_types"] = install_types

contexts = self.contexts.values if self.contexts is not None else None
contexts = (
self._contexts_with_default.values if self._contexts_with_default is not None else None
)
data["contexts"] = contexts

# don't set `dm_permission` if `contexts` is set
Expand Down
2 changes: 1 addition & 1 deletion disnake/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -3180,7 +3180,7 @@ async def skus(self) -> List[SKU]:
The list of SKUs.
"""
data = await self.http.get_skus(self.application_id)
return [SKU(data=d) for d in data]
return [SKU(data=d, state=self._connection) for d in data]

def entitlements(
self,
Expand Down
1 change: 0 additions & 1 deletion disnake/entitlement.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ class Entitlement(Hashable):
Set to ``None`` when this is a test entitlement.
ends_at: Optional[:class:`datetime.datetime`]
The time at which the entitlement stops being active.
Set to ``None`` when this is a test entitlement.
You can use :meth:`is_active` to check whether this entitlement is still active.
"""
Expand Down
Loading

0 comments on commit 7a2fd31

Please sign in to comment.