From 62d8cf79ef0a6e68cf62f0aa90c5b178f93b370f Mon Sep 17 00:00:00 2001 From: Soulter <905617992@qq.com> Date: Fri, 27 Jun 2025 14:31:35 +0800 Subject: [PATCH] fix: remove deprecated pre_send and post_send calls for specific platforms --- astrbot/core/pipeline/respond/stage.py | 20 ++++++++----------- .../core/pipeline/result_decorate/stage.py | 6 +++++- astrbot/core/pipeline/waking_check/stage.py | 2 -- astrbot/core/platform/astr_message_event.py | 4 ++-- .../qqofficial/qqofficial_message_event.py | 6 ++---- 5 files changed, 17 insertions(+), 21 deletions(-) diff --git a/astrbot/core/pipeline/respond/stage.py b/astrbot/core/pipeline/respond/stage.py index ad0a62c8b..794095268 100644 --- a/astrbot/core/pipeline/respond/stage.py +++ b/astrbot/core/pipeline/respond/stage.py @@ -128,9 +128,7 @@ class RespondStage(Stage): "streaming_segmented", False ) logger.info(f"应用流式输出({event.get_platform_name()})") - await event._pre_send() await event.send_streaming(result.async_stream, use_fallback) - await event._post_send() return elif len(result.chain) > 0: # 检查路径映射 @@ -141,8 +139,6 @@ class RespondStage(Stage): component.file = path_Mapping(mappings, component.file) event.get_result().chain[idx] = component - await event._pre_send() - # 检查消息链是否为空 try: if await self._is_empty_message_chain(result.chain): @@ -158,9 +154,14 @@ class RespondStage(Stage): c for c in result.chain if not isinstance(c, Comp.Record) ] - if self.enable_seg and ( - (self.only_llm_result and result.is_llm_result()) - or not self.only_llm_result + if ( + self.enable_seg + and ( + (self.only_llm_result and result.is_llm_result()) + or not self.only_llm_result + ) + and event.get_platform_name() + not in ["qq_official", "weixin_official_account", "dingtalk"] ): decorated_comps = [] if self.reply_with_mention: @@ -207,14 +208,9 @@ class RespondStage(Stage): logger.error(traceback.format_exc()) logger.error(f"发送消息失败: {e} chain: {result.chain}") - await event._post_send() logger.info( f"AstrBot -> {event.get_sender_name()}/{event.get_sender_id()}: {event._outline_chain(result.chain)}" ) - else: - # 对使用 qq_official 适配器的会话控制器发送消息的特殊处理 - if event.get_platform_name() == "qq_official": - await event._post_send() handlers = star_handlers_registry.get_handlers_by_event_type( EventType.OnAfterMessageSentEvent, platform_id=event.get_platform_id() diff --git a/astrbot/core/pipeline/result_decorate/stage.py b/astrbot/core/pipeline/result_decorate/stage.py index 7a12788a0..23a9bed4b 100644 --- a/astrbot/core/pipeline/result_decorate/stage.py +++ b/astrbot/core/pipeline/result_decorate/stage.py @@ -141,7 +141,11 @@ class ResultDecorateStage(Stage): break # 分段回复 - if self.enable_segmented_reply: + if self.enable_segmented_reply and event.get_platform_name() not in [ + "qq_official", + "weixin_official_account", + "dingtalk", + ]: if ( self.only_llm_result and result.is_llm_result() ) or not self.only_llm_result: diff --git a/astrbot/core/pipeline/waking_check/stage.py b/astrbot/core/pipeline/waking_check/stage.py index e654d07ce..14a9423fb 100644 --- a/astrbot/core/pipeline/waking_check/stage.py +++ b/astrbot/core/pipeline/waking_check/stage.py @@ -125,7 +125,6 @@ class WakingCheckStage(Stage): f"插件 {star_map[handler.handler_module_path].name}: {e}" ) ) - await event._post_send() event.stop_event() passed = False break @@ -140,7 +139,6 @@ class WakingCheckStage(Stage): f"您(ID: {event.get_sender_id()})的权限不足以使用此指令。通过 /sid 获取 ID 并请管理员添加。" ) ) - await event._post_send() logger.info( f"触发 {star_map[handler.handler_module_path].name} 时, 用户(ID={event.get_sender_id()}) 权限不足。" ) diff --git a/astrbot/core/platform/astr_message_event.py b/astrbot/core/platform/astr_message_event.py index 40aab6443..7a3102de5 100644 --- a/astrbot/core/platform/astr_message_event.py +++ b/astrbot/core/platform/astr_message_event.py @@ -235,10 +235,10 @@ class AstrMessageEvent(abc.ABC): self._has_send_oper = True async def _pre_send(self): - """调度器会在执行 send() 前调用该方法""" + """调度器会在执行 send() 前调用该方法 deprecated in v3.5.18""" async def _post_send(self): - """调度器会在执行 send() 后调用该方法""" + """调度器会在执行 send() 后调用该方法 deprecated in v3.5.18""" def set_result(self, result: Union[MessageEventResult, str]): """设置消息事件的结果。 diff --git a/astrbot/core/platform/sources/qqofficial/qqofficial_message_event.py b/astrbot/core/platform/sources/qqofficial/qqofficial_message_event.py index d55c2671b..9bb68a040 100644 --- a/astrbot/core/platform/sources/qqofficial/qqofficial_message_event.py +++ b/astrbot/core/platform/sources/qqofficial/qqofficial_message_event.py @@ -28,10 +28,8 @@ class QQOfficialMessageEvent(AstrMessageEvent): self.send_buffer = None async def send(self, message: MessageChain): - if not self.send_buffer: - self.send_buffer = message - else: - self.send_buffer.chain.extend(message.chain) + self.send_buffer = message + await self._post_send() async def send_streaming(self, generator, use_fallback: bool = False): """流式输出仅支持消息列表私聊"""