Skip to content

Commit

Permalink
refactor: "integration type" -> "install type"
Browse files Browse the repository at this point in the history
  • Loading branch information
shiftinv committed Dec 13, 2024
1 parent ae73577 commit 44cb10b
Show file tree
Hide file tree
Showing 17 changed files with 188 additions and 193 deletions.
12 changes: 6 additions & 6 deletions changelog/1173.feature.rst
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
Add support for user-installed commands. See :ref:`app_command_contexts` for further details.
- Add :attr:`ApplicationCommand.integration_types` and :attr:`ApplicationCommand.contexts` fields,
with respective :class:`ApplicationIntegrationTypes` and :class:`InteractionContextTypes` flag types.
- 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_integration_type_config` and :attr:`AppInfo.user_integration_type_config` fields.
- |commands| Add ``integration_types`` and ``contexts`` parameters to application command decorators.
- |commands| Add :func:`~ext.commands.integration_types` and :func:`~ext.commands.contexts` decorators.
- |commands| Using the :class:`GuildCommandInteraction` annotation now sets :attr:`~ApplicationCommand.integration_types` and :attr:`~ApplicationCommand.contexts`, instead of :attr:`~ApplicationCommand.dm_permission`.
- 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`.
100 changes: 50 additions & 50 deletions disnake/app_commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
try_enum,
try_enum_to_int,
)
from .flags import ApplicationIntegrationTypes, InteractionContextTypes
from .flags import ApplicationInstallTypes, InteractionContextTypes
from .i18n import Localized
from .permissions import Permissions
from .utils import MISSING, _get_as_snowflake, _maybe_cast, deprecated, warn_deprecated
Expand Down Expand Up @@ -492,9 +492,9 @@ class ApplicationCommand(ABC): # noqa: B024 # this will get refactored eventua
.. versionadded:: 2.8
integration_types: Optional[:class:`ApplicationIntegrationTypes`]
The integration types/installation contexts where the command is available.
Defaults to :attr:`ApplicationIntegrationTypes.guild` only.
install_types: Optional[:class:`ApplicationInstallTypes`]
The installation types where the command is available.
Defaults to :attr:`ApplicationInstallTypes.guild` only.
Only available for global commands.
.. versionadded:: 2.10
Expand All @@ -511,7 +511,7 @@ class ApplicationCommand(ABC): # noqa: B024 # this will get refactored eventua
"name",
"default_member_permissions",
"nsfw",
"integration_types",
"install_types",
"contexts",
)

