From 9f8d009309603f0b843791c983aa096bda57ad4a Mon Sep 17 00:00:00 2001 From: yanyongyu Date: Tue, 6 Oct 2020 16:24:04 +0800 Subject: [PATCH] :sparkles: add matcher.send method --- nonebot/matcher.py | 30 ++++++++++++++++++------------ 1 file changed, 18 insertions(+), 12 deletions(-) diff --git a/nonebot/matcher.py b/nonebot/matcher.py index ab2f99d4..04dea30e 100644 --- a/nonebot/matcher.py +++ b/nonebot/matcher.py @@ -279,13 +279,19 @@ class Matcher(metaclass=MatcherMeta): return _decorator + @classmethod + async def send(cls, message: Union[str, Message, MessageSegment]): + bot = current_bot.get() + event = current_event.get() + await bot.send(event=event, message=message) + @classmethod async def finish( cls, prompt: Optional[Union[str, Message, MessageSegment]] = None) -> NoReturn: - bot: Bot = current_bot.get() - event: Event = current_event.get() + bot = current_bot.get() + event = current_event.get() if prompt: await bot.send(event=event, message=prompt) raise FinishedException @@ -295,8 +301,8 @@ class Matcher(metaclass=MatcherMeta): cls, prompt: Optional[Union[str, Message, MessageSegment]] = None) -> NoReturn: - bot: Bot = current_bot.get() - event: Event = current_event.get() + bot = current_bot.get() + event = current_event.get() if prompt: await bot.send(event=event, message=prompt) raise PausedException @@ -306,8 +312,8 @@ class Matcher(metaclass=MatcherMeta): cls, prompt: Optional[Union[str, Message, MessageSegment]] = None) -> NoReturn: - bot: Bot = current_bot.get() - event: Event = current_event.get() + bot = current_bot.get() + event = current_event.get() if prompt: await bot.send(event=event, message=prompt) raise RejectedException @@ -508,8 +514,8 @@ class MatcherGroup: self, prompt: Optional[Union[str, Message, MessageSegment]] = None) -> NoReturn: - bot: Bot = current_bot.get() - event: Event = current_event.get() + bot = current_bot.get() + event = current_event.get() if prompt: await bot.send(event=event, message=prompt) raise FinishedException @@ -518,8 +524,8 @@ class MatcherGroup: self, prompt: Optional[Union[str, Message, MessageSegment]] = None) -> NoReturn: - bot: Bot = current_bot.get() - event: Event = current_event.get() + bot = current_bot.get() + event = current_event.get() if prompt: await bot.send(event=event, message=prompt) raise PausedException @@ -528,8 +534,8 @@ class MatcherGroup: self, prompt: Optional[Union[str, Message, MessageSegment]] = None) -> NoReturn: - bot: Bot = current_bot.get() - event: Event = current_event.get() + bot = current_bot.get() + event = current_event.get() if prompt: await bot.send(event=event, message=prompt) raise RejectedException