运行事件预处理。 参数: bot: Bot 对象 event: Event 对象 state: 会话状态 stack: 异步上下文栈 dependency_cache: 依赖缓存 show_log: 是否显示日志 返回: 是否继续处理事件
(
bot: "Bot",
event: "Event",
state: T_State,
stack: AsyncExitStack | None = None,
dependency_cache: T_DependencyCache | None = None,
show_log: bool = True,
)
| 151 | |
| 152 | |
| 153 | async def _apply_event_preprocessors( |
| 154 | bot: "Bot", |
| 155 | event: "Event", |
| 156 | state: T_State, |
| 157 | stack: AsyncExitStack | None = None, |
| 158 | dependency_cache: T_DependencyCache | None = None, |
| 159 | show_log: bool = True, |
| 160 | ) -> bool: |
| 161 | """运行事件预处理。 |
| 162 | |
| 163 | 参数: |
| 164 | bot: Bot 对象 |
| 165 | event: Event 对象 |
| 166 | state: 会话状态 |
| 167 | stack: 异步上下文栈 |
| 168 | dependency_cache: 依赖缓存 |
| 169 | show_log: 是否显示日志 |
| 170 | |
| 171 | 返回: |
| 172 | 是否继续处理事件 |
| 173 | """ |
| 174 | if not _event_preprocessors: |
| 175 | return True |
| 176 | |
| 177 | if show_log: |
| 178 | logger.debug("Running PreProcessors...") |
| 179 | |
| 180 | with catch( |
| 181 | { |
| 182 | IgnoredException: _handle_ignored_exception( |
| 183 | f"Event {escape_tag(event.get_event_name())} is <b>ignored</b>" |
| 184 | ), |
| 185 | Exception: _handle_exception( |
| 186 | "<r><bg #f8bbd0>Error when running EventPreProcessors. " |
| 187 | "Event ignored!</bg #f8bbd0></r>" |
| 188 | ), |
| 189 | } |
| 190 | ): |
| 191 | async with anyio.create_task_group() as tg: |
| 192 | for proc in _event_preprocessors: |
| 193 | tg.start_soon( |
| 194 | run_coro_with_catch, |
| 195 | proc( |
| 196 | bot=bot, |
| 197 | event=event, |
| 198 | state=state, |
| 199 | stack=stack, |
| 200 | dependency_cache=dependency_cache, |
| 201 | ), |
| 202 | (SkippedException,), |
| 203 | ) |
| 204 | |
| 205 | return True |
| 206 | |
| 207 | return False |
| 208 | |
| 209 | |
| 210 | async def _apply_event_postprocessors( |
no test coverage detected