Add redbot.core.app_commands namespace (#6006)

This commit is contained in:
Jakub Kuczys 2023-03-28 02:49:59 +02:00 committed by GitHub
parent c79d0d723e
commit 44e129bc66
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 104 additions and 21 deletions

5
.github/labeler.yml vendored
View File

@ -134,6 +134,11 @@
- redbot/core/bank.py - redbot/core/bank.py
# Docs # Docs
- docs/framework_bank.rst - docs/framework_bank.rst
"Category: Core - API - App Commands Package":
# Source
- redbot/core/app_commands/*
# Tests
- tests/core/test_app_commands.py
"Category: Core - API - Commands Package": "Category: Core - API - Commands Package":
# Source # Source
- any: - any:

View File

@ -0,0 +1,61 @@
########## SENSITIVE SECTION WARNING ###########
################################################
# Any edits of any of the exported names #
# may result in a breaking change. #
# Ensure no names are removed without warning. #
################################################
### DEP-WARN: Check this *every* discord.py update
from discord.app_commands import (
AllChannels as AllChannels,
AppCommand as AppCommand,
AppCommandChannel as AppCommandChannel,
AppCommandError as AppCommandError,
AppCommandGroup as AppCommandGroup,
AppCommandPermissions as AppCommandPermissions,
AppCommandThread as AppCommandThread,
Argument as Argument,
BotMissingPermissions as BotMissingPermissions,
Command as Command,
CommandAlreadyRegistered as CommandAlreadyRegistered,
CommandInvokeError as CommandInvokeError,
CommandLimitReached as CommandLimitReached,
CommandNotFound as CommandNotFound,
CommandOnCooldown as CommandOnCooldown,
CommandSignatureMismatch as CommandSignatureMismatch,
CommandSyncFailure as CommandSyncFailure,
CommandTree as CommandTree,
ContextMenu as ContextMenu,
Cooldown as Cooldown,
Group as Group,
GuildAppCommandPermissions as GuildAppCommandPermissions,
MissingAnyRole as MissingAnyRole,
MissingApplicationID as MissingApplicationID,
MissingPermissions as MissingPermissions,
MissingRole as MissingRole,
Namespace as Namespace,
NoPrivateMessage as NoPrivateMessage,
Parameter as Parameter,
Range as Range,
Transform as Transform,
Transformer as Transformer,
TransformerError as TransformerError,
TranslationContext as TranslationContext,
TranslationContextLocation as TranslationContextLocation,
TranslationContextTypes as TranslationContextTypes,
TranslationError as TranslationError,
Translator as Translator,
autocomplete as autocomplete,
check as check,
CheckFailure as CheckFailure,
Choice as Choice,
choices as choices,
command as command,
context_menu as context_menu,
default_permissions as default_permissions,
describe as describe,
guild_only as guild_only,
guilds as guilds,
locale_str as locale_str,
rename as rename,
)

View File

@ -59,7 +59,8 @@ from .utils._internal_utils import send_to_owners_with_prefix_replaced
if TYPE_CHECKING: if TYPE_CHECKING:
from discord.ext.commands.hybrid import CommandCallback, ContextT, P from discord.ext.commands.hybrid import CommandCallback, ContextT, P
from discord import app_commands
from redbot.core import app_commands
_T = TypeVar("_T") _T = TypeVar("_T")
@ -1728,7 +1729,7 @@ class Red(
raise TypeError("command type must be one of chat_input, message, user") raise TypeError("command type must be one of chat_input, message, user")
async with cfg as curr_commands: async with cfg as curr_commands:
if len(curr_commands) >= limit: if len(curr_commands) >= limit:
raise discord.app_commands.CommandLimitReached(None, limit, type=command_type) raise app_commands.CommandLimitReached(None, limit, type=command_type)
if command_name not in curr_commands: if command_name not in curr_commands:
curr_commands[command_name] = None curr_commands[command_name] = None

View File

@ -46,6 +46,7 @@ from discord.ext.commands import (
from .errors import ConversionFailure from .errors import ConversionFailure
from .requires import PermState, PrivilegeLevel, Requires, PermStateAllowedStates from .requires import PermState, PrivilegeLevel, Requires, PermStateAllowedStates
from .. import app_commands
from ..i18n import Translator from ..i18n import Translator
_T = TypeVar("_T") _T = TypeVar("_T")
@ -1093,7 +1094,7 @@ class HybridGroup(Group, DPYHybridGroup[_CogT, _P, _T]):
def hybrid_command( def hybrid_command(
name: Union[str, discord.app_commands.locale_str] = discord.utils.MISSING, name: Union[str, app_commands.locale_str] = discord.utils.MISSING,
*, *,
with_app_command: bool = True, with_app_command: bool = True,
**attrs: Any, **attrs: Any,
@ -1113,7 +1114,7 @@ def hybrid_command(
def hybrid_group( def hybrid_group(
name: Union[str, discord.app_commands.locale_str] = discord.utils.MISSING, name: Union[str, app_commands.locale_str] = discord.utils.MISSING,
*, *,
with_app_command: bool = True, with_app_command: bool = True,
**attrs: Any, **attrs: Any,

View File

@ -18,7 +18,7 @@ import pip
import traceback import traceback
from pathlib import Path from pathlib import Path
from collections import defaultdict from collections import defaultdict
from redbot.core import data_manager from redbot.core import app_commands, data_manager
from redbot.core.utils.menus import menu from redbot.core.utils.menus import menu
from redbot.core.utils.views import SetApiView from redbot.core.utils.views import SetApiView
from redbot.core.commands import GuildConverter, RawUserIdConverter from redbot.core.commands import GuildConverter, RawUserIdConverter
@ -2005,7 +2005,7 @@ class Core(commands.commands._RuleDropper, commands.Cog, CoreLogic):
try: try:
await self.bot.enable_app_command(command_name, raw_type) await self.bot.enable_app_command(command_name, raw_type)
except discord.app_commands.CommandLimitReached: except app_commands.CommandLimitReached:
await ctx.send(_("The command limit has been reached. Disable a command first.")) await ctx.send(_("The command limit has been reached. Disable a command first."))
return return

View File

@ -1,22 +1,23 @@
import discord import discord
from discord.abc import Snowflake from discord.abc import Snowflake
from discord.utils import MISSING from discord.utils import MISSING
from discord.app_commands import (
Command, from .app_commands import (
Group,
ContextMenu,
AppCommand, AppCommand,
AppCommandError, AppCommandError,
BotMissingPermissions, BotMissingPermissions,
CheckFailure, CheckFailure,
Command,
CommandAlreadyRegistered, CommandAlreadyRegistered,
CommandInvokeError, CommandInvokeError,
CommandNotFound, CommandNotFound,
CommandOnCooldown, CommandOnCooldown,
CommandTree,
ContextMenu,
Group,
NoPrivateMessage, NoPrivateMessage,
TransformerError, TransformerError,
) )
from .i18n import Translator from .i18n import Translator
from .utils.chat_formatting import humanize_list, inline from .utils.chat_formatting import humanize_list, inline
@ -31,7 +32,7 @@ log = logging.getLogger("red")
_ = Translator(__name__, __file__) _ = Translator(__name__, __file__)
class RedTree(discord.app_commands.CommandTree): class RedTree(CommandTree):
"""A container that holds application command information. """A container that holds application command information.
Internally does not actually add commands to the tree unless they are Internally does not actually add commands to the tree unless they are

View File

@ -0,0 +1,23 @@
import inspect
import pytest
from discord import app_commands as dpy_app_commands
from redbot.core import app_commands
def test_dpy_app_commands_reexports():
dpy_attrs = set()
for attr_name, attr_value in dpy_app_commands.__dict__.items():
if attr_name.startswith("_") or inspect.ismodule(attr_value):
continue
dpy_attrs.add(attr_name)
missing_attrs = dpy_attrs - set(app_commands.__dict__.keys())
if missing_attrs:
pytest.fail(
"redbot.core.app_commands is missing these names from discord.app_commands: "
+ ", ".join(missing_attrs)
)

View File

@ -50,15 +50,6 @@ def test_dpy_commands_reexports():
dpy_attrs.add(attr_name) dpy_attrs.add(attr_name)
missing_attrs = dpy_attrs - set(commands.__dict__.keys()) missing_attrs = dpy_attrs - set(commands.__dict__.keys())
# temporarily ignore things related to app commands as the work on that is done separately
missing_attrs -= {
"GroupCog",
"HybridGroup",
"hybrid_group",
"hybrid_command",
"HybridCommand",
"HybridCommandError",
}
if missing_attrs: if missing_attrs:
pytest.fail( pytest.fail(