From f9a6c685df504034df78c202bfa1e8b2af8af6e4 Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Sun, 2 Mar 2025 01:16:14 +0800 Subject: [PATCH] =?UTF-8?q?=E2=80=BC=EF=B8=8Ffix:=20=E4=BF=AE=E5=A4=8D?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=20AsyncGenerator=20=E5=9C=A8=E6=B2=A1?= =?UTF-8?q?=E6=9C=89=E6=89=A7=E8=A1=8C=20yield=20=E8=AF=AD=E5=8F=A5?= =?UTF-8?q?=E7=9A=84=E6=83=85=E5=86=B5=E4=B8=8B=E8=AE=BE=E7=BD=AE=E4=BA=8B?= =?UTF-8?q?=E4=BB=B6=E7=BB=93=E6=9E=9C=E6=97=A0=E6=B3=95=E8=A2=AB=E5=A4=84?= =?UTF-8?q?=E7=90=86=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/pipeline/stage.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/astrbot/core/pipeline/stage.py b/astrbot/core/pipeline/stage.py index fc31786b2..88b6e7943 100644 --- a/astrbot/core/pipeline/stage.py +++ b/astrbot/core/pipeline/stage.py @@ -51,13 +51,17 @@ class Stage(abc.ABC): ready_to_call = handler(event, ctx.plugin_manager.context, *args, **kwargs) if isinstance(ready_to_call, AsyncGenerator): + _has_yielded = False async for ret in ready_to_call: # 如果处理函数是生成器,返回值只能是 MessageEventResult 或者 None(无返回值) + _has_yielded = True if isinstance(ret, (MessageEventResult, CommandResult)): event.set_result(ret) yield else: yield ret + if not _has_yielded: + yield elif inspect.iscoroutine(ready_to_call): # 如果只是一个 coroutine ret = await ready_to_call