2
This commit is contained in:
11
core/ws.py
11
core/ws.py
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user