fix: 再次修复消息发送

pull/1444/head
tcmofashi 2025-12-18 13:50:50 +08:00
parent b82389e4a2
commit 7ad97158c4
1 changed files with 19 additions and 16 deletions

View File

@ -186,6 +186,7 @@ async def _send_message(message: MessageSending, show_log=True) -> bool:
async def send_with_new_api(legacy_exception=None):
try:
from src.config.config import global_config
# 如果未开启 API Server直接跳过 Fallback
if not global_config.maim_message.enable_api_server:
if legacy_exception:
@ -210,7 +211,7 @@ async def _send_message(message: MessageSending, show_log=True) -> bool:
api_message = APIMessageBase(
message_info=message.message_info,
message_segment=message.message_segment,
message_dim=msg_dim
message_dim=msg_dim,
)
# 直接调用 Server 的 send_message 接口,它会自动处理路由
@ -219,7 +220,9 @@ async def _send_message(message: MessageSending, show_log=True) -> bool:
# 检查是否有任何连接发送成功
if any(results.values()):
if show_log:
logger.info(f"已通过API Server Fallback将消息 '{message_preview}' 发往平台'{platform}' (key: {target_api_key})")
logger.info(
f"已通过API Server Fallback将消息 '{message_preview}' 发往平台'{platform}' (key: {target_api_key})"
)
return True
except Exception:
pass
@ -231,13 +234,13 @@ async def _send_message(message: MessageSending, show_log=True) -> bool:
try:
send_result = await get_global_api().send_message(message)
if send_result:
# if send_result:
if show_log:
logger.info(f"已将消息 '{message_preview}' 发往平台'{message.message_info.platform}'")
return True
# Legacy API 返回 False (发送失败但未报错),尝试 Fallback
return await send_with_new_api()
# return await send_with_new_api()
except Exception as legacy_e:
# Legacy API 抛出异常,尝试 Fallback