Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions astrbot/core/config/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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",
Expand Down
22 changes: 8 additions & 14 deletions astrbot/core/platform/sources/kook/kook_adapter.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
Expand All @@ -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)
Expand Down
2 changes: 0 additions & 2 deletions astrbot/core/platform/sources/kook/kook_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ class KookConfig:

# 基础配置
token: str
bot_nickname: str = ""
enable: bool = False
id: str = "kook"

Expand Down Expand Up @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -593,11 +593,6 @@
"type": "string",
"hint": "必填项。从 KOOK 开发者平台获取的机器人 Token"
},
"kook_bot_nickname": {
"description": "Bot Nickname",
"type": "string",
"hint": "可选项。若发送者昵称与此值一致,将忽略该消息。"
},
"kook_reconnect_delay": {
"description": "重连延迟",
"type": "int",
Expand Down