feat(翻译): 改进翻译功能,同时显示原文和译文

修改翻译功能,不再替换原文而是同时显示原文和翻译内容,方便用户对照
更新 DeepSeek API 配置为官方地址和模型
优化 Discord 适配器的重连逻辑,直接关闭 WebSocket 触发重连
修复 Discord 频道 ID 转换逻辑,简化处理流程
This commit is contained in:
2026-03-22 15:07:18 +08:00
committed by 镀铬酸钾
parent 7eb585748d
commit 1c3282aaad
2 changed files with 16 additions and 8 deletions

View File

@@ -16,9 +16,9 @@ class CrossPlatformConfig:
self.ENABLE_CROSS_PLATFORM = True
# DeepSeek API 配置
self.DEEPSEEK_API_KEY = "sk-Cn4BeHyTHDPRKuDadLy6dUnjSSHxrz5wQa54ZFAdQovXguLD"
self.DEEPSEEK_API_URL = "https://api.gptgod.online/v1/chat/completions"
self.DEEPSEEK_MODEL = "gemini-3-flash-preview"
self.DEEPSEEK_API_KEY = "sk-7b824b05e85445f8a9ceef6c849388a9"
self.DEEPSEEK_API_URL = "https://api.deepseek.com/v1/chat/completions"
self.DEEPSEEK_MODEL = "deepseek-chat"
# 是否启用翻译功能
self.ENABLE_TRANSLATION = True
@@ -48,12 +48,14 @@ class CrossPlatformConfig:
for key, value in mappings.items():
if isinstance(value, dict) and "qq_group_id" in value:
try:
discord_id = int(key) if str(key).isdigit() else int(str(key).split('.')[-1])
# 直接将 key 转换为整数
discord_id = int(str(key))
self.CROSS_PLATFORM_MAP[discord_id] = {
"qq_group_id": int(value.get("qq_group_id", 0)),
"name": value.get("name", "")
}
except (ValueError, AttributeError):
logger.warning(f"[CrossPlatform] 无效的 Discord 频道 ID: {key}")
continue
logger.success(f"[CrossPlatform] 配置已重新加载: {len(self.CROSS_PLATFORM_MAP)} 个映射")

View File

@@ -193,6 +193,11 @@ class DiscordAdapter(discord.Client if DISCORD_AVAILABLE else object):
self.logger.info(f"[DiscordAdapter] 正在发送消息到频道 {channel_id}")
else:
self.logger.error(f"[DiscordAdapter] 会话已关闭,无法发送消息到频道 {channel_id}")
# 触发重连
self.logger.warning(f"[DiscordAdapter] 会话已关闭,将触发重连")
if self.ws is not None:
# 关闭 WebSocket 连接,让 discord.py 自动重连
await self.ws.close(4000)
return
embed = None
@@ -284,9 +289,8 @@ class DiscordAdapter(discord.Client if DISCORD_AVAILABLE else object):
# 如果发送失败,尝试检查会话状态
if self.is_closed():
self.logger.warning(f"[DiscordAdapter] 会话已关闭,将触发重连")
await self.close()
# 重新启动客户端
asyncio.create_task(self.start_client())
if self.ws is not None:
await self.ws.close(4000)
raise
else:
self.logger.debug(f"[DiscordAdapter] 没有内容需要发送到频道 {channel_id}")
@@ -325,6 +329,8 @@ class DiscordAdapter(discord.Client if DISCORD_AVAILABLE else object):
self.logger.info(f"将在 {retry_delay} 秒后重连 ({retry_count}/{max_retries if max_retries != -1 else '无限'})...")
# 清理旧的连接状态
if hasattr(self, 'http') and self.http:
await self.http.close()
self.clear()
await asyncio.sleep(retry_delay)
@@ -347,7 +353,7 @@ class DiscordAdapter(discord.Client if DISCORD_AVAILABLE else object):
# 我们可以通过检查 self.is_closed() 或者 ws.open 来判断
if self.ws is not None and not getattr(self.ws, 'open', True):
self.logger.warning("检测到 WebSocket 连接已关闭,触发重连...")
await self.close()
await self.ws.close(4000)
break
self.logger.debug(f"心跳正常: {self.user}")