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

@@ -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}")