We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
Bug: event_postprocessor 不能在 matcher 运行后正常执行
**描述问题：**

event_postprocessor 不能在 matcher 运行后正常执行

**如何复现？**

编写以下插件
```python
from nonebot import on_command, logger
from nonebot.message import event_postprocessor
from nonebot.typing import T_State
from nonebot.adapters.cqhttp.event import Event, MessageEvent
from nonebot.adapters.cqhttp.bot import Bot


test = on_command('test')


@test.handle()
async def handle_test(bot: Bot, event: MessageEvent, state: T_State):
    logger.opt(colors=True).info('<ly>matcher is running!</ly>')


@event_postprocessor
async def handle_event_postprocessor(bot: Bot, event: Event, state: T_State):
    logger.opt(colors=True).success('<ly>event_postprocessor is running!</ly>')
```

**期望的结果**

event_postprocessor 能在任意情况下正常执行

实际上当 matcher 运行后 event_postprocessor 会被跳过

![image](https://user-images.githubusercontent.com/41713304/134709135-4d0d52ec-2df1-48a8-94ee-196c9c4d3da6.png)

**其他信息**

第 250 行 `return result` 将直接导致 matcher 运行后 event_postprocessor 被跳过

https://github.com/nonebot/nonebot2/blob/0b35d5e724a2fc7fc1e7d90499aea8a9c27e821d/nonebot/message.py#L238-L262

**环境信息：**

 - OS: Windows 10 21H1
 - Python Version: 3.9.6
 - Nonebot Version: 2.0.0a15

**协议端信息：**

 - 协议端: 无
 - 协议端版本: 无

**截图或日志**

如上


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `nonebot/message.py`
Content:
```
1 """
2 事件处理
3 ========
4 
5 NoneBot 内部处理并按优先级分发事件给所有事件响应器，提供了多个插槽以进行事件的预处理等。
6 """
7 
8 import asyncio
9 from datetime import datetime
10 from typing import TYPE_CHECKING, Set, Type, Optional
11 
12 from nonebot.log import logger
13 from nonebot.rule import TrieRule
14 from nonebot.utils import escape_tag
15 from nonebot.matcher import Matcher, matchers
16 from nonebot.exception import NoLogException, StopPropagation, IgnoredException
17 from nonebot.typing import (T_State, T_RunPreProcessor, T_RunPostProcessor,
18                             T_EventPreProcessor, T_EventPostProcessor)
19 
20 if TYPE_CHECKING:
21     from nonebot.adapters import Bot, Event
22 
23 _event_preprocessors: Set[T_EventPreProcessor] = set()
24 _event_postprocessors: Set[T_EventPostProcessor] = set()
25 _run_preprocessors: Set[T_RunPreProcessor] = set()
26 _run_postprocessors: Set[T_RunPostProcessor] = set()
27 
28 
29 def event_preprocessor(func: T_EventPreProcessor) -> T_EventPreProcessor:
30     """
31     :说明:
32 
33       事件预处理。装饰一个函数，使它在每次接收到事件并分发给各响应器之前执行。
34 
35     :参数:
36 
37       事件预处理函数接收三个参数。
38 
39       * ``bot: Bot``: Bot 对象
40       * ``event: Event``: Event 对象
41       * ``state: T_State``: 当前 State
42     """
43     _event_preprocessors.add(func)
44     return func
45 
46 
47 def event_postprocessor(func: T_EventPostProcessor) -> T_EventPostProcessor:
48     """
49     :说明:
50 
51       事件后处理。装饰一个函数，使它在每次接收到事件并分发给各响应器之后执行。
52 
53     :参数:
54 
55       事件后处理函数接收三个参数。
56 
57       * ``bot: Bot``: Bot 对象
58       * ``event: Event``: Event 对象
59       * ``state: T_State``: 当前事件运行前 State
60     """
61     _event_postprocessors.add(func)
62     return func
63 
64 
65 def run_preprocessor(func: T_RunPreProcessor) -> T_RunPreProcessor:
66     """
67     :说明:
68 
69       运行预处理。装饰一个函数，使它在每次事件响应器运行前执行。
70 
71     :参数:
72 
73       运行预处理函数接收四个参数。
74 
75       * ``matcher: Matcher``: 当前要运行的事件响应器
76       * ``bot: Bot``: Bot 对象
77       * ``event: Event``: Event 对象
78       * ``state: T_State``: 当前 State
79     """
80     _run_preprocessors.add(func)
81     return func
82 
83 
84 def run_postprocessor(func: T_RunPostProcessor) -> T_RunPostProcessor:
85     """
86     :说明:
87 
88       运行后处理。装饰一个函数，使它在每次事件响应器运行后执行。
89 
90     :参数:
91 
92       运行后处理函数接收五个参数。
93 
94       * ``matcher: Matcher``: 运行完毕的事件响应器
95       * ``exception: Optional[Exception]``: 事件响应器运行错误（如果存在）
96       * ``bot: Bot``: Bot 对象
97       * ``event: Event``: Event 对象
98       * ``state: T_State``: 当前 State
99     """
100     _run_postprocessors.add(func)
101     return func
102 
103 
104 async def _check_matcher(priority: int, Matcher: Type[Matcher], bot: "Bot",
105                          event: "Event", state: T_State) -> None:
106     if Matcher.expire_time and datetime.now() > Matcher.expire_time:
107         try:
108             matchers[priority].remove(Matcher)
109         except Exception:
110             pass
111         return
112 
113     try:
114         if not await Matcher.check_perm(
115                 bot, event) or not await Matcher.check_rule(bot, event, state):
116             return
117     except Exception as e:
118         logger.opt(colors=True, exception=e).error(
119             f"<r><bg #f8bbd0>Rule check failed for {Matcher}.</bg #f8bbd0></r>")
120         return
121 
122     if Matcher.temp:
123         try:
124             matchers[priority].remove(Matcher)
125         except Exception:
126             pass
127 
128     await _run_matcher(Matcher, bot, event, state)
129 
130 
131 async def _run_matcher(Matcher: Type[Matcher], bot: "Bot", event: "Event",
132                        state: T_State) -> None:
133     logger.info(f"Event will be handled by {Matcher}")
134 
135     matcher = Matcher()
136 
137     coros = list(
138         map(lambda x: x(matcher, bot, event, state), _run_preprocessors))
139     if coros:
140         try:
141             await asyncio.gather(*coros)
142         except IgnoredException:
143             logger.opt(colors=True).info(
144                 f"Matcher {matcher} running is <b>cancelled</b>")
145             return
146         except Exception as e:
147             logger.opt(colors=True, exception=e).error(
148                 "<r><bg #f8bbd0>Error when running RunPreProcessors. "
149                 "Running cancelled!</bg #f8bbd0></r>")
150             return
151 
152     exception = None
153 
154     try:
155         logger.debug(f"Running matcher {matcher}")
156         await matcher.run(bot, event, state)
157     except Exception as e:
158         logger.opt(colors=True, exception=e).error(
159             f"<r><bg #f8bbd0>Running matcher {matcher} failed.</bg #f8bbd0></r>"
160         )
161         exception = e
162 
163     coros = list(
164         map(lambda x: x(matcher, exception, bot, event, state),
165             _run_postprocessors))
166     if coros:
167         try:
168             await asyncio.gather(*coros)
169         except Exception as e:
170             logger.opt(colors=True, exception=e).error(
171                 "<r><bg #f8bbd0>Error when running RunPostProcessors</bg #f8bbd0></r>"
172             )
173 
174     if matcher.block:
175         raise StopPropagation
176     return
177 
178 
179 async def handle_event(bot: "Bot", event: "Event") -> Optional[Exception]:
180     """
181     :说明:
182 
183        处理一个事件。调用该函数以实现分发事件。
184 
185     :参数:
186 
187       * ``bot: Bot``: Bot 对象
188       * ``event: Event``: Event 对象
189 
190     :示例:
191 
192     .. code-block:: python
193 
194         import asyncio
195         asyncio.create_task(handle_event(bot, event))
196     """
197     show_log = True
198     log_msg = f"<m>{escape_tag(bot.type.upper())} {escape_tag(bot.self_id)}</m> | "
199     try:
200         log_msg += event.get_log_string()
201     except NoLogException:
202         show_log = False
203     if show_log:
204         logger.opt(colors=True).success(log_msg)
205 
206     state = {}
207     coros = list(map(lambda x: x(bot, event, state), _event_preprocessors))
208     if coros:
209         try:
210             if show_log:
211                 logger.debug("Running PreProcessors...")
212             await asyncio.gather(*coros)
213         except IgnoredException as e:
214             logger.opt(colors=True).info(
215                 f"Event {escape_tag(event.get_event_name())} is <b>ignored</b>")
216             return e
217         except Exception as e:
218             logger.opt(colors=True, exception=e).error(
219                 "<r><bg #f8bbd0>Error when running EventPreProcessors. "
220                 "Event ignored!</bg #f8bbd0></r>")
221             return e
222 
223     # Trie Match
224     _, _ = TrieRule.get_value(bot, event, state)
225 
226     break_flag = False
227     for priority in sorted(matchers.keys()):
228         if break_flag:
229             break
230 
231         if show_log:
232             logger.debug(f"Checking for matchers in priority {priority}...")
233 
234         pending_tasks = [
235             _check_matcher(priority, matcher, bot, event, state.copy())
236             for matcher in matchers[priority]
237         ]
238 
239         results = await asyncio.gather(*pending_tasks, return_exceptions=True)
240 
241         for result in results:
242             if not isinstance(result, Exception):
243                 continue
244             if isinstance(result, StopPropagation):
245                 break_flag = True
246                 logger.debug("Stop event propagation")
247             else:
248                 logger.opt(colors=True, exception=result).error(
249                     "<r><bg #f8bbd0>Error when checking Matcher.</bg #f8bbd0></r>"
250                 )
251             return result
252 
253     coros = list(map(lambda x: x(bot, event, state), _event_postprocessors))
254     if coros:
255         try:
256             if show_log:
257                 logger.debug("Running PostProcessors...")
258             await asyncio.gather(*coros)
259         except Exception as e:
260             logger.opt(colors=True, exception=e).error(
261                 "<r><bg #f8bbd0>Error when running EventPostProcessors</bg #f8bbd0></r>"
262             )
263             return e
264
```
--- END FILES ---

Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.

Here is an example:

```diff
diff --git a/examples/server_async.py b/examples/server_async.py
--- a/examples/server_async.py
+++ b/examples/server_async.py
@@ -313,4 +313,4 @@
 
 
 if __name__ == "__main__":
-    asyncio.run(run_async_server("."), debug=True)
+    asyncio.run(run_async_server(), debug=True)
diff --git a/examples/server_sync.py b/examples/server_sync.py
--- a/examples/server_sync.py
+++ b/examples/server_sync.py
@@ -313,5 +313,5 @@
 
 
 if __name__ == "__main__":
-    server = run_sync_server(".")
+    server = run_sync_server()
     server.shutdown()

```

diff --git a/nonebot/message.py b/nonebot/message.py
--- a/nonebot/message.py
+++ b/nonebot/message.py
@@ -176,7 +176,7 @@
     return
 
 
-async def handle_event(bot: "Bot", event: "Event") -> Optional[Exception]:
+async def handle_event(bot: "Bot", event: "Event") -> None:
     """
     :说明:
 
@@ -213,12 +213,12 @@
         except IgnoredException as e:
             logger.opt(colors=True).info(
                 f"Event {escape_tag(event.get_event_name())} is <b>ignored</b>")
-            return e
+            return
         except Exception as e:
             logger.opt(colors=True, exception=e).error(
                 "<r><bg #f8bbd0>Error when running EventPreProcessors. "
                 "Event ignored!</bg #f8bbd0></r>")
-            return e
+            return
 
     # Trie Match
     _, _ = TrieRule.get_value(bot, event, state)
@@ -248,7 +248,6 @@
                 logger.opt(colors=True, exception=result).error(
                     "<r><bg #f8bbd0>Error when checking Matcher.</bg #f8bbd0></r>"
                 )
-            return result
 
     coros = list(map(lambda x: x(bot, event, state), _event_postprocessors))
     if coros:
@@ -260,4 +259,3 @@
             logger.opt(colors=True, exception=e).error(
                 "<r><bg #f8bbd0>Error when running EventPostProcessors</bg #f8bbd0></r>"
             )
-            return e

{"golden_diff": "diff --git a/nonebot/message.py b/nonebot/message.py\n--- a/nonebot/message.py\n+++ b/nonebot/message.py\n@@ -176,7 +176,7 @@\n     return\n \n \n-async def handle_event(bot: \"Bot\", event: \"Event\") -> Optional[Exception]:\n+async def handle_event(bot: \"Bot\", event: \"Event\") -> None:\n     \"\"\"\n     :\u8bf4\u660e:\n \n@@ -213,12 +213,12 @@\n         except IgnoredException as e:\n             logger.opt(colors=True).info(\n                 f\"Event {escape_tag(event.get_event_name())} is <b>ignored</b>\")\n-            return e\n+            return\n         except Exception as e:\n             logger.opt(colors=True, exception=e).error(\n                 \"<r><bg #f8bbd0>Error when running EventPreProcessors. \"\n                 \"Event ignored!</bg #f8bbd0></r>\")\n-            return e\n+            return\n \n     # Trie Match\n     _, _ = TrieRule.get_value(bot, event, state)\n@@ -248,7 +248,6 @@\n                 logger.opt(colors=True, exception=result).error(\n                     \"<r><bg #f8bbd0>Error when checking Matcher.</bg #f8bbd0></r>\"\n                 )\n-            return result\n \n     coros = list(map(lambda x: x(bot, event, state), _event_postprocessors))\n     if coros:\n@@ -260,4 +259,3 @@\n             logger.opt(colors=True, exception=e).error(\n                 \"<r><bg #f8bbd0>Error when running EventPostProcessors</bg #f8bbd0></r>\"\n             )\n-            return e\n", "issue": "Bug: event_postprocessor \u4e0d\u80fd\u5728 matcher \u8fd0\u884c\u540e\u6b63\u5e38\u6267\u884c\n**\u63cf\u8ff0\u95ee\u9898\uff1a**\r\n\r\nevent_postprocessor \u4e0d\u80fd\u5728 matcher \u8fd0\u884c\u540e\u6b63\u5e38\u6267\u884c\r\n\r\n**\u5982\u4f55\u590d\u73b0\uff1f**\r\n\r\n\u7f16\u5199\u4ee5\u4e0b\u63d2\u4ef6\r\n```python\r\nfrom nonebot import on_command, logger\r\nfrom nonebot.message import event_postprocessor\r\nfrom nonebot.typing import T_State\r\nfrom nonebot.adapters.cqhttp.event import Event, MessageEvent\r\nfrom nonebot.adapters.cqhttp.bot import Bot\r\n\r\n\r\ntest = on_command('test')\r\n\r\n\r\n@test.handle()\r\nasync def handle_test(bot: Bot, event: MessageEvent, state: T_State):\r\n    logger.opt(colors=True).info('<ly>matcher is running!</ly>')\r\n\r\n\r\n@event_postprocessor\r\nasync def handle_event_postprocessor(bot: Bot, event: Event, state: T_State):\r\n    logger.opt(colors=True).success('<ly>event_postprocessor is running!</ly>')\r\n```\r\n\r\n**\u671f\u671b\u7684\u7ed3\u679c**\r\n\r\nevent_postprocessor \u80fd\u5728\u4efb\u610f\u60c5\u51b5\u4e0b\u6b63\u5e38\u6267\u884c\r\n\r\n\u5b9e\u9645\u4e0a\u5f53 matcher \u8fd0\u884c\u540e event_postprocessor \u4f1a\u88ab\u8df3\u8fc7\r\n\r\n![image](https://user-images.githubusercontent.com/41713304/134709135-4d0d52ec-2df1-48a8-94ee-196c9c4d3da6.png)\r\n\r\n**\u5176\u4ed6\u4fe1\u606f**\r\n\r\n\u7b2c 250 \u884c `return result` \u5c06\u76f4\u63a5\u5bfc\u81f4 matcher \u8fd0\u884c\u540e event_postprocessor \u88ab\u8df3\u8fc7\r\n\r\nhttps://github.com/nonebot/nonebot2/blob/0b35d5e724a2fc7fc1e7d90499aea8a9c27e821d/nonebot/message.py#L238-L262\r\n\r\n**\u73af\u5883\u4fe1\u606f\uff1a**\r\n\r\n - OS: Windows 10 21H1\r\n - Python Version: 3.9.6\r\n - Nonebot Version: 2.0.0a15\r\n\r\n**\u534f\u8bae\u7aef\u4fe1\u606f\uff1a**\r\n\r\n - \u534f\u8bae\u7aef: \u65e0\r\n - \u534f\u8bae\u7aef\u7248\u672c: \u65e0\r\n\r\n**\u622a\u56fe\u6216\u65e5\u5fd7**\r\n\r\n\u5982\u4e0a\r\n\n", "before_files": [{"content": "\"\"\"\n\u4e8b\u4ef6\u5904\u7406\n========\n\nNoneBot \u5185\u90e8\u5904\u7406\u5e76\u6309\u4f18\u5148\u7ea7\u5206\u53d1\u4e8b\u4ef6\u7ed9\u6240\u6709\u4e8b\u4ef6\u54cd\u5e94\u5668\uff0c\u63d0\u4f9b\u4e86\u591a\u4e2a\u63d2\u69fd\u4ee5\u8fdb\u884c\u4e8b\u4ef6\u7684\u9884\u5904\u7406\u7b49\u3002\n\"\"\"\n\nimport asyncio\nfrom datetime import datetime\nfrom typing import TYPE_CHECKING, Set, Type, Optional\n\nfrom nonebot.log import logger\nfrom nonebot.rule import TrieRule\nfrom nonebot.utils import escape_tag\nfrom nonebot.matcher import Matcher, matchers\nfrom nonebot.exception import NoLogException, StopPropagation, IgnoredException\nfrom nonebot.typing import (T_State, T_RunPreProcessor, T_RunPostProcessor,\n                            T_EventPreProcessor, T_EventPostProcessor)\n\nif TYPE_CHECKING:\n    from nonebot.adapters import Bot, Event\n\n_event_preprocessors: Set[T_EventPreProcessor] = set()\n_event_postprocessors: Set[T_EventPostProcessor] = set()\n_run_preprocessors: Set[T_RunPreProcessor] = set()\n_run_postprocessors: Set[T_RunPostProcessor] = set()\n\n\ndef event_preprocessor(func: T_EventPreProcessor) -> T_EventPreProcessor:\n    \"\"\"\n    :\u8bf4\u660e:\n\n      \u4e8b\u4ef6\u9884\u5904\u7406\u3002\u88c5\u9970\u4e00\u4e2a\u51fd\u6570\uff0c\u4f7f\u5b83\u5728\u6bcf\u6b21\u63a5\u6536\u5230\u4e8b\u4ef6\u5e76\u5206\u53d1\u7ed9\u5404\u54cd\u5e94\u5668\u4e4b\u524d\u6267\u884c\u3002\n\n    :\u53c2\u6570:\n\n      \u4e8b\u4ef6\u9884\u5904\u7406\u51fd\u6570\u63a5\u6536\u4e09\u4e2a\u53c2\u6570\u3002\n\n      * ``bot: Bot``: Bot \u5bf9\u8c61\n      * ``event: Event``: Event \u5bf9\u8c61\n      * ``state: T_State``: \u5f53\u524d State\n    \"\"\"\n    _event_preprocessors.add(func)\n    return func\n\n\ndef event_postprocessor(func: T_EventPostProcessor) -> T_EventPostProcessor:\n    \"\"\"\n    :\u8bf4\u660e:\n\n      \u4e8b\u4ef6\u540e\u5904\u7406\u3002\u88c5\u9970\u4e00\u4e2a\u51fd\u6570\uff0c\u4f7f\u5b83\u5728\u6bcf\u6b21\u63a5\u6536\u5230\u4e8b\u4ef6\u5e76\u5206\u53d1\u7ed9\u5404\u54cd\u5e94\u5668\u4e4b\u540e\u6267\u884c\u3002\n\n    :\u53c2\u6570:\n\n      \u4e8b\u4ef6\u540e\u5904\u7406\u51fd\u6570\u63a5\u6536\u4e09\u4e2a\u53c2\u6570\u3002\n\n      * ``bot: Bot``: Bot \u5bf9\u8c61\n      * ``event: Event``: Event \u5bf9\u8c61\n      * ``state: T_State``: \u5f53\u524d\u4e8b\u4ef6\u8fd0\u884c\u524d State\n    \"\"\"\n    _event_postprocessors.add(func)\n    return func\n\n\ndef run_preprocessor(func: T_RunPreProcessor) -> T_RunPreProcessor:\n    \"\"\"\n    :\u8bf4\u660e:\n\n      \u8fd0\u884c\u9884\u5904\u7406\u3002\u88c5\u9970\u4e00\u4e2a\u51fd\u6570\uff0c\u4f7f\u5b83\u5728\u6bcf\u6b21\u4e8b\u4ef6\u54cd\u5e94\u5668\u8fd0\u884c\u524d\u6267\u884c\u3002\n\n    :\u53c2\u6570:\n\n      \u8fd0\u884c\u9884\u5904\u7406\u51fd\u6570\u63a5\u6536\u56db\u4e2a\u53c2\u6570\u3002\n\n      * ``matcher: Matcher``: \u5f53\u524d\u8981\u8fd0\u884c\u7684\u4e8b\u4ef6\u54cd\u5e94\u5668\n      * ``bot: Bot``: Bot \u5bf9\u8c61\n      * ``event: Event``: Event \u5bf9\u8c61\n      * ``state: T_State``: \u5f53\u524d State\n    \"\"\"\n    _run_preprocessors.add(func)\n    return func\n\n\ndef run_postprocessor(func: T_RunPostProcessor) -> T_RunPostProcessor:\n    \"\"\"\n    :\u8bf4\u660e:\n\n      \u8fd0\u884c\u540e\u5904\u7406\u3002\u88c5\u9970\u4e00\u4e2a\u51fd\u6570\uff0c\u4f7f\u5b83\u5728\u6bcf\u6b21\u4e8b\u4ef6\u54cd\u5e94\u5668\u8fd0\u884c\u540e\u6267\u884c\u3002\n\n    :\u53c2\u6570:\n\n      \u8fd0\u884c\u540e\u5904\u7406\u51fd\u6570\u63a5\u6536\u4e94\u4e2a\u53c2\u6570\u3002\n\n      * ``matcher: Matcher``: \u8fd0\u884c\u5b8c\u6bd5\u7684\u4e8b\u4ef6\u54cd\u5e94\u5668\n      * ``exception: Optional[Exception]``: \u4e8b\u4ef6\u54cd\u5e94\u5668\u8fd0\u884c\u9519\u8bef\uff08\u5982\u679c\u5b58\u5728\uff09\n      * ``bot: Bot``: Bot \u5bf9\u8c61\n      * ``event: Event``: Event \u5bf9\u8c61\n      * ``state: T_State``: \u5f53\u524d State\n    \"\"\"\n    _run_postprocessors.add(func)\n    return func\n\n\nasync def _check_matcher(priority: int, Matcher: Type[Matcher], bot: \"Bot\",\n                         event: \"Event\", state: T_State) -> None:\n    if Matcher.expire_time and datetime.now() > Matcher.expire_time:\n        try:\n            matchers[priority].remove(Matcher)\n        except Exception:\n            pass\n        return\n\n    try:\n        if not await Matcher.check_perm(\n                bot, event) or not await Matcher.check_rule(bot, event, state):\n            return\n    except Exception as e:\n        logger.opt(colors=True, exception=e).error(\n            f\"<r><bg #f8bbd0>Rule check failed for {Matcher}.</bg #f8bbd0></r>\")\n        return\n\n    if Matcher.temp:\n        try:\n            matchers[priority].remove(Matcher)\n        except Exception:\n            pass\n\n    await _run_matcher(Matcher, bot, event, state)\n\n\nasync def _run_matcher(Matcher: Type[Matcher], bot: \"Bot\", event: \"Event\",\n                       state: T_State) -> None:\n    logger.info(f\"Event will be handled by {Matcher}\")\n\n    matcher = Matcher()\n\n    coros = list(\n        map(lambda x: x(matcher, bot, event, state), _run_preprocessors))\n    if coros:\n        try:\n            await asyncio.gather(*coros)\n        except IgnoredException:\n            logger.opt(colors=True).info(\n                f\"Matcher {matcher} running is <b>cancelled</b>\")\n            return\n        except Exception as e:\n            logger.opt(colors=True, exception=e).error(\n                \"<r><bg #f8bbd0>Error when running RunPreProcessors. \"\n                \"Running cancelled!</bg #f8bbd0></r>\")\n            return\n\n    exception = None\n\n    try:\n        logger.debug(f\"Running matcher {matcher}\")\n        await matcher.run(bot, event, state)\n    except Exception as e:\n        logger.opt(colors=True, exception=e).error(\n            f\"<r><bg #f8bbd0>Running matcher {matcher} failed.</bg #f8bbd0></r>\"\n        )\n        exception = e\n\n    coros = list(\n        map(lambda x: x(matcher, exception, bot, event, state),\n            _run_postprocessors))\n    if coros:\n        try:\n            await asyncio.gather(*coros)\n        except Exception as e:\n            logger.opt(colors=True, exception=e).error(\n                \"<r><bg #f8bbd0>Error when running RunPostProcessors</bg #f8bbd0></r>\"\n            )\n\n    if matcher.block:\n        raise StopPropagation\n    return\n\n\nasync def handle_event(bot: \"Bot\", event: \"Event\") -> Optional[Exception]:\n    \"\"\"\n    :\u8bf4\u660e:\n\n       \u5904\u7406\u4e00\u4e2a\u4e8b\u4ef6\u3002\u8c03\u7528\u8be5\u51fd\u6570\u4ee5\u5b9e\u73b0\u5206\u53d1\u4e8b\u4ef6\u3002\n\n    :\u53c2\u6570:\n\n      * ``bot: Bot``: Bot \u5bf9\u8c61\n      * ``event: Event``: Event \u5bf9\u8c61\n\n    :\u793a\u4f8b:\n\n    .. code-block:: python\n\n        import asyncio\n        asyncio.create_task(handle_event(bot, event))\n    \"\"\"\n    show_log = True\n    log_msg = f\"<m>{escape_tag(bot.type.upper())} {escape_tag(bot.self_id)}</m> | \"\n    try:\n        log_msg += event.get_log_string()\n    except NoLogException:\n        show_log = False\n    if show_log:\n        logger.opt(colors=True).success(log_msg)\n\n    state = {}\n    coros = list(map(lambda x: x(bot, event, state), _event_preprocessors))\n    if coros:\n        try:\n            if show_log:\n                logger.debug(\"Running PreProcessors...\")\n            await asyncio.gather(*coros)\n        except IgnoredException as e:\n            logger.opt(colors=True).info(\n                f\"Event {escape_tag(event.get_event_name())} is <b>ignored</b>\")\n            return e\n        except Exception as e:\n            logger.opt(colors=True, exception=e).error(\n                \"<r><bg #f8bbd0>Error when running EventPreProcessors. \"\n                \"Event ignored!</bg #f8bbd0></r>\")\n            return e\n\n    # Trie Match\n    _, _ = TrieRule.get_value(bot, event, state)\n\n    break_flag = False\n    for priority in sorted(matchers.keys()):\n        if break_flag:\n            break\n\n        if show_log:\n            logger.debug(f\"Checking for matchers in priority {priority}...\")\n\n        pending_tasks = [\n            _check_matcher(priority, matcher, bot, event, state.copy())\n            for matcher in matchers[priority]\n        ]\n\n        results = await asyncio.gather(*pending_tasks, return_exceptions=True)\n\n        for result in results:\n            if not isinstance(result, Exception):\n                continue\n            if isinstance(result, StopPropagation):\n                break_flag = True\n                logger.debug(\"Stop event propagation\")\n            else:\n                logger.opt(colors=True, exception=result).error(\n                    \"<r><bg #f8bbd0>Error when checking Matcher.</bg #f8bbd0></r>\"\n                )\n            return result\n\n    coros = list(map(lambda x: x(bot, event, state), _event_postprocessors))\n    if coros:\n        try:\n            if show_log:\n                logger.debug(\"Running PostProcessors...\")\n            await asyncio.gather(*coros)\n        except Exception as e:\n            logger.opt(colors=True, exception=e).error(\n                \"<r><bg #f8bbd0>Error when running EventPostProcessors</bg #f8bbd0></r>\"\n            )\n            return e\n", "path": "nonebot/message.py"}], "after_files": [{"content": "\"\"\"\n\u4e8b\u4ef6\u5904\u7406\n========\n\nNoneBot \u5185\u90e8\u5904\u7406\u5e76\u6309\u4f18\u5148\u7ea7\u5206\u53d1\u4e8b\u4ef6\u7ed9\u6240\u6709\u4e8b\u4ef6\u54cd\u5e94\u5668\uff0c\u63d0\u4f9b\u4e86\u591a\u4e2a\u63d2\u69fd\u4ee5\u8fdb\u884c\u4e8b\u4ef6\u7684\u9884\u5904\u7406\u7b49\u3002\n\"\"\"\n\nimport asyncio\nfrom datetime import datetime\nfrom typing import TYPE_CHECKING, Set, Type, Optional\n\nfrom nonebot.log import logger\nfrom nonebot.rule import TrieRule\nfrom nonebot.utils import escape_tag\nfrom nonebot.matcher import Matcher, matchers\nfrom nonebot.exception import NoLogException, StopPropagation, IgnoredException\nfrom nonebot.typing import (T_State, T_RunPreProcessor, T_RunPostProcessor,\n                            T_EventPreProcessor, T_EventPostProcessor)\n\nif TYPE_CHECKING:\n    from nonebot.adapters import Bot, Event\n\n_event_preprocessors: Set[T_EventPreProcessor] = set()\n_event_postprocessors: Set[T_EventPostProcessor] = set()\n_run_preprocessors: Set[T_RunPreProcessor] = set()\n_run_postprocessors: Set[T_RunPostProcessor] = set()\n\n\ndef event_preprocessor(func: T_EventPreProcessor) -> T_EventPreProcessor:\n    \"\"\"\n    :\u8bf4\u660e:\n\n      \u4e8b\u4ef6\u9884\u5904\u7406\u3002\u88c5\u9970\u4e00\u4e2a\u51fd\u6570\uff0c\u4f7f\u5b83\u5728\u6bcf\u6b21\u63a5\u6536\u5230\u4e8b\u4ef6\u5e76\u5206\u53d1\u7ed9\u5404\u54cd\u5e94\u5668\u4e4b\u524d\u6267\u884c\u3002\n\n    :\u53c2\u6570:\n\n      \u4e8b\u4ef6\u9884\u5904\u7406\u51fd\u6570\u63a5\u6536\u4e09\u4e2a\u53c2\u6570\u3002\n\n      * ``bot: Bot``: Bot \u5bf9\u8c61\n      * ``event: Event``: Event \u5bf9\u8c61\n      * ``state: T_State``: \u5f53\u524d State\n    \"\"\"\n    _event_preprocessors.add(func)\n    return func\n\n\ndef event_postprocessor(func: T_EventPostProcessor) -> T_EventPostProcessor:\n    \"\"\"\n    :\u8bf4\u660e:\n\n      \u4e8b\u4ef6\u540e\u5904\u7406\u3002\u88c5\u9970\u4e00\u4e2a\u51fd\u6570\uff0c\u4f7f\u5b83\u5728\u6bcf\u6b21\u63a5\u6536\u5230\u4e8b\u4ef6\u5e76\u5206\u53d1\u7ed9\u5404\u54cd\u5e94\u5668\u4e4b\u540e\u6267\u884c\u3002\n\n    :\u53c2\u6570:\n\n      \u4e8b\u4ef6\u540e\u5904\u7406\u51fd\u6570\u63a5\u6536\u4e09\u4e2a\u53c2\u6570\u3002\n\n      * ``bot: Bot``: Bot \u5bf9\u8c61\n      * ``event: Event``: Event \u5bf9\u8c61\n      * ``state: T_State``: \u5f53\u524d\u4e8b\u4ef6\u8fd0\u884c\u524d State\n    \"\"\"\n    _event_postprocessors.add(func)\n    return func\n\n\ndef run_preprocessor(func: T_RunPreProcessor) -> T_RunPreProcessor:\n    \"\"\"\n    :\u8bf4\u660e:\n\n      \u8fd0\u884c\u9884\u5904\u7406\u3002\u88c5\u9970\u4e00\u4e2a\u51fd\u6570\uff0c\u4f7f\u5b83\u5728\u6bcf\u6b21\u4e8b\u4ef6\u54cd\u5e94\u5668\u8fd0\u884c\u524d\u6267\u884c\u3002\n\n    :\u53c2\u6570:\n\n      \u8fd0\u884c\u9884\u5904\u7406\u51fd\u6570\u63a5\u6536\u56db\u4e2a\u53c2\u6570\u3002\n\n      * ``matcher: Matcher``: \u5f53\u524d\u8981\u8fd0\u884c\u7684\u4e8b\u4ef6\u54cd\u5e94\u5668\n      * ``bot: Bot``: Bot \u5bf9\u8c61\n      * ``event: Event``: Event \u5bf9\u8c61\n      * ``state: T_State``: \u5f53\u524d State\n    \"\"\"\n    _run_preprocessors.add(func)\n    return func\n\n\ndef run_postprocessor(func: T_RunPostProcessor) -> T_RunPostProcessor:\n    \"\"\"\n    :\u8bf4\u660e:\n\n      \u8fd0\u884c\u540e\u5904\u7406\u3002\u88c5\u9970\u4e00\u4e2a\u51fd\u6570\uff0c\u4f7f\u5b83\u5728\u6bcf\u6b21\u4e8b\u4ef6\u54cd\u5e94\u5668\u8fd0\u884c\u540e\u6267\u884c\u3002\n\n    :\u53c2\u6570:\n\n      \u8fd0\u884c\u540e\u5904\u7406\u51fd\u6570\u63a5\u6536\u4e94\u4e2a\u53c2\u6570\u3002\n\n      * ``matcher: Matcher``: \u8fd0\u884c\u5b8c\u6bd5\u7684\u4e8b\u4ef6\u54cd\u5e94\u5668\n      * ``exception: Optional[Exception]``: \u4e8b\u4ef6\u54cd\u5e94\u5668\u8fd0\u884c\u9519\u8bef\uff08\u5982\u679c\u5b58\u5728\uff09\n      * ``bot: Bot``: Bot \u5bf9\u8c61\n      * ``event: Event``: Event \u5bf9\u8c61\n      * ``state: T_State``: \u5f53\u524d State\n    \"\"\"\n    _run_postprocessors.add(func)\n    return func\n\n\nasync def _check_matcher(priority: int, Matcher: Type[Matcher], bot: \"Bot\",\n                         event: \"Event\", state: T_State) -> None:\n    if Matcher.expire_time and datetime.now() > Matcher.expire_time:\n        try:\n            matchers[priority].remove(Matcher)\n        except Exception:\n            pass\n        return\n\n    try:\n        if not await Matcher.check_perm(\n                bot, event) or not await Matcher.check_rule(bot, event, state):\n            return\n    except Exception as e:\n        logger.opt(colors=True, exception=e).error(\n            f\"<r><bg #f8bbd0>Rule check failed for {Matcher}.</bg #f8bbd0></r>\")\n        return\n\n    if Matcher.temp:\n        try:\n            matchers[priority].remove(Matcher)\n        except Exception:\n            pass\n\n    await _run_matcher(Matcher, bot, event, state)\n\n\nasync def _run_matcher(Matcher: Type[Matcher], bot: \"Bot\", event: \"Event\",\n                       state: T_State) -> None:\n    logger.info(f\"Event will be handled by {Matcher}\")\n\n    matcher = Matcher()\n\n    coros = list(\n        map(lambda x: x(matcher, bot, event, state), _run_preprocessors))\n    if coros:\n        try:\n            await asyncio.gather(*coros)\n        except IgnoredException:\n            logger.opt(colors=True).info(\n                f\"Matcher {matcher} running is <b>cancelled</b>\")\n            return\n        except Exception as e:\n            logger.opt(colors=True, exception=e).error(\n                \"<r><bg #f8bbd0>Error when running RunPreProcessors. \"\n                \"Running cancelled!</bg #f8bbd0></r>\")\n            return\n\n    exception = None\n\n    try:\n        logger.debug(f\"Running matcher {matcher}\")\n        await matcher.run(bot, event, state)\n    except Exception as e:\n        logger.opt(colors=True, exception=e).error(\n            f\"<r><bg #f8bbd0>Running matcher {matcher} failed.</bg #f8bbd0></r>\"\n        )\n        exception = e\n\n    coros = list(\n        map(lambda x: x(matcher, exception, bot, event, state),\n            _run_postprocessors))\n    if coros:\n        try:\n            await asyncio.gather(*coros)\n        except Exception as e:\n            logger.opt(colors=True, exception=e).error(\n                \"<r><bg #f8bbd0>Error when running RunPostProcessors</bg #f8bbd0></r>\"\n            )\n\n    if matcher.block:\n        raise StopPropagation\n    return\n\n\nasync def handle_event(bot: \"Bot\", event: \"Event\") -> None:\n    \"\"\"\n    :\u8bf4\u660e:\n\n       \u5904\u7406\u4e00\u4e2a\u4e8b\u4ef6\u3002\u8c03\u7528\u8be5\u51fd\u6570\u4ee5\u5b9e\u73b0\u5206\u53d1\u4e8b\u4ef6\u3002\n\n    :\u53c2\u6570:\n\n      * ``bot: Bot``: Bot \u5bf9\u8c61\n      * ``event: Event``: Event \u5bf9\u8c61\n\n    :\u793a\u4f8b:\n\n    .. code-block:: python\n\n        import asyncio\n        asyncio.create_task(handle_event(bot, event))\n    \"\"\"\n    show_log = True\n    log_msg = f\"<m>{escape_tag(bot.type.upper())} {escape_tag(bot.self_id)}</m> | \"\n    try:\n        log_msg += event.get_log_string()\n    except NoLogException:\n        show_log = False\n    if show_log:\n        logger.opt(colors=True).success(log_msg)\n\n    state = {}\n    coros = list(map(lambda x: x(bot, event, state), _event_preprocessors))\n    if coros:\n        try:\n            if show_log:\n                logger.debug(\"Running PreProcessors...\")\n            await asyncio.gather(*coros)\n        except IgnoredException as e:\n            logger.opt(colors=True).info(\n                f\"Event {escape_tag(event.get_event_name())} is <b>ignored</b>\")\n            return\n        except Exception as e:\n            logger.opt(colors=True, exception=e).error(\n                \"<r><bg #f8bbd0>Error when running EventPreProcessors. \"\n                \"Event ignored!</bg #f8bbd0></r>\")\n            return\n\n    # Trie Match\n    _, _ = TrieRule.get_value(bot, event, state)\n\n    break_flag = False\n    for priority in sorted(matchers.keys()):\n        if break_flag:\n            break\n\n        if show_log:\n            logger.debug(f\"Checking for matchers in priority {priority}...\")\n\n        pending_tasks = [\n            _check_matcher(priority, matcher, bot, event, state.copy())\n            for matcher in matchers[priority]\n        ]\n\n        results = await asyncio.gather(*pending_tasks, return_exceptions=True)\n\n        for result in results:\n            if not isinstance(result, Exception):\n                continue\n            if isinstance(result, StopPropagation):\n                break_flag = True\n                logger.debug(\"Stop event propagation\")\n            else:\n                logger.opt(colors=True, exception=result).error(\n                    \"<r><bg #f8bbd0>Error when checking Matcher.</bg #f8bbd0></r>\"\n                )\n\n    coros = list(map(lambda x: x(bot, event, state), _event_postprocessors))\n    if coros:\n        try:\n            if show_log:\n                logger.debug(\"Running PostProcessors...\")\n            await asyncio.gather(*coros)\n        except Exception as e:\n            logger.opt(colors=True, exception=e).error(\n                \"<r><bg #f8bbd0>Error when running EventPostProcessors</bg #f8bbd0></r>\"\n            )\n", "path": "nonebot/message.py"}]}