This commit is contained in:
2025-12-31 22:15:34 +08:00
parent 2cba589b2e
commit 082d3c9758
5 changed files with 29 additions and 6 deletions

View File

@@ -84,11 +84,14 @@ class WS:
print(f" 事件分发失败: {e}")
async def call_api(self, action: str, params: dict = None):
"""公有 API供插件调用发送指令并异步等待结果"""
if not self.ws or self.ws.closed:
return {"status": "failed", "msg": "websocket not connected"}
if not self.ws:
return {"status": "failed", "msg": "websocket not initialized"}
# 检查 websockets 13.x+ 的状态属性
from websockets.protocol import State
if getattr(self.ws, "state", None) is not State.OPEN:
return {"status": "failed", "msg": "websocket is not open"}
# 创建唯一的 echo ID
echo_id = str(uuid.uuid4())
payload = {
"action": action,