From f7e4223dc680ca2cafc558734bc4589aa7800c5e Mon Sep 17 00:00:00 2001 From: Richard Chien Date: Fri, 14 Feb 2020 16:44:22 +0800 Subject: [PATCH] Support str type for aliases --- nonebot/command/__init__.py | 5 ++++- nonebot/command/group.pyi | 2 +- 2 files changed, 5 insertions(+), 2 deletions(-) diff --git a/nonebot/command/__init__.py b/nonebot/command/__init__.py index 5a9fb7bf..7ffccdb6 100644 --- a/nonebot/command/__init__.py +++ b/nonebot/command/__init__.py @@ -151,7 +151,7 @@ class CommandFunc: def on_command(name: Union[str, CommandName_T], *, - aliases: Iterable[str] = (), + aliases: Union[Iterable[str], str] = (), permission: int = perm.EVERYBODY, only_to_me: bool = True, privileged: bool = False, @@ -189,6 +189,9 @@ def on_command(name: Union[str, CommandName_T], *, current_parent = current_parent[parent_key] current_parent[cmd_name[-1]] = cmd + nonlocal aliases + if isinstance(aliases, str): + aliases = (aliases,) for alias in aliases: _aliases[alias] = cmd_name diff --git a/nonebot/command/group.pyi b/nonebot/command/group.pyi index ace431a8..68eee38a 100644 --- a/nonebot/command/group.pyi +++ b/nonebot/command/group.pyi @@ -17,7 +17,7 @@ class CommandGroup: shell_like: bool = ...): ... def command(self, name: Union[str, CommandName_T], *, - aliases: Iterable[str] = ..., + aliases: Union[Iterable[str], str] = ..., permission: int = ..., only_to_me: bool = ..., privileged: bool = ...,