Implement a least breaking approach to slash commands (#39)

* Most slash command support completed, needs some debugging (and reindent)

* Implement a ctx.send helper for slash commands

* Add group command support

* Add Option converter, fix default optional, fix help command

* Add client.setup and move readying commands to that

* Implement _FakeSlashMessage.from_interaction

* Rename normmal_command to message_command

* Add docs for added params

* Add slash_command_guilds to bot and decos

* Fix merge conflict

* Remove name from commands.Option, wasn't used

* Move slash command processing to BotBase.process_slash_commands

* Create slash_only.py

Basic example for slash commands

* Create slash_and_message.py

Basic example for mixed commands

* Fix slash_command and normal_command bools

* Add some basic error handling for registration

* Fixed converter upload errors

* Fix some logic and make an actual example

* Thanks Safety Jim

* docstrings, *args, and error changes

* Add proper literal support

* Add basic documentation on slash commands

* Fix non-slash command interactions

* Fix ctx.reply in slash command context

* Fix typing on Context.reply

* Fix multiple optional argument sorting

* Update ctx.message docs to mention error instead of warning

* Move slash command creation to BotBase

* Fix code style issues with Black

* Rearrange some stuff and add flag support

* Change some errors and fix interaction.channel fixing

* Fix slash command quoting for *args

Co-authored-by: iDutchy <42503862+iDutchy@users.noreply.github.com>
Co-authored-by: Lint Action <lint-action@samuelmeuli.com>
This commit is contained in:
Gnome!
2021-09-19 00:28:11 +01:00
committed by GitHub
parent 75a23351c4
commit 1957fa6011
14 changed files with 662 additions and 39 deletions

View File

@@ -77,6 +77,7 @@ __all__ = (
"GuildStickerConverter",
"clean_content",
"Greedy",
"Option",
"run_converters",
)
@@ -96,6 +97,8 @@ T_co = TypeVar("T_co", covariant=True)
CT = TypeVar("CT", bound=discord.abc.GuildChannel)
TT = TypeVar("TT", bound=discord.Thread)
DT = TypeVar("DT", bound=str)
@runtime_checkable
class Converter(Protocol[T_co]):
@@ -583,7 +586,7 @@ class ThreadConverter(IDConverter[discord.Thread]):
2. Lookup by mention.
3. Lookup by name.
.. versionadded: 2.0
.. versionadded:: 2.0
"""
async def convert(self, ctx: Context, argument: str) -> discord.Thread:
@@ -1005,6 +1008,27 @@ class Greedy(List[T]):
return cls(converter=converter)
if TYPE_CHECKING:
def Option(default: T = inspect.Parameter.empty, *, description: str) -> T:
...
else:
class Option(Generic[T, DT]):
description: DT
default: Union[T, inspect.Parameter.empty]
__slots__ = (
"default",
"description",
)
def __init__(self, default: T = inspect.Parameter.empty, *, description: DT) -> None:
self.description = description
self.default = default
def _convert_to_bool(argument: str) -> bool:
lowered = argument.lower()
if lowered in ("yes", "y", "true", "t", "1", "enable", "on"):