fix(discord): 修复 WebSocket 连接检测并增强跨平台文件处理
修复 Discord WebSocket 连接检测逻辑,使用正确的属性检查连接状态 为跨平台消息处理添加文件类型支持,并增加详细的调试日志 优化附件处理逻辑,确保所有文件类型都能正确识别和转发
This commit is contained in:
@@ -28,6 +28,7 @@ async def send_to_discord(channel_id: int, content: str, attachments: List[dict]
|
||||
|
||||
async def send_to_qq(group_id: int, content: str, attachments: List[dict] = None):
|
||||
"""发送消息到 QQ 群"""
|
||||
logger.debug(f"[CrossPlatform] send_to_qq: group_id={group_id}, content='{content}', attachments={attachments}")
|
||||
try:
|
||||
from core.managers.bot_manager import bot_manager
|
||||
from models.message import MessageSegment
|
||||
@@ -59,21 +60,29 @@ async def send_to_qq(group_id: int, content: str, attachments: List[dict] = None
|
||||
full_message.append(MessageSegment.record(attachment_url, cache=True, proxy=True, timeout=30))
|
||||
elif att_type == "video":
|
||||
full_message.append(MessageSegment.video(attachment_url))
|
||||
elif att_type == "file":
|
||||
full_message.append(MessageSegment.file(attachment_url))
|
||||
logger.success(f"[CrossPlatform] 已添加文件到 QQ 消息: {attachment_url}")
|
||||
else:
|
||||
attachment_url = str(attachment)
|
||||
if attachment_url.lower().endswith(('.mp4', '.avi', '.mkv', '.mov', '.flv', '.wmv')):
|
||||
full_message.append(MessageSegment.video(attachment_url))
|
||||
elif attachment_url.lower().endswith(('.amr', '.silk', '.mp3', '.wav', '.ogg', '.m4a')):
|
||||
full_message.append(MessageSegment.record(attachment_url, cache=True, proxy=True, timeout=30))
|
||||
elif attachment_url.lower().endswith(('.png', '.jpg', '.jpeg', '.gif', '.webp')):
|
||||
image_type = "flash" if attachment_url.lower().endswith('.gif') else None
|
||||
full_message.append(MessageSegment.image(attachment_url, cache=True, proxy=True, timeout=30, image_type=image_type))
|
||||
else:
|
||||
full_message.append(MessageSegment.image(attachment_url, cache=True, proxy=True, timeout=30))
|
||||
full_message.append(MessageSegment.file(attachment_url))
|
||||
logger.success(f"[CrossPlatform] 已添加文件到 QQ 消息 (通过扩展名识别): {attachment_url}")
|
||||
|
||||
logger.debug(f"[CrossPlatform] 准备发送消息到 QQ 群 {group_id}: {full_message}")
|
||||
await bot.send_group_msg(group_id, full_message)
|
||||
logger.info(f"[CrossPlatform] 消息已发送到 QQ 群 {group_id}")
|
||||
logger.success(f"[CrossPlatform] 消息已发送到 QQ 群 {group_id}: {full_message}")
|
||||
else:
|
||||
logger.debug(f"[CrossPlatform] 准备发送纯文本消息到 QQ 群 {group_id}: {message}")
|
||||
await bot.send_group_msg(group_id, message)
|
||||
logger.info(f"[CrossPlatform] 消息已发送到 QQ 群 {group_id}")
|
||||
logger.success(f"[CrossPlatform] 纯文本消息已发送到 QQ 群 {group_id}: {message}")
|
||||
break
|
||||
except Exception as e:
|
||||
logger.error(f"[CrossPlatform] 发送消息到 QQ 群 {group_id} 失败: {e}")
|
||||
@@ -89,6 +98,7 @@ async def forward_discord_to_qq(
|
||||
attachments: List[dict] = None
|
||||
):
|
||||
"""将 Discord 消息转发到所有映射的 QQ 群"""
|
||||
logger.debug(f"[CrossPlatform] forward_discord_to_qq: channel_id={channel_id}, attachments={attachments}")
|
||||
if channel_id not in config.CROSS_PLATFORM_MAP:
|
||||
logger.warning(f"[CrossPlatform] 未找到 Discord 频道 {channel_id} 的映射配置")
|
||||
return
|
||||
@@ -104,6 +114,8 @@ async def forward_discord_to_qq(
|
||||
attachments
|
||||
)
|
||||
|
||||
logger.debug(f"[CrossPlatform] 格式化后的内容: '{formatted_content}', 图片列表: {image_list}")
|
||||
|
||||
if formatted_content:
|
||||
translated_content = await translate_with_deepseek(formatted_content, "zh-CN", channel_id, "en2zh")
|
||||
if translated_content != formatted_content:
|
||||
@@ -111,6 +123,7 @@ async def forward_discord_to_qq(
|
||||
|
||||
await send_to_qq(target_qq_group, formatted_content, image_list)
|
||||
logger.success(f"[CrossPlatform] Discord 频道 {channel_id} -> QQ 群 {target_qq_group}")
|
||||
logger.debug(f"[CrossPlatform] send_to_qq 已调用: group_id={target_qq_group}, formatted_content='{formatted_content}', image_list={image_list}")
|
||||
|
||||
async def forward_qq_to_discord(
|
||||
qq_nickname: str,
|
||||
|
||||
Reference in New Issue
Block a user