From c2de849ea7ed737f9d080b924558915483363cd6 Mon Sep 17 00:00:00 2001 From: Richard Chien Date: Mon, 1 Jul 2019 09:59:49 +0800 Subject: [PATCH] Update natural_language.py --- nonebot/natural_language.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/nonebot/natural_language.py b/nonebot/natural_language.py index 8df08fbd..e1a49367 100644 --- a/nonebot/natural_language.py +++ b/nonebot/natural_language.py @@ -27,7 +27,7 @@ class NLProcessor: self.allow_empty_message = allow_empty_message -def on_natural_language(keywords: Union[Optional[Iterable], Callable] = None, +def on_natural_language(keywords: Union[Optional[Iterable], str, Callable] = None, *, permission: int = perm.EVERYBODY, only_to_me: bool = True, only_short_message: bool = True, @@ -42,9 +42,6 @@ def on_natural_language(keywords: Union[Optional[Iterable], Callable] = None, :param allow_empty_message: handle empty messages """ - if isinstance(keywords, str): - keywords = (keywords,) - def deco(func: Callable) -> Callable: nl_processor = NLProcessor(func=func, keywords=keywords, permission=permission, @@ -58,6 +55,8 @@ def on_natural_language(keywords: Union[Optional[Iterable], Callable] = None, # here "keywords" is the function to be decorated return on_natural_language()(keywords) else: + if isinstance(keywords, str): + keywords = (keywords,) return deco