Skip to content

Commit aacc2a1

Browse files
committed
refactor: KookClient移到KookPlatformAdapter.__init__里初始化
1 parent 831afca commit aacc2a1

1 file changed

Lines changed: 13 additions & 15 deletions

File tree

astrbot/core/platform/sources/kook/kook_adapter.py

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ def __init__(
3333
logger.debug(f"[KOOK] 配置: {self.kook_config.pretty_jsons()}")
3434
# self.config = platform_config
3535
self.settings = platform_settings
36-
self.client = None
36+
self.client = KookClient(self.kook_config, self._on_received)
3737
self._reconnect_task = None
3838
self.running = False
3939
self._main_task = None
@@ -58,25 +58,23 @@ def meta(self) -> PlatformMetadata:
5858
name="kook", description="KOOK 适配器", id=self.kook_config.id
5959
)
6060

61+
async def _on_received(self, data: dict):
62+
logger.debug(f"KOOK 收到数据: {data}")
63+
if "d" in data and data["s"] == 0:
64+
event_type = data["d"].get("type")
65+
# 支持type=9(文本)和type=10(卡片)
66+
if event_type in (9, 10):
67+
try:
68+
abm = await self.convert_message(data["d"])
69+
await self.handle_msg(abm)
70+
except Exception as e:
71+
logger.error(f"[KOOK] 消息处理异常: {e}")
72+
6173
async def run(self):
6274
"""主运行循环"""
6375
self.running = True
6476
logger.info("[KOOK] 启动KOOK适配器")
6577

66-
async def on_received(data):
67-
logger.debug(f"KOOK 收到数据: {data}")
68-
if "d" in data and data["s"] == 0:
69-
event_type = data["d"].get("type")
70-
# 支持type=9(文本)和type=10(卡片)
71-
if event_type in (9, 10):
72-
try:
73-
abm = await self.convert_message(data["d"])
74-
await self.handle_msg(abm)
75-
except Exception as e:
76-
logger.error(f"[KOOK] 消息处理异常: {e}")
77-
78-
self.client = KookClient(self.kook_config, on_received)
79-
8078
# 启动主循环
8179
self._main_task = asyncio.create_task(self._main_loop())
8280

0 commit comments

Comments
 (0)