Dev (#77)
* fix(discord): 修复 WebSocket 连接检测并增强跨平台文件处理 修复 Discord WebSocket 连接检测逻辑,使用正确的属性检查连接状态 为跨平台消息处理添加文件类型支持,并增加详细的调试日志 优化附件处理逻辑,确保所有文件类型都能正确识别和转发 * feat(跨平台): 优化消息处理并添加纯文本提取功能 添加 extract_text_only 函数过滤非文本标记 修改翻译逻辑仅处理纯文本内容 完善附件处理和消息内容拼接 修复仅包含表情时的消息处理问题 * refactor(discord-cross): 使用模块专用日志记录器替换全局日志记录器 将各模块中的全局日志记录器替换为模块专用日志记录器,以提供更清晰的日志来源标识 同时在适配器中添加会话状态检查和重连机制,提升消息发送的可靠性 * feat(翻译): 改进翻译功能,同时显示原文和译文 修改翻译功能,不再替换原文而是同时显示原文和翻译内容,方便用户对照 更新 DeepSeek API 配置为官方地址和模型 优化 Discord 适配器的重连逻辑,直接关闭 WebSocket 触发重连 修复 Discord 频道 ID 转换逻辑,简化处理流程 * feat(cross-platform): 添加跨平台功能支持及配置优化 - 新增跨平台配置模型和全局配置支持 - 优化 Discord 适配器的连接管理和错误处理 - 添加 watchdog 和 discord.py 依赖 - 创建 DeepSeek API 配置文档 - 移除重复的同步帮助图片代码 - 改进跨平台插件配置加载逻辑 * fix(jrcd): 修正群组ID检查条件 删除不再使用的示例插件文件
This commit is contained in:
@@ -96,7 +96,7 @@ class DiscordAdapter(discord.Client if DISCORD_AVAILABLE else object):
|
||||
return
|
||||
|
||||
try:
|
||||
channel_name = "neobot_discord_send"
|
||||
channel_name = "neobot_cross_platform"
|
||||
pubsub = redis_manager.redis.pubsub()
|
||||
await pubsub.subscribe(channel_name)
|
||||
|
||||
@@ -319,23 +319,64 @@ class DiscordAdapter(discord.Client if DISCORD_AVAILABLE else object):
|
||||
except asyncio.CancelledError:
|
||||
self.logger.info("连接被取消")
|
||||
break
|
||||
except discord.ConnectionClosed as e:
|
||||
retry_count += 1
|
||||
self.logger.warning(f"Discord 连接关闭: code={e.code}, reason={e.reason}")
|
||||
|
||||
# 如果是正常关闭,不计入重连次数
|
||||
if e.code == 1000:
|
||||
self.logger.info("连接正常关闭,等待重新连接...")
|
||||
continue
|
||||
|
||||
if max_retries != -1 and retry_count >= max_retries:
|
||||
self.logger.error(f"已达到最大重连次数 ({max_retries}),停止重连")
|
||||
break
|
||||
|
||||
self.logger.info(f"将在 {retry_delay} 秒后重连 ({retry_count}/{max_retries if max_retries != -1 else '无限'})...")
|
||||
await self._cleanup_connection()
|
||||
await asyncio.sleep(retry_delay)
|
||||
except Exception as e:
|
||||
retry_count += 1
|
||||
self.logger.error(f"Discord 连接失败: {e}")
|
||||
self.logger.error(f"Discord 连接异常: {e}")
|
||||
|
||||
if max_retries != -1 and retry_count >= max_retries:
|
||||
self.logger.error(f"已达到最大重连次数 ({max_retries}),停止重连")
|
||||
break
|
||||
|
||||
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 self._cleanup_connection()
|
||||
await asyncio.sleep(retry_delay)
|
||||
|
||||
self.logger.info("Discord 客户端已停止")
|
||||
|
||||
async def _cleanup_connection(self):
|
||||
"""
|
||||
清理旧的连接状态
|
||||
"""
|
||||
try:
|
||||
# 停止心跳任务
|
||||
if hasattr(self, 'heartbeat_task') and not self.heartbeat_task.done():
|
||||
self.heartbeat_task.cancel()
|
||||
try:
|
||||
await self.heartbeat_task
|
||||
except asyncio.CancelledError:
|
||||
pass
|
||||
except Exception as e:
|
||||
self.logger.error(f"清理心跳任务时出错: {e}")
|
||||
|
||||
try:
|
||||
# 清理 HTTP 连接
|
||||
if hasattr(self, 'http') and self.http:
|
||||
await self.http.close()
|
||||
except Exception as e:
|
||||
self.logger.error(f"清理 HTTP 连接时出错: {e}")
|
||||
|
||||
try:
|
||||
# 清理客户端状态
|
||||
self.clear()
|
||||
except Exception as e:
|
||||
self.logger.error(f"清理客户端状态时出错: {e}")
|
||||
|
||||
async def start_heartbeat(self, interval: int = 30):
|
||||
"""
|
||||
启动心跳机制,定期检查连接状态
|
||||
|
||||
Reference in New Issue
Block a user