From ae35c2e08a03595acf2392b29f74c6fb998f1ed4 Mon Sep 17 00:00:00 2001 From: Richard Chien Date: Fri, 25 Jan 2019 14:03:57 +0800 Subject: [PATCH] Keep `send_kwargs` through `get()` and argument filter --- nonebot/command/__init__.py | 8 +++++--- nonebot/command/argfilter/__init__.py | 3 ++- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/nonebot/command/__init__.py b/nonebot/command/__init__.py index 1288b59e..be1cfa9e 100644 --- a/nonebot/command/__init__.py +++ b/nonebot/command/__init__.py @@ -260,7 +260,8 @@ class SwitchException(Exception): class CommandSession(BaseSession): - __slots__ = ('cmd', 'current_key', 'current_arg_filters', + __slots__ = ('cmd', + 'current_key', 'current_arg_filters', '_current_send_kwargs', 'current_arg', '_current_arg_text', '_current_arg_images', '_state', '_last_interaction', '_running') @@ -275,6 +276,8 @@ class CommandSession(BaseSession): # initialize current argument filters self.current_arg_filters: Optional[List[ArgFilter_T]] = None + self._current_send_kwargs: Dict[str, Any] = {} + # initialize current argument self.current_arg: str = '' # with potential CQ codes self._current_arg_text = None @@ -392,8 +395,7 @@ class CommandSession(BaseSession): self.current_key = key self.current_arg_filters = arg_filters - # TODO: self.current_send_kwargs - # ask the user for more information + self._current_send_kwargs = kwargs self.pause(prompt, **kwargs) def get_optional(self, key: str, diff --git a/nonebot/command/argfilter/__init__.py b/nonebot/command/argfilter/__init__.py index ace534de..ba78e3e1 100644 --- a/nonebot/command/argfilter/__init__.py +++ b/nonebot/command/argfilter/__init__.py @@ -44,7 +44,8 @@ async def run_arg_filters(session: 'CommandSession', failure_message = render_expression( session.bot.config.DEFAULT_VALIDATION_FAILURE_EXPRESSION ) - session.pause(failure_message) + # noinspection PyProtectedMember + session.pause(failure_message, **session._current_send_kwargs) # passed all filters session.state[session.current_key] = arg