MCPcopy Index your code
hub / github.com/nonebot/nonebot2 / _apply_run_preprocessors

Function _apply_run_preprocessors

nonebot/message.py:256–312  ·  view source on GitHub ↗

运行事件响应器运行前处理。 参数: bot: Bot 对象 event: Event 对象 state: 会话状态 matcher: 事件响应器 stack: 异步上下文栈 dependency_cache: 依赖缓存 返回: 是否继续处理事件

(
    bot: "Bot",
    event: "Event",
    state: T_State,
    matcher: Matcher,
    stack: AsyncExitStack | None = None,
    dependency_cache: T_DependencyCache | None = None,
)

Source from the content-addressed store, hash-verified

254
255
256async def _apply_run_preprocessors(
257 bot: "Bot",
258 event: "Event",
259 state: T_State,
260 matcher: Matcher,
261 stack: AsyncExitStack | None = None,
262 dependency_cache: T_DependencyCache | None = None,
263) -> bool:
264 """运行事件响应器运行前处理。
265
266 参数:
267 bot: Bot 对象
268 event: Event 对象
269 state: 会话状态
270 matcher: 事件响应器
271 stack: 异步上下文栈
272 dependency_cache: 依赖缓存
273
274 返回:
275 是否继续处理事件
276 """
277 if not _run_preprocessors:
278 return True
279
280 # ensure matcher function can be correctly called
281 with (
282 matcher.ensure_context(bot, event),
283 catch(
284 {
285 IgnoredException: _handle_ignored_exception(
286 f"{matcher} running is <b>cancelled</b>"
287 ),
288 Exception: _handle_exception(
289 "<r><bg #f8bbd0>Error when running RunPreProcessors. "
290 "Running cancelled!</bg #f8bbd0></r>"
291 ),
292 }
293 ),
294 ):
295 async with anyio.create_task_group() as tg:
296 for proc in _run_preprocessors:
297 tg.start_soon(
298 run_coro_with_catch,
299 proc(
300 matcher=matcher,
301 bot=bot,
302 event=event,
303 state=state,
304 stack=stack,
305 dependency_cache=dependency_cache,
306 ),
307 (SkippedException,),
308 )
309
310 return True
311
312 return False
313

Callers 1

_run_matcherFunction · 0.85

Calls 3

_handle_exceptionFunction · 0.85
ensure_contextMethod · 0.80

Tested by

no test coverage detected