fix: remove deprecated pre_send and post_send calls for specific platforms

This commit is contained in:
Soulter
2025-06-27 14:31:35 +08:00
parent 1ce95c473d
commit 62d8cf79ef
5 changed files with 17 additions and 21 deletions

View File

@@ -128,9 +128,7 @@ class RespondStage(Stage):
"streaming_segmented", False "streaming_segmented", False
) )
logger.info(f"应用流式输出({event.get_platform_name()})") logger.info(f"应用流式输出({event.get_platform_name()})")
await event._pre_send()
await event.send_streaming(result.async_stream, use_fallback) await event.send_streaming(result.async_stream, use_fallback)
await event._post_send()
return return
elif len(result.chain) > 0: elif len(result.chain) > 0:
# 检查路径映射 # 检查路径映射
@@ -141,8 +139,6 @@ class RespondStage(Stage):
component.file = path_Mapping(mappings, component.file) component.file = path_Mapping(mappings, component.file)
event.get_result().chain[idx] = component event.get_result().chain[idx] = component
await event._pre_send()
# 检查消息链是否为空 # 检查消息链是否为空
try: try:
if await self._is_empty_message_chain(result.chain): 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) c for c in result.chain if not isinstance(c, Comp.Record)
] ]
if self.enable_seg and ( if (
(self.only_llm_result and result.is_llm_result()) self.enable_seg
or not self.only_llm_result 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 = [] decorated_comps = []
if self.reply_with_mention: if self.reply_with_mention:
@@ -207,14 +208,9 @@ class RespondStage(Stage):
logger.error(traceback.format_exc()) logger.error(traceback.format_exc())
logger.error(f"发送消息失败: {e} chain: {result.chain}") logger.error(f"发送消息失败: {e} chain: {result.chain}")
await event._post_send()
logger.info( logger.info(
f"AstrBot -> {event.get_sender_name()}/{event.get_sender_id()}: {event._outline_chain(result.chain)}" 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( handlers = star_handlers_registry.get_handlers_by_event_type(
EventType.OnAfterMessageSentEvent, platform_id=event.get_platform_id() EventType.OnAfterMessageSentEvent, platform_id=event.get_platform_id()

View File

@@ -141,7 +141,11 @@ class ResultDecorateStage(Stage):
break 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 ( if (
self.only_llm_result and result.is_llm_result() self.only_llm_result and result.is_llm_result()
) or not self.only_llm_result: ) or not self.only_llm_result:

View File

@@ -125,7 +125,6 @@ class WakingCheckStage(Stage):
f"插件 {star_map[handler.handler_module_path].name}: {e}" f"插件 {star_map[handler.handler_module_path].name}: {e}"
) )
) )
await event._post_send()
event.stop_event() event.stop_event()
passed = False passed = False
break break
@@ -140,7 +139,6 @@ class WakingCheckStage(Stage):
f"您(ID: {event.get_sender_id()})的权限不足以使用此指令。通过 /sid 获取 ID 并请管理员添加。" f"您(ID: {event.get_sender_id()})的权限不足以使用此指令。通过 /sid 获取 ID 并请管理员添加。"
) )
) )
await event._post_send()
logger.info( logger.info(
f"触发 {star_map[handler.handler_module_path].name} 时, 用户(ID={event.get_sender_id()}) 权限不足。" f"触发 {star_map[handler.handler_module_path].name} 时, 用户(ID={event.get_sender_id()}) 权限不足。"
) )

View File

@@ -235,10 +235,10 @@ class AstrMessageEvent(abc.ABC):
self._has_send_oper = True self._has_send_oper = True
async def _pre_send(self): async def _pre_send(self):
"""调度器会在执行 send() 前调用该方法""" """调度器会在执行 send() 前调用该方法 deprecated in v3.5.18"""
async def _post_send(self): async def _post_send(self):
"""调度器会在执行 send() 后调用该方法""" """调度器会在执行 send() 后调用该方法 deprecated in v3.5.18"""
def set_result(self, result: Union[MessageEventResult, str]): def set_result(self, result: Union[MessageEventResult, str]):
"""设置消息事件的结果。 """设置消息事件的结果。

View File

@@ -28,10 +28,8 @@ class QQOfficialMessageEvent(AstrMessageEvent):
self.send_buffer = None self.send_buffer = None
async def send(self, message: MessageChain): async def send(self, message: MessageChain):
if not self.send_buffer: self.send_buffer = message
self.send_buffer = message await self._post_send()
else:
self.send_buffer.chain.extend(message.chain)
async def send_streaming(self, generator, use_fallback: bool = False): async def send_streaming(self, generator, use_fallback: bool = False):
"""流式输出仅支持消息列表私聊""" """流式输出仅支持消息列表私聊"""