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