feat(action): 将回复处理逻辑封装为异步函数,优化代码结构和可读性

This commit is contained in:
Windpicker-owo
2025-11-10 13:44:52 +08:00
parent 882f93c886
commit 259a744a3b

View File

@@ -306,6 +306,7 @@ class ChatterActionManager:
if action_name == "respond" and should_quote_reply is None: if action_name == "respond" and should_quote_reply is None:
should_quote_reply = False should_quote_reply = False
async def _after_reply():
# 发送并存储回复 # 发送并存储回复
loop_info, reply_text, cycle_timers_reply = await self._send_and_store_reply( loop_info, reply_text, cycle_timers_reply = await self._send_and_store_reply(
chat_stream, chat_stream,
@@ -318,7 +319,7 @@ class ChatterActionManager:
should_quote_reply, # 传递should_quote_reply参数 should_quote_reply, # 传递should_quote_reply参数
) )
# 记录回复动作到目标消息(改为同步等待) # 记录回复动作到目标消息
await self._record_action_to_message(chat_stream, action_name, target_message, action_data) await self._record_action_to_message(chat_stream, action_name, target_message, action_data)
if clear_unread_messages: if clear_unread_messages:
@@ -327,6 +328,8 @@ class ChatterActionManager:
# 回复成功,重置打断计数(改为同步等待) # 回复成功,重置打断计数(改为同步等待)
await self._reset_interruption_count_after_action(chat_stream.stream_id) await self._reset_interruption_count_after_action(chat_stream.stream_id)
return loop_info, reply_text, cycle_timers_reply
loop_info, reply_text, cycle_timers_reply = await asyncio.create_task(_after_reply())
return {"action_type": action_name, "success": True, "reply_text": reply_text, "loop_info": loop_info} return {"action_type": action_name, "success": True, "reply_text": reply_text, "loop_info": loop_info}
except Exception as e: except Exception as e: