add kwargs support for matcher send/finish/pause/reject

This commit is contained in:
yanyongyu 2020-10-17 19:50:25 +08:00
parent 9ad629841b
commit 56c9c24dc6

View File

@ -298,66 +298,70 @@ class Matcher(metaclass=MatcherMeta):
return _decorator
@classmethod
async def send(cls, message: Union[str, Message, MessageSegment]):
async def send(cls, message: Union[str, Message, MessageSegment], **kwargs):
"""
:说明:
发送一条消息给当前交互用户
:参数:
* ``message: Union[str, Message, MessageSegment]``: 消息内容
* ``**kwargs``: 其他传递给 ``bot.send`` 的参数请参考对应 adapter bot 对象 api
"""
bot = current_bot.get()
event = current_event.get()
await bot.send(event=event, message=message)
await bot.send(event=event, message=message, **kwargs)
@classmethod
async def finish(
cls,
message: Optional[Union[str, Message,
MessageSegment]] = None) -> NoReturn:
async def finish(cls,
message: Optional[Union[str, Message,
MessageSegment]] = None,
**kwargs) -> NoReturn:
"""
:说明:
发送一条消息给当前交互用户并结束当前事件响应器
:参数:
* ``message: Union[str, Message, MessageSegment]``: 消息内容
* ``**kwargs``: 其他传递给 ``bot.send`` 的参数请参考对应 adapter bot 对象 api
"""
bot = current_bot.get()
event = current_event.get()
if message:
await bot.send(event=event, message=message)
await bot.send(event=event, message=message, **kwargs)
raise FinishedException
@classmethod
async def pause(
cls,
prompt: Optional[Union[str, Message,
MessageSegment]] = None) -> NoReturn:
async def pause(cls,
prompt: Optional[Union[str, Message,
MessageSegment]] = None,
**kwargs) -> NoReturn:
"""
:说明:
发送一条消息给当前交互用户并暂停事件响应器在接收用户新的一条消息后继续下一个处理函数
:参数:
* ``prompt: Union[str, Message, MessageSegment]``: 消息内容
* ``**kwargs``: 其他传递给 ``bot.send`` 的参数请参考对应 adapter bot 对象 api
"""
bot = current_bot.get()
event = current_event.get()
if prompt:
await bot.send(event=event, message=prompt)
await bot.send(event=event, message=prompt, **kwargs)
raise PausedException
@classmethod
async def reject(
cls,
prompt: Optional[Union[str, Message,
MessageSegment]] = None) -> NoReturn:
async def reject(cls,
prompt: Optional[Union[str, Message,
MessageSegment]] = None,
**kwargs) -> NoReturn:
"""
:说明:
发送一条消息给当前交互用户并暂停事件响应器在接收用户新的一条消息后重新运行当前处理函数
:参数:
* ``prompt: Union[str, Message, MessageSegment]``: 消息内容
* ``**kwargs``: 其他传递给 ``bot.send`` 的参数请参考对应 adapter bot 对象 api
"""
bot = current_bot.get()
event = current_event.get()
if prompt:
await bot.send(event=event, message=prompt)
await bot.send(event=event, message=prompt, **kwargs)
raise RejectedException
# 运行handlers