Expand All @@ -522,7 +522,7 @@ def __init__(
dm_permission: Optional[bool] = None, # deprecated
default_member_permissions: Optional[Union[Permissions, int]] = None,
nsfw: Optional[bool] = None,
integration_types: Optional[ApplicationIntegrationTypes] = None,
install_types: Optional[ApplicationInstallTypes] = None,
contexts: Optional[InteractionContextTypes] = None,
) -> None:
self.type: ApplicationCommandType = enum_if_int(ApplicationCommandType, type)
Expand All @@ -544,7 +544,7 @@ def __init__(
self._default_member_permissions = default_member_permissions.value

# note: this defaults to `[0]` for syncing purposes only
self.integration_types: Optional[ApplicationIntegrationTypes] = integration_types
self.install_types: Optional[ApplicationInstallTypes] = install_types
self.contexts: Optional[InteractionContextTypes] = contexts

self._always_synced: bool = False
Expand Down Expand Up @@ -628,7 +628,7 @@ def __eq__(self, other) -> bool:
if not any(
(isinstance(obj, _APIApplicationCommandMixin) and obj.guild_id) for obj in (self, other)
):
if self._integration_types_with_default != other._integration_types_with_default:
if self._install_types_with_default != other._install_types_with_default:
return False

# `contexts` takes priority over `dm_permission`;
Expand All @@ -645,18 +645,18 @@ def __eq__(self, other) -> bool:
return True

@property
def _integration_types_with_default(self) -> Optional[ApplicationIntegrationTypes]:
def _install_types_with_default(self) -> Optional[ApplicationInstallTypes]:
# if this is an api-provided command object, keep things as-is
if self.integration_types is None and not isinstance(self, _APIApplicationCommandMixin):
if self.install_types is None and not isinstance(self, _APIApplicationCommandMixin):
# 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).
# Additionally, this provides consistency independent of the dev portal configuration,
# even if it might not be ideal.
# In an ideal world, we would make use of `application_info().integration_types_config`.
return ApplicationIntegrationTypes(guild=True)
# In an ideal world, we would make use of `application_info().install_types_config`.
return ApplicationInstallTypes(guild=True)

return self.integration_types
return self.install_types

def to_dict(self) -> EditApplicationCommandPayload:
data: EditApplicationCommandPayload = {
Expand All @@ -671,12 +671,12 @@ def to_dict(self) -> EditApplicationCommandPayload:
"nsfw": self.nsfw,
}

integration_types = (
self._integration_types_with_default.values
if self._integration_types_with_default is not None
install_types = (
self._install_types_with_default.values
if self._install_types_with_default is not None
else None
)
data["integration_types"] = integration_types
data["integration_types"] = install_types

contexts = self.contexts.values if self.contexts is not None else None
data["contexts"] = contexts
Expand Down Expand Up @@ -731,9 +731,9 @@ class UserCommand(ApplicationCommand):
.. versionadded:: 2.8
integration_types: Optional[:class:`ApplicationIntegrationTypes`]
The integration types/installation contexts where the command is available.
Defaults to :attr:`ApplicationIntegrationTypes.guild` only.
install_types: Optional[:class:`ApplicationInstallTypes`]
The installation types where the command is available.
Defaults to :attr:`ApplicationInstallTypes.guild` only.
Only available for global commands.
.. versionadded:: 2.10
Expand All @@ -753,7 +753,7 @@ def __init__(
dm_permission: Optional[bool] = None, # deprecated
default_member_permissions: Optional[Union[Permissions, int]] = None,
nsfw: Optional[bool] = None,
integration_types: Optional[ApplicationIntegrationTypes] = None,
install_types: Optional[ApplicationInstallTypes] = None,
contexts: Optional[InteractionContextTypes] = None,
) -> None:
super().__init__(
Expand All @@ -762,7 +762,7 @@ def __init__(
dm_permission=dm_permission,
default_member_permissions=default_member_permissions,
nsfw=nsfw,
integration_types=integration_types,
install_types=install_types,
contexts=contexts,
)

Expand All @@ -786,9 +786,9 @@ class APIUserCommand(UserCommand, _APIApplicationCommandMixin):
.. versionadded:: 2.8
integration_types: Optional[:class:`ApplicationIntegrationTypes`]
The integration types/installation contexts where the command is available.
Defaults to :attr:`ApplicationIntegrationTypes.guild` only.
install_types: Optional[:class:`ApplicationInstallTypes`]
The installation types where the command is available.
Defaults to :attr:`ApplicationInstallTypes.guild` only.
Only available for global commands.
.. versionadded:: 2.10
Expand Down Expand Up @@ -821,9 +821,9 @@ def from_dict(cls, data: ApplicationCommandPayload) -> Self:
name=Localized(data["name"], data=data.get("name_localizations")),
default_member_permissions=_get_as_snowflake(data, "default_member_permissions"),
nsfw=data.get("nsfw"),
integration_types=(
ApplicationIntegrationTypes._from_values(integration_types)
if (integration_types := data.get("integration_types")) is not None
install_types=(
ApplicationInstallTypes._from_values(install_types)
if (install_types := data.get("integration_types")) is not None
else None
),
contexts=(
Expand Down Expand Up @@ -854,9 +854,9 @@ class MessageCommand(ApplicationCommand):
.. versionadded:: 2.8
integration_types: Optional[:class:`ApplicationIntegrationTypes`]
The integration types/installation contexts where the command is available.
Defaults to :attr:`ApplicationIntegrationTypes.guild` only.
install_types: Optional[:class:`ApplicationInstallTypes`]
The installation types where the command is available.
Defaults to :attr:`ApplicationInstallTypes.guild` only.
Only available for global commands.
.. versionadded:: 2.10
Expand All @@ -876,7 +876,7 @@ def __init__(
dm_permission: Optional[bool] = None, # deprecated
default_member_permissions: Optional[Union[Permissions, int]] = None,
nsfw: Optional[bool] = None,
integration_types: Optional[ApplicationIntegrationTypes] = None,
install_types: Optional[ApplicationInstallTypes] = None,
contexts: Optional[InteractionContextTypes] = None,
) -> None:
super().__init__(
Expand All @@ -885,7 +885,7 @@ def __init__(
dm_permission=dm_permission,
default_member_permissions=default_member_permissions,
nsfw=nsfw,
integration_types=integration_types,
install_types=install_types,
contexts=contexts,
)

Expand All @@ -909,9 +909,9 @@ class APIMessageCommand(MessageCommand, _APIApplicationCommandMixin):
.. versionadded:: 2.8
integration_types: Optional[:class:`ApplicationIntegrationTypes`]
The integration types/installation contexts where the command is available.
Defaults to :attr:`ApplicationIntegrationTypes.guild` only.
install_types: Optional[:class:`ApplicationInstallTypes`]
The installation types where the command is available.
Defaults to :attr:`ApplicationInstallTypes.guild` only.
Only available for global commands.
.. versionadded:: 2.10
Expand Down Expand Up @@ -944,9 +944,9 @@ def from_dict(cls, data: ApplicationCommandPayload) -> Self:
name=Localized(data["name"], data=data.get("name_localizations")),
default_member_permissions=_get_as_snowflake(data, "default_member_permissions"),
nsfw=data.get("nsfw"),
integration_types=(
ApplicationIntegrationTypes._from_values(integration_types)
if (integration_types := data.get("integration_types")) is not None
install_types=(
ApplicationInstallTypes._from_values(install_types)
if (install_types := data.get("integration_types")) is not None
else None
),
contexts=(
Expand Down Expand Up @@ -984,9 +984,9 @@ class SlashCommand(ApplicationCommand):
.. versionadded:: 2.8
integration_types: Optional[:class:`ApplicationIntegrationTypes`]
The integration types/installation contexts where the command is available.
Defaults to :attr:`ApplicationIntegrationTypes.guild` only.
install_types: Optional[:class:`ApplicationInstallTypes`]
The installation types where the command is available.
Defaults to :attr:`ApplicationInstallTypes.guild` only.
Only available for global commands.
.. versionadded:: 2.10
Expand Down Expand Up @@ -1014,7 +1014,7 @@ def __init__(
dm_permission: Optional[bool] = None, # deprecated
default_member_permissions: Optional[Union[Permissions, int]] = None,
nsfw: Optional[bool] = None,
integration_types: Optional[ApplicationIntegrationTypes] = None,
install_types: Optional[ApplicationInstallTypes] = None,
contexts: Optional[InteractionContextTypes] = None,
) -> None:
super().__init__(
Expand All @@ -1023,7 +1023,7 @@ def __init__(
dm_permission=dm_permission,
default_member_permissions=default_member_permissions,
nsfw=nsfw,
integration_types=integration_types,
install_types=install_types,
contexts=contexts,
)
_validate_name(self.name)
Expand Down Expand Up @@ -1123,9 +1123,9 @@ class APISlashCommand(SlashCommand, _APIApplicationCommandMixin):
.. versionadded:: 2.8
integration_types: Optional[:class:`ApplicationIntegrationTypes`]
The integration types/installation contexts where the command is available.
Defaults to :attr:`ApplicationIntegrationTypes.guild` only.
install_types: Optional[:class:`ApplicationInstallTypes`]
The installation types where the command is available.
Defaults to :attr:`ApplicationInstallTypes.guild` only.
Only available for global commands.
.. versionadded:: 2.10
Expand Down Expand Up @@ -1164,9 +1164,9 @@ def from_dict(cls, data: ApplicationCommandPayload) -> Self:
),
default_member_permissions=_get_as_snowflake(data, "default_member_permissions"),
nsfw=data.get("nsfw"),
integration_types=(
ApplicationIntegrationTypes._from_values(integration_types)
if (integration_types := data.get("integration_types")) is not None
install_types=(
ApplicationInstallTypes._from_values(install_types)
if (install_types := data.get("integration_types")) is not None
else None
),
contexts=(
Expand Down
Loading

0 comments on commit 44cb10b

Please sign in to comment.