| 820 | current_matcher.reset(m_t) |
| 821 | |
| 822 | async def simple_run( |
| 823 | self, |
| 824 | bot: Bot, |
| 825 | event: Event, |
| 826 | state: T_State, |
| 827 | stack: AsyncExitStack | None = None, |
| 828 | dependency_cache: T_DependencyCache | None = None, |
| 829 | ): |
| 830 | logger.trace( |
| 831 | f"{self} run with incoming args: " |
| 832 | f"bot={bot}, event={event!r}, state={state!r}" |
| 833 | ) |
| 834 | |
| 835 | def _handle_stop_propagation(exc_group: BaseExceptionGroup[StopPropagation]): |
| 836 | self.block = True |
| 837 | |
| 838 | with self.ensure_context(bot, event): |
| 839 | try: |
| 840 | with catch({StopPropagation: _handle_stop_propagation}): |
| 841 | # Refresh preprocess state |
| 842 | self.state.update(state) |
| 843 | |
| 844 | while self.remain_handlers: |
| 845 | handler = self.remain_handlers.pop(0) |
| 846 | current_handler.set(handler) |
| 847 | logger.debug(f"Running handler {handler}") |
| 848 | |
| 849 | def _handle_skipped( |
| 850 | exc_group: BaseExceptionGroup[SkippedException], |
| 851 | ): |
| 852 | logger.debug(f"Handler {handler} skipped") |
| 853 | |
| 854 | with catch({SkippedException: _handle_skipped}): |
| 855 | await handler( |
| 856 | matcher=self, |
| 857 | bot=bot, |
| 858 | event=event, |
| 859 | state=self.state, |
| 860 | stack=stack, |
| 861 | dependency_cache=dependency_cache, |
| 862 | ) |
| 863 | finally: |
| 864 | logger.info(f"{self} running complete") |
| 865 | |
| 866 | # 运行handlers |
| 867 | async def run( |