refactor(reverse_ws): 重构反向WebSocket管理器的防重复处理逻辑

将防重复处理数据结构改为按客户端隔离,防止不同客户端间的事件冲突
添加事件处理中的状态跟踪,避免并发处理同一事件
优化群消息内容防重复检查,仅对群聊消息生效
增加详细的调试日志,便于问题排查
This commit is contained in:
2026-02-28 22:45:36 +08:00
parent 8e6f6cca0c
commit 311b1985dd
2 changed files with 189 additions and 64 deletions

View File

@@ -25,7 +25,6 @@ from websockets.legacy.client import WebSocketClientProtocol
from models.events.factory import EventFactory
from .config_loader import global_config
from .managers.command_manager import matcher
from .utils.executor import CodeExecutor
from .utils.logger import ModuleLogger
from .utils.exceptions import (
@@ -210,6 +209,7 @@ class WS:
self.logger.debug(f"[元事件] {meta_event_type}")
# 分发事件
from .managers.command_manager import matcher
await matcher.handle_event(self.bot, event)
except Exception as e:
@@ -297,3 +297,16 @@ class WS:
message=f"API调用异常: {str(e)}",
data={"action": action, "params": params}
)
class ReverseWSClient(WS):
"""
反向 WebSocket 客户端代理,用于 Bot 实例调用 API。
"""
def __init__(self, manager: Any, client_id: str):
super().__init__()
self.manager = manager
self.client_id = client_id
async def call_api(self, action: str, params: Optional[Dict[Any, Any]] = None) -> Dict[Any, Any]:
return await self.manager.call_api(action, params, self.client_id)