运行事件响应器。 临时事件响应器将在运行前被**销毁**。 参数: Matcher: 事件响应器 bot: Bot 对象 event: Event 对象 state: 会话状态 stack: 异步上下文栈 dependency_cache: 依赖缓存 异常: StopPropagation: 阻止事件继续传播
(
Matcher: type[Matcher],
bot: "Bot",
event: "Event",
state: T_State,
stack: AsyncExitStack | None = None,
dependency_cache: T_DependencyCache | None = None,
)
| 413 | |
| 414 | |
| 415 | async def _run_matcher( |
| 416 | Matcher: type[Matcher], |
| 417 | bot: "Bot", |
| 418 | event: "Event", |
| 419 | state: T_State, |
| 420 | stack: AsyncExitStack | None = None, |
| 421 | dependency_cache: T_DependencyCache | None = None, |
| 422 | ) -> None: |
| 423 | """运行事件响应器。 |
| 424 | |
| 425 | 临时事件响应器将在运行前被**销毁**。 |
| 426 | |
| 427 | 参数: |
| 428 | Matcher: 事件响应器 |
| 429 | bot: Bot 对象 |
| 430 | event: Event 对象 |
| 431 | state: 会话状态 |
| 432 | stack: 异步上下文栈 |
| 433 | dependency_cache: 依赖缓存 |
| 434 | |
| 435 | 异常: |
| 436 | StopPropagation: 阻止事件继续传播 |
| 437 | """ |
| 438 | logger.info(f"Event will be handled by {Matcher}") |
| 439 | |
| 440 | if Matcher.temp: |
| 441 | with contextlib.suppress(Exception): |
| 442 | Matcher.destroy() |
| 443 | |
| 444 | matcher = Matcher() |
| 445 | |
| 446 | if not await _apply_run_preprocessors( |
| 447 | bot=bot, |
| 448 | event=event, |
| 449 | state=state, |
| 450 | matcher=matcher, |
| 451 | stack=stack, |
| 452 | dependency_cache=dependency_cache, |
| 453 | ): |
| 454 | return |
| 455 | |
| 456 | exception = None |
| 457 | |
| 458 | logger.debug(f"Running {matcher}") |
| 459 | |
| 460 | try: |
| 461 | await matcher.run(bot, event, state, stack, dependency_cache) |
| 462 | except Exception as e: |
| 463 | logger.opt(colors=True, exception=e).error( |
| 464 | f"<r><bg #f8bbd0>Running {matcher} failed.</bg #f8bbd0></r>" |
| 465 | ) |
| 466 | exception = e |
| 467 | |
| 468 | await _apply_run_postprocessors( |
| 469 | bot=bot, |
| 470 | event=event, |
| 471 | matcher=matcher, |
| 472 | exception=exception, |
no test coverage detected