Dev (#74)
* fix(discord): 修复 WebSocket 连接检测并增强跨平台文件处理 修复 Discord WebSocket 连接检测逻辑,使用正确的属性检查连接状态 为跨平台消息处理添加文件类型支持,并增加详细的调试日志 优化附件处理逻辑,确保所有文件类型都能正确识别和转发 * feat(跨平台): 优化消息处理并添加纯文本提取功能 添加 extract_text_only 函数过滤非文本标记 修改翻译逻辑仅处理纯文本内容 完善附件处理和消息内容拼接 修复仅包含表情时的消息处理问题
This commit is contained in:
@@ -8,7 +8,7 @@ from core.utils.logger import logger
|
||||
from core.managers.redis_manager import redis_manager
|
||||
from .config import config
|
||||
from .translator import translate_with_deepseek
|
||||
from .parser import format_discord_to_qq_content, format_qq_to_discord_content
|
||||
from .parser import format_discord_to_qq_content, format_qq_to_discord_content, extract_text_only
|
||||
|
||||
async def send_to_discord(channel_id: int, content: str, attachments: List[dict] = None, embed: dict = None):
|
||||
"""发送消息到 Discord 频道"""
|
||||
@@ -117,9 +117,13 @@ async def forward_discord_to_qq(
|
||||
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:
|
||||
formatted_content = f"{formatted_content}\n\n━━━━━ 翻译 ━━━━━\n{translated_content}"
|
||||
# 只提取文本进行翻译,过滤掉非文本内容
|
||||
text_only = extract_text_only(formatted_content)
|
||||
if text_only:
|
||||
translated_content = await translate_with_deepseek(text_only, "zh-CN", channel_id, "en2zh")
|
||||
if translated_content != text_only:
|
||||
# 将翻译后的文本替换回原文本位置
|
||||
formatted_content = formatted_content.replace(text_only, translated_content)
|
||||
|
||||
await send_to_qq(target_qq_group, formatted_content, image_list)
|
||||
logger.success(f"[CrossPlatform] Discord 频道 {channel_id} -> QQ 群 {target_qq_group}")
|
||||
@@ -154,9 +158,12 @@ async def forward_qq_to_discord(
|
||||
|
||||
if embed and embed.get("description"):
|
||||
original_text = embed["description"]
|
||||
translated_text = await translate_with_deepseek(original_text, "en", group_id, "zh2en")
|
||||
if translated_text != original_text:
|
||||
embed["description"] = f"{original_text}\n\n**Translation:**\n{translated_text}"
|
||||
# 只提取文本进行翻译
|
||||
text_only = extract_text_only(original_text)
|
||||
if text_only:
|
||||
translated_text = await translate_with_deepseek(text_only, "en", group_id, "zh2en")
|
||||
if translated_text != text_only:
|
||||
embed["description"] = embed["description"].replace(text_only, translated_text)
|
||||
|
||||
for channel_id in target_channels:
|
||||
await send_to_discord(channel_id, formatted_content, image_list, embed)
|
||||
|
||||
Reference in New Issue
Block a user