mirror of
https://github.com/Cog-Creators/Red-DiscordBot.git
synced 2025-11-06 03:08:55 -05:00
Add redbot.core.app_commands namespace (#6006)
This commit is contained in:
parent
c79d0d723e
commit
44e129bc66
5
.github/labeler.yml
vendored
5
.github/labeler.yml
vendored
@ -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:
|
||||||
|
|||||||
61
redbot/core/app_commands/__init__.py
Normal file
61
redbot/core/app_commands/__init__.py
Normal 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,
|
||||||
|
)
|
||||||
@ -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
|
||||||
|
|
||||||
|
|||||||
@ -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,
|
||||||
|
|||||||
@ -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
|
||||||
|
|
||||||
|
|||||||
@ -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
|
||||||
|
|||||||
23
tests/core/test_app_commands.py
Normal file
23
tests/core/test_app_commands.py
Normal 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)
|
||||||
|
)
|
||||||
@ -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(
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user