refc:重构插件api,补全文档,合并expressor和replyer,分离reply和sender,新log浏览器

This commit is contained in:
SengokuCola
2025-06-19 20:20:34 +08:00
parent 7e05ede846
commit ab28b94e33
63 changed files with 5285 additions and 8316 deletions

View File

@@ -15,7 +15,7 @@ install(extra_lines=3)
logger = get_logger("sender")
async def send_message(message: MessageSending) -> str:
async def send_message(message: MessageSending) -> bool:
"""合并后的消息发送函数包含WS发送和日志记录"""
message_preview = truncate_message(message.processed_plain_text, max_length=40)
@@ -23,7 +23,7 @@ async def send_message(message: MessageSending) -> str:
# 直接调用API发送消息
await get_global_api().send_message(message)
logger.info(f"已将消息 '{message_preview}' 发往平台'{message.message_info.platform}'")
return message.processed_plain_text
return True
except Exception as e:
logger.error(f"发送消息 '{message_preview}' 发往平台'{message.message_info.platform}' 失败: {str(e)}")
@@ -73,17 +73,15 @@ class HeartFCSender:
thinking_message = self.thinking_messages.get(chat_id, {}).get(message_id)
return thinking_message.thinking_start_time if thinking_message else None
async def send_message(self, message: MessageSending, has_thinking=False, typing=False, set_reply=False):
async def send_message(self, message: MessageSending, typing=False, set_reply=False, storage_message=True):
"""
处理、发送并存储一条消息。
参数:
message: MessageSending 对象,待发送的消息。
has_thinking: 是否管理思考状态,表情包无思考状态(如需调用 register_thinking/complete_thinking
typing: 是否模拟打字等待(根据 has_thinking 控制等待时长)。
typing: 是否模拟打字等待
用法:
- has_thinking=True 时,自动处理思考消息的时间和清理。
- typing=True 时,发送前会有打字等待。
"""
if not message.chat_stream:
@@ -98,40 +96,29 @@ class HeartFCSender:
try:
if set_reply:
_ = message.update_thinking_time()
message.build_reply()
logger.debug(f"[{chat_id}] 选择回复引用消息: {message.processed_plain_text[:20]}...")
# --- 条件应用 set_reply 逻辑 ---
if (
message.is_head
and not message.is_private_message()
and message.reply.processed_plain_text != "[System Trigger Context]"
):
# message.set_reply(message.reply)
message.set_reply()
logger.debug(f"[{chat_id}] 应用 set_reply 逻辑: {message.processed_plain_text[:20]}...")
# print(f"message.display_message: {message.display_message}")
await message.process()
# print(f"message.display_message: {message.display_message}")
if typing:
if has_thinking:
typing_time = calculate_typing_time(
input_string=message.processed_plain_text,
thinking_start_time=message.thinking_start_time,
is_emoji=message.is_emoji,
)
await asyncio.sleep(typing_time)
else:
await asyncio.sleep(0.5)
typing_time = calculate_typing_time(
input_string=message.processed_plain_text,
thinking_start_time=message.thinking_start_time,
is_emoji=message.is_emoji,
)
await asyncio.sleep(typing_time)
sent_msg = await send_message(message)
await self.storage.store_message(message, message.chat_stream)
if not sent_msg:
return False
if sent_msg:
return sent_msg
else:
return "发送失败"
if storage_message:
await self.storage.store_message(message, message.chat_stream)
return sent_msg
except Exception as e:
logger.error(f"[{chat_id}] 处理或存储消息 {message_id} 时出错: {e}")