Skip to content

Commit

Permalink
Rename AppIntegrationType and related things to AppInstallationType
Browse files Browse the repository at this point in the history
  • Loading branch information
Rapptz committed Mar 22, 2024
1 parent 8e2d7fa commit 9e9f7ed
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 50 deletions.
78 changes: 39 additions & 39 deletions discord/app_commands/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
from copy import copy as shallow_copy

from ..enums import AppCommandOptionType, AppCommandType, ChannelType, Locale
from ..flags import AppCommandContext, AppIntegrationType
from ..flags import AppCommandContext, AppInstallationType
from .models import Choice
from .transformers import annotation_to_parameter, CommandParameter, NoneType
from .errors import AppCommandError, CheckFailure, CommandInvokeError, CommandSignatureMismatch, CommandAlreadyRegistered
Expand Down Expand Up @@ -93,7 +93,7 @@
'allow_contexts',
'guild_install',
'user_install',
'install_types',
'allow_installs',
'default_permissions',
)

Expand Down Expand Up @@ -630,7 +630,7 @@ class Command(Generic[GroupT, P, T]):
Overrides ``guild_only`` if this is set.
.. versionadded:: 2.4
integration_types: Optional[:class:`~discord.AppIntegrationType`]
allowed_installs: Optional[:class:`~discord.AppInstallationType`]
The installation contexts that the command is allowed to be installed
on.
Expand All @@ -656,7 +656,7 @@ def __init__(
parent: Optional[Group] = None,
guild_ids: Optional[List[int]] = None,
allowed_contexts: Optional[AppCommandContext] = None,
integration_types: Optional[AppIntegrationType] = None,
allowed_installs: Optional[AppInstallationType] = None,
auto_locale_strings: bool = True,
extras: Dict[Any, Any] = MISSING,
):
Expand Down Expand Up @@ -694,8 +694,8 @@ def __init__(
self.allowed_contexts: Optional[AppCommandContext] = allowed_contexts or getattr(
callback, '__discord_app_commands_contexts__', None
)
self.integration_types: Optional[AppIntegrationType] = integration_types or getattr(
callback, '__discord_app_commands_integration_types__', None
self.allowed_installs: Optional[AppInstallationType] = allowed_installs or getattr(
callback, '__discord_app_commands_installation_types__', None
)

self.nsfw: bool = nsfw
Expand Down Expand Up @@ -787,7 +787,7 @@ def to_dict(self) -> Dict[str, Any]:
base['dm_permission'] = not self.guild_only
base['default_member_permissions'] = None if self.default_permissions is None else self.default_permissions.value
base['contexts'] = self.allowed_contexts.to_array() if self.allowed_contexts is not None else None
base['integration_types'] = self.integration_types.to_array() if self.integration_types is not None else None
base['integration_types'] = self.allowed_installs.to_array() if self.allowed_installs is not None else None

return base

Expand Down Expand Up @@ -1200,7 +1200,7 @@ class ContextMenu:
Overrides ``guild_only`` if set.
.. versionadded:: 2.4
integration_types: Optional[:class:`~discord.AppIntegrationType`]
allowed_installs: Optional[:class:`~discord.AppInstallationType`]
The installation contexts that the command is allowed to be installed
on.
Expand Down Expand Up @@ -1228,7 +1228,7 @@ def __init__(
nsfw: bool = False,
guild_ids: Optional[List[int]] = None,
allowed_contexts: Optional[AppCommandContext] = None,
integration_types: Optional[AppIntegrationType] = None,
allowed_installs: Optional[AppInstallationType] = None,
auto_locale_strings: bool = True,
extras: Dict[Any, Any] = MISSING,
):
Expand Down Expand Up @@ -1257,8 +1257,8 @@ def __init__(
self.allowed_contexts: Optional[AppCommandContext] = allowed_contexts or getattr(
callback, '__discord_app_commands_contexts__', None
)
self.integration_types: Optional[AppIntegrationType] = integration_types or getattr(
callback, '__discord_app_commands_integration_types__', None
self.allowed_installs: Optional[AppInstallationType] = allowed_installs or getattr(
callback, '__discord_app_commands_installation_types__', None
)
self.checks: List[Check] = getattr(callback, '__discord_app_commands_checks__', [])
self.extras: Dict[Any, Any] = extras or {}
Expand Down Expand Up @@ -1296,7 +1296,7 @@ def to_dict(self) -> Dict[str, Any]:
'type': self.type.value,
'dm_permission': not self.guild_only,
'contexts': self.allowed_contexts.to_array() if self.allowed_contexts is not None else None,
'integration_types': self.integration_types.to_array() if self.integration_types is not None else None,
'integration_types': self.allowed_installs.to_array() if self.allowed_installs is not None else None,
'default_member_permissions': None if self.default_permissions is None else self.default_permissions.value,
'nsfw': self.nsfw,
}
Expand Down Expand Up @@ -1458,7 +1458,7 @@ class shortened to 100 characters.
guild_only if set.
.. versionadded:: 2.4
integration_types: Optional[:class:`~discord.AppIntegrationType`]
allowed_installs: Optional[:class:`~discord.AppInstallationType`]
The installation contexts that the command is allowed to be installed
on.
Expand All @@ -1483,7 +1483,7 @@ class shortened to 100 characters.
__discord_app_commands_group_nsfw__: bool = False
__discord_app_commands_guild_only__: bool = MISSING
__discord_app_commands_contexts__: Optional[AppCommandContext] = MISSING
__discord_app_commands_integration_types__: Optional[AppIntegrationType] = MISSING
__discord_app_commands_installation_types__: Optional[AppInstallationType] = MISSING
__discord_app_commands_default_permissions__: Optional[Permissions] = MISSING
__discord_app_commands_has_module__: bool = False
__discord_app_commands_error_handler__: Optional[
Expand Down Expand Up @@ -1553,7 +1553,7 @@ def __init__(
guild_ids: Optional[List[int]] = None,
guild_only: bool = MISSING,
allowed_contexts: Optional[AppCommandContext] = MISSING,
integration_types: Optional[AppIntegrationType] = MISSING,
allowed_installs: Optional[AppInstallationType] = MISSING,
nsfw: bool = MISSING,
auto_locale_strings: bool = True,
default_permissions: Optional[Permissions] = MISSING,
Expand Down Expand Up @@ -1610,13 +1610,13 @@ def __init__(

self.allowed_contexts: Optional[AppCommandContext] = allowed_contexts

if integration_types is MISSING:
if cls.__discord_app_commands_integration_types__ is MISSING:
integration_types = None
if allowed_installs is MISSING:
if cls.__discord_app_commands_installation_types__ is MISSING:
allowed_installs = None
else:
integration_types = cls.__discord_app_commands_integration_types__
allowed_installs = cls.__discord_app_commands_installation_types__

self.integration_types: Optional[AppIntegrationType] = integration_types
self.allowed_installs: Optional[AppInstallationType] = allowed_installs

if nsfw is MISSING:
nsfw = cls.__discord_app_commands_group_nsfw__
Expand Down Expand Up @@ -1751,7 +1751,7 @@ def to_dict(self) -> Dict[str, Any]:
base['dm_permission'] = not self.guild_only
base['default_member_permissions'] = None if self.default_permissions is None else self.default_permissions.value
base['contexts'] = self.allowed_contexts.to_array() if self.allowed_contexts is not None else None
base['integration_types'] = self.integration_types.to_array() if self.integration_types is not None else None
base['integration_types'] = self.allowed_installs.to_array() if self.allowed_installs is not None else None

return base

Expand Down Expand Up @@ -2668,13 +2668,13 @@ async def my_guild_install_command(interaction: discord.Interaction) -> None:

def inner(f: T) -> T:
if isinstance(f, (Command, Group, ContextMenu)):
integration_types = f.integration_types or AppIntegrationType.none()
f.integration_types = integration_types
allowed_installs = f.allowed_installs or AppInstallationType.none()
f.allowed_installs = allowed_installs
else:
integration_types = getattr(f, '__discord_app_commands_integration_types__', None) or AppIntegrationType.none()
f.__discord_app_commands_integration_types__ = integration_types # type: ignore # Runtime attribute assignment
allowed_installs = getattr(f, '__discord_app_commands_installation_types__', None) or AppInstallationType.none()
f.__discord_app_commands_installation_types__ = allowed_installs # type: ignore # Runtime attribute assignment

integration_types.guild_install = True
allowed_installs.guild = True

return f

Expand Down Expand Up @@ -2706,13 +2706,13 @@ async def my_user_install_command(interaction: discord.Interaction) -> None:

def inner(f: T) -> T:
if isinstance(f, (Command, Group, ContextMenu)):
integration_types = f.integration_types or AppIntegrationType.none()
f.integration_types = integration_types
allowed_installs = f.allowed_installs or AppInstallationType.none()
f.allowed_installs = allowed_installs
else:
integration_types = getattr(f, '__discord_app_commands_integration_types__', None) or AppIntegrationType.none()
f.__discord_app_commands_integration_types__ = integration_types # type: ignore # Runtime attribute assignment
allowed_installs = getattr(f, '__discord_app_commands_installation_types__', None) or AppInstallationType.none()
f.__discord_app_commands_installation_types__ = allowed_installs # type: ignore # Runtime attribute assignment

integration_types.user_install = True
allowed_installs.user = True

return f

Expand All @@ -2724,7 +2724,7 @@ def inner(f: T) -> T:
return inner(func)


def install_types(
def allow_installs(
guilds: bool = MISSING,
users: bool = MISSING,
) -> Union[T, Callable[[T], T]]:
Expand All @@ -2741,24 +2741,24 @@ def install_types(
.. code-block:: python3
@app_commands.command()
@app_commands.install_types(guilds=False, users=True)
@app_commands.allow_installs(guilds=False, users=True)
async def my_command(interaction: discord.Interaction) -> None:
await interaction.response.send_message('I am installed in users by default!')
"""

def inner(f: T) -> T:
if isinstance(f, (Command, Group, ContextMenu)):
integration_types = f.integration_types or AppIntegrationType.none()
f.integration_types = integration_types
allowed_installs = f.allowed_installs or AppInstallationType.none()
f.allowed_installs = allowed_installs
else:
integration_types = getattr(f, '__discord_app_commands_integration_types__', None) or AppIntegrationType.none()
f.__discord_app_commands_integration_types__ = integration_types # type: ignore # Runtime attribute assignment
allowed_installs = getattr(f, '__discord_app_commands_installation_types__', None) or AppInstallationType.none()
f.__discord_app_commands_installation_types__ = allowed_installs # type: ignore # Runtime attribute assignment

if guilds is not MISSING:
integration_types.guild_install = guilds
allowed_installs.guild = guilds

if users is not MISSING:
integration_types.user_install = users
allowed_installs.user = users

return f

Expand Down
2 changes: 1 addition & 1 deletion discord/ext/commands/cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ def __new__(cls, *args: Any, **kwargs: Any) -> Self:
guild_ids=getattr(cls, '__discord_app_commands_default_guilds__', None),
guild_only=getattr(cls, '__discord_app_commands_guild_only__', False),
allowed_contexts=getattr(cls, '__discord_app_commands_contexts__', None),
integration_types=getattr(cls, '__discord_app_commands_integration_types__', None),
allowed_installs=getattr(cls, '__discord_app_commands_installation_types__', None),
default_permissions=getattr(cls, '__discord_app_commands_default_permissions__', None),
extras=cls.__cog_group_extras__,
)
Expand Down
20 changes: 10 additions & 10 deletions discord/flags.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
'AppCommandContext',
'AttachmentFlags',
'RoleFlags',
'AppIntegrationType',
'AppInstallationType',
'SKUFlags',
)

Expand Down Expand Up @@ -1839,7 +1839,7 @@ def private_channel(self):


@fill_with_flags()
class AppIntegrationType(ArrayFlags):
class AppInstallationType(ArrayFlags):
r"""Represents the installation location of an application command.
.. versionadded:: 2.4
Expand All @@ -1848,30 +1848,30 @@ class AppIntegrationType(ArrayFlags):
.. describe:: x == y
Checks if two AppIntegrationType flags are equal.
Checks if two AppInstallationType flags are equal.
.. describe:: x != y
Checks if two AppIntegrationType flags are not equal.
Checks if two AppInstallationType flags are not equal.
.. describe:: x | y, x |= y
Returns an AppIntegrationType instance with all enabled flags from
Returns an AppInstallationType instance with all enabled flags from
both x and y.
.. describe:: x & y, x &= y
Returns an AppIntegrationType instance with only flags enabled on
Returns an AppInstallationType instance with only flags enabled on
both x and y.
.. describe:: x ^ y, x ^= y
Returns an AppIntegrationType instance with only flags enabled on
Returns an AppInstallationType instance with only flags enabled on
only one of x or y, not on both.
.. describe:: ~x
Returns an AppIntegrationType instance with all flags inverted from x
Returns an AppInstallationType instance with all flags inverted from x
.. describe:: hash(x)
Expand All @@ -1894,12 +1894,12 @@ class AppIntegrationType(ArrayFlags):
"""

@flag_value
def guild_install(self):
def guild(self):
""":class:`bool`: Whether the integration is a guild install."""
return 1 << 0

@flag_value
def user_install(self):
def user(self):
""":class:`bool`: Whether the integration is a user install."""
return 1 << 1

Expand Down

0 comments on commit 9e9f7ed

Please sign in to comment.