diff --git a/astrbot/core/config/default.py b/astrbot/core/config/default.py index cbadb5c18f..ec6bc423b4 100644 --- a/astrbot/core/config/default.py +++ b/astrbot/core/config/default.py @@ -454,7 +454,6 @@ class ChatProviderTemplate(TypedDict): "type": "kook", "enable": False, "kook_bot_token": "", - "kook_bot_nickname": "", "kook_reconnect_delay": 1, "kook_max_reconnect_delay": 60, "kook_max_retry_delay": 60, @@ -809,11 +808,6 @@ class ChatProviderTemplate(TypedDict): "type": "string", "hint": "必填项。从 KOOK 开发者平台获取的机器人 Token。", }, - "kook_bot_nickname": { - "description": "Bot Nickname", - "type": "string", - "hint": "可选项。若发送者昵称与此值一致,将忽略该消息以避免广播风暴。", - }, "kook_reconnect_delay": { "description": "重连延迟", "type": "int", diff --git a/astrbot/core/platform/sources/kook/kook_adapter.py b/astrbot/core/platform/sources/kook/kook_adapter.py index 1124c6841d..48e0bf5958 100644 --- a/astrbot/core/platform/sources/kook/kook_adapter.py +++ b/astrbot/core/platform/sources/kook/kook_adapter.py @@ -57,20 +57,14 @@ def meta(self) -> PlatformMetadata: name="kook", description="KOOK 适配器", id=self.kook_config.id ) - def _should_ignore_event_by_bot_nickname(self, payload: dict) -> bool: - bot_nickname = self.kook_config.bot_nickname.strip() - if not bot_nickname: + def _should_ignore_event_by_bot_self(self, payload: dict) -> bool: + bot_id = self.client.bot_id + if not bot_id: + logger.warning("[kook] 发现 bot_id 为空, 将无法过滤来自机器人自身的消息") + author_id: str | None = payload.get("author_id") + if not author_id: return False - - author = payload.get("extra", {}).get("author", {}) - if not isinstance(author, dict): - return False - - author_nickname = author.get("nickname") or author.get("username") or "" - if not isinstance(author_nickname, str): - author_nickname = str(author_nickname) - - return author_nickname.strip().casefold() == bot_nickname.casefold() + return bot_id == author_id async def _on_received(self, data: dict): logger.debug(f"KOOK 收到数据: {data}") @@ -79,7 +73,7 @@ async def _on_received(self, data: dict): event_type = payload.get("type") # 支持type=9(文本)和type=10(卡片) if event_type in (9, 10): - if self._should_ignore_event_by_bot_nickname(payload): + if self._should_ignore_event_by_bot_self(payload): return try: abm = await self.convert_message(payload) diff --git a/astrbot/core/platform/sources/kook/kook_config.py b/astrbot/core/platform/sources/kook/kook_config.py index 21f2547b03..0b9d180a29 100644 --- a/astrbot/core/platform/sources/kook/kook_config.py +++ b/astrbot/core/platform/sources/kook/kook_config.py @@ -9,7 +9,6 @@ class KookConfig: # 基础配置 token: str - bot_nickname: str = "" enable: bool = False id: str = "kook" @@ -41,7 +40,6 @@ def from_dict(cls, config_dict: dict) -> "KookConfig": # id=config_dict.get("id", "kook"), enable=config_dict.get("enable", False), token=config_dict.get("kook_bot_token", ""), - bot_nickname=config_dict.get("kook_bot_nickname", ""), reconnect_delay=config_dict.get( "kook_reconnect_delay", KookConfig.reconnect_delay, diff --git a/dashboard/src/i18n/locales/en-US/features/config-metadata.json b/dashboard/src/i18n/locales/en-US/features/config-metadata.json index a143678c23..b69225b078 100644 --- a/dashboard/src/i18n/locales/en-US/features/config-metadata.json +++ b/dashboard/src/i18n/locales/en-US/features/config-metadata.json @@ -590,11 +590,6 @@ "type": "string", "hint": "Required. The Bot Token obtained from the KOOK Developer Platform." }, - "kook_bot_nickname": { - "description": "Bot Nickname", - "type": "string", - "hint": "Optional. If the sender nickname matches this value, the message will be ignored to prevent broadcast storms." - }, "kook_reconnect_delay": { "description": "Reconnect Delay", "type": "int", diff --git a/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json b/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json index 015ce3082c..e5ffa96df7 100644 --- a/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json +++ b/dashboard/src/i18n/locales/zh-CN/features/config-metadata.json @@ -593,11 +593,6 @@ "type": "string", "hint": "必填项。从 KOOK 开发者平台获取的机器人 Token" }, - "kook_bot_nickname": { - "description": "Bot Nickname", - "type": "string", - "hint": "可选项。若发送者昵称与此值一致,将忽略该消息。" - }, "kook_reconnect_delay": { "description": "重连延迟", "type": "int",