Browse Source

Make Application enums consistent (AppCommandType -> ApplicationCommandType)

pull/10109/head
dolfies 2 years ago
parent
commit
5efdd767f6
  1. 14
      discord/abc.py
  2. 84
      discord/commands.py
  3. 12
      discord/enums.py
  4. 4
      discord/message.py
  5. 4
      discord/types/integration.py
  6. 4
      docs/api.rst

14
discord/abc.py

@ -48,7 +48,7 @@ from typing import (
from .object import OLDEST_OBJECT, Object from .object import OLDEST_OBJECT, Object
from .context_managers import Typing from .context_managers import Typing
from .enums import AppCommandType, ChannelType from .enums import ApplicationCommandType, ChannelType
from .errors import ClientException from .errors import ClientException
from .mentions import AllowedMentions from .mentions import AllowedMentions
from .permissions import PermissionOverwrite, Permissions from .permissions import PermissionOverwrite, Permissions
@ -163,7 +163,7 @@ async def _purge_helper(
@overload @overload
def _handle_commands( def _handle_commands(
messageable: Messageable, messageable: Messageable,
type: Literal[AppCommandType.chat_input], type: Literal[ApplicationCommandType.chat_input],
*, *,
query: Optional[str] = ..., query: Optional[str] = ...,
limit: Optional[int] = ..., limit: Optional[int] = ...,
@ -178,7 +178,7 @@ def _handle_commands(
@overload @overload
def _handle_commands( def _handle_commands(
messageable: Messageable, messageable: Messageable,
type: Literal[AppCommandType.user], type: Literal[ApplicationCommandType.user],
*, *,
query: Optional[str] = ..., query: Optional[str] = ...,
limit: Optional[int] = ..., limit: Optional[int] = ...,
@ -193,7 +193,7 @@ def _handle_commands(
@overload @overload
def _handle_commands( def _handle_commands(
messageable: Message, messageable: Message,
type: Literal[AppCommandType.message], type: Literal[ApplicationCommandType.message],
*, *,
query: Optional[str] = ..., query: Optional[str] = ...,
limit: Optional[int] = ..., limit: Optional[int] = ...,
@ -207,7 +207,7 @@ def _handle_commands(
async def _handle_commands( async def _handle_commands(
messageable: Union[Messageable, Message], messageable: Union[Messageable, Message],
type: AppCommandType, type: ApplicationCommandType,
*, *,
query: Optional[str] = None, query: Optional[str] = None,
limit: Optional[int] = None, limit: Optional[int] = None,
@ -2424,7 +2424,7 @@ class Messageable:
""" """
return _handle_commands( return _handle_commands(
self, self,
AppCommandType.chat_input, ApplicationCommandType.chat_input,
query=query, query=query,
limit=limit, limit=limit,
command_ids=command_ids, command_ids=command_ids,
@ -2500,7 +2500,7 @@ class Messageable:
""" """
return _handle_commands( return _handle_commands(
self, self,
AppCommandType.user, ApplicationCommandType.user,
query=query, query=query,
limit=limit, limit=limit,
command_ids=command_ids, command_ids=command_ids,

84
discord/commands.py

@ -26,7 +26,7 @@ from __future__ import annotations
from typing import TYPE_CHECKING, Any, Dict, List, Optional, Protocol, Tuple, Type, Union, runtime_checkable from typing import TYPE_CHECKING, Any, Dict, List, Optional, Protocol, Tuple, Type, Union, runtime_checkable
from .enums import AppCommandOptionType, AppCommandType, ChannelType, InteractionType, try_enum from .enums import ApplicationCommandOptionType, ApplicationCommandType, ChannelType, InteractionType, try_enum
from .interactions import _wrapped_interaction from .interactions import _wrapped_interaction
from .mixins import Hashable from .mixins import Hashable
from .permissions import Permissions from .permissions import Permissions
@ -76,7 +76,7 @@ class ApplicationCommand(Protocol):
The command's name. The command's name.
description: :class:`str` description: :class:`str`
The command's description, if any. The command's description, if any.
type: :class:`~discord.AppCommandType` type: :class:`~discord.ApplicationCommandType`
The type of application command. The type of application command.
dm_permission: :class:`bool` dm_permission: :class:`bool`
Whether the command is enabled in DMs. Whether the command is enabled in DMs.
@ -101,7 +101,7 @@ class ApplicationCommand(Protocol):
name: str name: str
description: str description: str
version: int version: int
type: AppCommandType type: ApplicationCommandType
dm_permission: bool dm_permission: bool
nsfw: bool nsfw: bool
application_id: int application_id: int
@ -203,7 +203,7 @@ class BaseCommand(ApplicationCommand, Hashable):
self.application_id: int = int(data['application_id']) self.application_id: int = int(data['application_id'])
self.id: int = int(data['id']) self.id: int = int(data['id'])
self.version = int(data['version']) self.version = int(data['version'])
self.type = try_enum(AppCommandType, data['type']) self.type = try_enum(ApplicationCommandType, data['type'])
application = data.get('application') application = data.get('application')
self.application = state.create_integration_application(application) if application else None self.application = state.create_integration_application(application) if application else None
@ -263,25 +263,25 @@ class SlashMixin(ApplicationCommand, Protocol):
type = option.type type = option.type
if type in { if type in {
AppCommandOptionType.user, ApplicationCommandOptionType.user,
AppCommandOptionType.channel, ApplicationCommandOptionType.channel,
AppCommandOptionType.role, ApplicationCommandOptionType.role,
AppCommandOptionType.mentionable, ApplicationCommandOptionType.mentionable,
}: }:
v = str(v.id) v = str(v.id)
elif type is AppCommandOptionType.boolean: elif type is ApplicationCommandOptionType.boolean:
v = bool(v) v = bool(v)
elif type is AppCommandOptionType.attachment: elif type is ApplicationCommandOptionType.attachment:
files.append(v) files.append(v)
v = len(files) - 1 v = len(files) - 1
else: else:
v = option._convert(v) v = option._convert(v)
if type is AppCommandOptionType.string: if type is ApplicationCommandOptionType.string:
v = str(v) v = str(v)
elif type is AppCommandOptionType.integer: elif type is ApplicationCommandOptionType.integer:
v = int(v) v = int(v)
elif type is AppCommandOptionType.number: elif type is ApplicationCommandOptionType.number:
v = float(v) v = float(v)
options.append({'name': k, 'value': v, 'type': type.value}) options.append({'name': k, 'value': v, 'type': type.value})
@ -296,10 +296,10 @@ class SlashMixin(ApplicationCommand, Protocol):
options = [] options = []
children = [] children = []
for option in data: for option in data:
type = try_enum(AppCommandOptionType, option['type']) type = try_enum(ApplicationCommandOptionType, option['type'])
if type in { if type in {
AppCommandOptionType.sub_command, ApplicationCommandOptionType.sub_command,
AppCommandOptionType.sub_command_group, ApplicationCommandOptionType.sub_command_group,
}: }:
children.append(SubCommand(parent=self, data=option)) children.append(SubCommand(parent=self, data=option))
else: else:
@ -346,8 +346,8 @@ class UserCommand(BaseCommand):
The command's name. The command's name.
description: :class:`str` description: :class:`str`
The command's description, if any. The command's description, if any.
type: :class:`AppCommandType` type: :class:`ApplicationCommandType`
The type of application command. This will always be :attr:`AppCommandType.user`. The type of application command. This will always be :attr:`ApplicationCommandType.user`.
dm_permission: :class:`bool` dm_permission: :class:`bool`
Whether the command is enabled in DMs. Whether the command is enabled in DMs.
nsfw: :class:`bool` nsfw: :class:`bool`
@ -458,8 +458,8 @@ class MessageCommand(BaseCommand):
The command's name. The command's name.
description: :class:`str` description: :class:`str`
The command's description, if any. The command's description, if any.
type: :class:`AppCommandType` type: :class:`ApplicationCommandType`
The type of application command. This will always be :attr:`AppCommandType.message`. The type of application command. This will always be :attr:`ApplicationCommandType.message`.
dm_permission: :class:`bool` dm_permission: :class:`bool`
Whether the command is enabled in DMs. Whether the command is enabled in DMs.
nsfw: :class:`bool` nsfw: :class:`bool`
@ -571,7 +571,7 @@ class SlashCommand(BaseCommand, SlashMixin):
The command's name. The command's name.
description: :class:`str` description: :class:`str`
The command's description, if any. The command's description, if any.
type: :class:`AppCommandType` type: :class:`ApplicationCommandType`
The type of application command. The type of application command.
dm_permission: :class:`bool` dm_permission: :class:`bool`
Whether the command is enabled in DMs. Whether the command is enabled in DMs.
@ -669,8 +669,8 @@ class SubCommand(SlashMixin):
The subcommand's name. The subcommand's name.
description: :class:`str` description: :class:`str`
The subcommand's description, if any. The subcommand's description, if any.
type: :class:`AppCommandType` type: :class:`ApplicationCommandType`
The type of application command. Always :attr:`AppCommandType.chat_input`. The type of application command. Always :attr:`ApplicationCommandType.chat_input`.
parent: Union[:class:`SlashCommand`, :class:`SubCommand`] parent: Union[:class:`SlashCommand`, :class:`SubCommand`]
The parent command. The parent command.
options: List[:class:`Option`] options: List[:class:`Option`]
@ -695,8 +695,8 @@ class SubCommand(SlashMixin):
self._state = parent._state self._state = parent._state
self.parent: Union[SlashCommand, SubCommand] = parent self.parent: Union[SlashCommand, SubCommand] = parent
self._parent: SlashCommand = getattr(parent, 'parent', parent) # type: ignore self._parent: SlashCommand = getattr(parent, 'parent', parent) # type: ignore
self.type = AppCommandType.chat_input # Avoid confusion I guess self.type = ApplicationCommandType.chat_input # Avoid confusion I guess
self._type: AppCommandOptionType = try_enum(AppCommandOptionType, data['type']) self._type: ApplicationCommandOptionType = try_enum(ApplicationCommandOptionType, data['type'])
self._unwrap_options(data.get('options', [])) self._unwrap_options(data.get('options', []))
def __str__(self) -> str: def __str__(self) -> str:
@ -827,7 +827,7 @@ class SubCommand(SlashMixin):
:class:`bool` :class:`bool`
Whether this command is a group. Whether this command is a group.
""" """
return self._type is AppCommandOptionType.sub_command_group return self._type is ApplicationCommandOptionType.sub_command_group
@property @property
def application(self): def application(self):
@ -866,26 +866,26 @@ class Option:
The option's name. The option's name.
description: :class:`str` description: :class:`str`
The option's description, if any. The option's description, if any.
type: :class:`AppCommandOptionType` type: :class:`ApplicationCommandOptionType`
The type of option. The type of option.
required: :class:`bool` required: :class:`bool`
Whether the option is required. Whether the option is required.
min_value: Optional[Union[:class:`int`, :class:`float`]] min_value: Optional[Union[:class:`int`, :class:`float`]]
Minimum value of the option. Only applicable to :attr:`AppCommandOptionType.integer` and :attr:`AppCommandOptionType.number`. Minimum value of the option. Only applicable to :attr:`ApplicationCommandOptionType.integer` and :attr:`ApplicationCommandOptionType.number`.
max_value: Optional[Union[:class:`int`, :class:`float`]] max_value: Optional[Union[:class:`int`, :class:`float`]]
Maximum value of the option. Only applicable to :attr:`AppCommandOptionType.integer` and :attr:`AppCommandOptionType.number`. Maximum value of the option. Only applicable to :attr:`ApplicationCommandOptionType.integer` and :attr:`ApplicationCommandOptionType.number`.
choices: List[:class:`OptionChoice`] choices: List[:class:`OptionChoice`]
A list of possible choices to choose from. If these are present, you must choose one from them. A list of possible choices to choose from. If these are present, you must choose one from them.
Only applicable to :attr:`AppCommandOptionType.string`, :attr:`AppCommandOptionType.integer`, and :attr:`AppCommandOptionType.number`. Only applicable to :attr:`ApplicationCommandOptionType.string`, :attr:`ApplicationCommandOptionType.integer`, and :attr:`ApplicationCommandOptionType.number`.
channel_types: List[:class:`ChannelType`] channel_types: List[:class:`ChannelType`]
A list of channel types that you can choose from. If these are present, you must choose a channel that is one of these types. A list of channel types that you can choose from. If these are present, you must choose a channel that is one of these types.
Only applicable to :attr:`AppCommandOptionType.channel`. Only applicable to :attr:`ApplicationCommandOptionType.channel`.
autocomplete: :class:`bool` autocomplete: :class:`bool`
Whether the option autocompletes. Whether the option autocompletes.
Only applicable to :attr:`AppCommandOptionType.string`, :attr:`AppCommandOptionType.integer`, and :attr:`AppCommandOptionType.number`. Only applicable to :attr:`ApplicationCommandOptionType.string`, :attr:`ApplicationCommandOptionType.integer`, and :attr:`ApplicationCommandOptionType.number`.
Always ``False`` if :attr:`choices` are present. Always ``False`` if :attr:`choices` are present.
""" """
@ -904,7 +904,7 @@ class Option:
def __init__(self, data): def __init__(self, data):
self.name: str = data['name'] self.name: str = data['name']
self.description: str = data['description'] self.description: str = data['description']
self.type: AppCommandOptionType = try_enum(AppCommandOptionType, data['type']) self.type: ApplicationCommandOptionType = try_enum(ApplicationCommandOptionType, data['type'])
self.required: bool = data.get('required', False) self.required: bool = data.get('required', False)
self.min_value: Optional[Union[int, float]] = data.get('min_value') self.min_value: Optional[Union[int, float]] = data.get('min_value')
self.max_value: Optional[int] = data.get('max_value') self.max_value: Optional[int] = data.get('max_value')
@ -946,14 +946,14 @@ class OptionChoice:
__slots__ = ('name', 'value') __slots__ = ('name', 'value')
def __init__(self, data: Dict[str, str], type: AppCommandOptionType): def __init__(self, data: Dict[str, str], type: ApplicationCommandOptionType):
self.name: str = data['name'] self.name: str = data['name']
self.value: Union[str, int, float] self.value: Union[str, int, float]
if type is AppCommandOptionType.string: if type is ApplicationCommandOptionType.string:
self.value = data['value'] self.value = data['value']
elif type is AppCommandOptionType.integer: elif type is ApplicationCommandOptionType.integer:
self.value = int(data['value']) self.value = int(data['value'])
elif type is AppCommandOptionType.number: elif type is ApplicationCommandOptionType.number:
self.value = float(data['value']) self.value = float(data['value'])
def __str__(self) -> str: def __str__(self) -> str:
@ -968,13 +968,13 @@ class OptionChoice:
return value return value
def _command_factory(command_type: int) -> Tuple[AppCommandType, Type[BaseCommand]]: def _command_factory(command_type: int) -> Tuple[ApplicationCommandType, Type[BaseCommand]]:
value = try_enum(AppCommandType, command_type) value = try_enum(ApplicationCommandType, command_type)
if value is AppCommandType.chat_input: if value is ApplicationCommandType.chat_input:
return value, SlashCommand return value, SlashCommand
elif value is AppCommandType.user: elif value is ApplicationCommandType.user:
return value, UserCommand return value, UserCommand
elif value is AppCommandType.message: elif value is ApplicationCommandType.message:
return value, MessageCommand return value, MessageCommand
else: else:
return value, BaseCommand # IDK about this return value, BaseCommand # IDK about this

12
discord/enums.py

@ -64,7 +64,9 @@ __all__ = (
'Locale', 'Locale',
'EntityType', 'EntityType',
'EventStatus', 'EventStatus',
'ApplicationCommandType',
'AppCommandType', 'AppCommandType',
'ApplicationCommandOptionType',
'AppCommandOptionType', 'AppCommandOptionType',
'RelationshipType', 'RelationshipType',
'HypeSquadHouse', 'HypeSquadHouse',
@ -1055,7 +1057,7 @@ class EventStatus(Enum):
cancelled = 4 cancelled = 4
class AppCommandOptionType(Enum): class ApplicationCommandOptionType(Enum):
subcommand = 1 subcommand = 1
sub_command = 1 sub_command = 1
subcommand_group = 2 subcommand_group = 2
@ -1071,7 +1073,10 @@ class AppCommandOptionType(Enum):
attachment = 11 attachment = 11
class AppCommandType(Enum): AppCommandOptionType = ApplicationCommandOptionType
class ApplicationCommandType(Enum):
chat_input = 1 chat_input = 1
user = 2 user = 2
message = 3 message = 3
@ -1080,6 +1085,9 @@ class AppCommandType(Enum):
return self.value return self.value
AppCommandType = ApplicationCommandType
class ConnectionType(Enum): class ConnectionType(Enum):
battle_net = 'battlenet' battle_net = 'battlenet'
contacts = 'contacts' contacts = 'contacts'

4
discord/message.py

@ -51,7 +51,7 @@ from .reaction import Reaction
from .emoji import Emoji from .emoji import Emoji
from .partial_emoji import PartialEmoji from .partial_emoji import PartialEmoji
from .calls import CallMessage from .calls import CallMessage
from .enums import MessageType, ChannelType, AppCommandType, try_enum from .enums import MessageType, ChannelType, ApplicationCommandType, try_enum
from .errors import HTTPException from .errors import HTTPException
from .components import _component_factory from .components import _component_factory
from .embeds import Embed from .embeds import Embed
@ -2359,7 +2359,7 @@ class Message(PartialMessage, Hashable):
""" """
return _handle_commands( return _handle_commands(
self, self,
AppCommandType.message, ApplicationCommandType.message,
query=query, query=query,
limit=limit, limit=limit,
command_ids=command_ids, command_ids=command_ids,

4
discord/types/integration.py

@ -30,7 +30,7 @@ from typing_extensions import NotRequired
from .application import IntegrationApplication, RoleConnectionMetadata from .application import IntegrationApplication, RoleConnectionMetadata
from .guild import Guild from .guild import Guild
from .snowflake import Snowflake from .snowflake import Snowflake
from .user import User from .user import APIUser
class IntegrationAccount(TypedDict): class IntegrationAccount(TypedDict):
@ -54,7 +54,7 @@ IntegrationType = Literal['twitch', 'youtube', 'discord', 'guild_subscription']
class BaseIntegration(PartialIntegration): class BaseIntegration(PartialIntegration):
enabled: bool enabled: bool
user: NotRequired[User] user: NotRequired[APIUser]
class StreamIntegration(BaseIntegration): class StreamIntegration(BaseIntegration):

4
docs/api.rst

@ -5483,7 +5483,7 @@ of :class:`enum.Enum`.
An alias for :attr:`paragraph`. An alias for :attr:`paragraph`.
.. class:: AppCommandType .. class:: ApplicationCommandType
The type of application command. The type of application command.
@ -5501,7 +5501,7 @@ of :class:`enum.Enum`.
A message context menu command. A message context menu command.
.. class:: AppCommandOptionType .. class:: ApplicationCommandOptionType
The application command's option type. This is usually the type of parameter an application command takes. The application command's option type. This is usually the type of parameter an application command takes.

Loading…
Cancel
Save