File tree Expand file tree Collapse file tree
astrbot/core/platform/sources/kook Expand file tree Collapse file tree Original file line number Diff line number Diff line change 11import asyncio
22import base64
3- import json
43import os
54import random
65import time
@@ -188,7 +187,12 @@ async def listen(self):
188187 try :
189188 while self .running :
190189 try :
191- msg = await asyncio .wait_for (self .ws .recv (), timeout = 10 ) # type: ignore
190+ if self .ws is None :
191+ logger .warning (
192+ "[KOOK] 尚未连接kook WebSocket服务器, 跳过消息监听流程"
193+ )
194+ continue
195+ msg = await asyncio .wait_for (self .ws .recv (), timeout = 10 )
192196
193197 if isinstance (msg , bytes ):
194198 try :
@@ -326,9 +330,16 @@ async def _heartbeat_loop(self):
326330
327331 async def _send_ping (self ):
328332 """发送心跳PING"""
333+ if self .ws is None :
334+ logger .warning ("[KOOK] 尚未连接kook WebSocket服务器, 跳过发送心跳包流程" )
335+ return
329336 try :
330- ping_data = {"s" : 2 , "sn" : self .last_sn }
331- await self .ws .send (json .dumps (ping_data )) # type: ignore
337+ ping_data = KookWebsocketEvent (
338+ s = KookMessageSignal .PING ,
339+ d = None ,
340+ sn = self .last_sn ,
341+ )
342+ await self .ws .send (ping_data .to_json ())
332343 except Exception as e :
333344 logger .error (f"[KOOK] 发送心跳失败: { e } " )
334345
You can’t perform that action at this time.
0 commit comments