Skip to content

refactor: 使用kook接口中获取的bot_id判断是否过滤来自bot自身的信息,而不是用户手动输入的bot_nickname来判断#5705

Closed
shuiping233 wants to merge 2 commits intoAstrBotDevs:masterfrom
shuiping233:refactor/kook-adapter-ignore-event-by-self
Closed

refactor: 使用kook接口中获取的bot_id判断是否过滤来自bot自身的信息,而不是用户手动输入的bot_nickname来判断#5705
shuiping233 wants to merge 2 commits intoAstrBotDevs:masterfrom
shuiping233:refactor/kook-adapter-ignore-event-by-self

Conversation

@shuiping233
Copy link
Contributor

@shuiping233 shuiping233 commented Mar 3, 2026

Modifications / 改动点

  • astrbot/core/platform/sources/kook/kook_adapter.py , 使用了更精确判断bot_id的方式来过滤来自bot自身的消息事件,因为能通过kook接口获取到bot_id,所以也不再需要用户手动在控制台里输入了
  • This is NOT a breaking change. / 这不是一个破坏性变更。

Screenshots or Test Results / 运行截图或测试结果

image

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations in requirements.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Summary by Sourcery

使用来自平台客户端的 KOOK 机器人 ID 来识别并忽略由机器人自身发送的消息,并移除现已不再需要的机器人昵称配置。

Bug Fixes:

  • 通过依赖 KOOK 机器人 ID 而不是手动配置的机器人昵称,防止错误的自发消息过滤。

Enhancements:

  • 通过从核心配置和仪表盘 i18n 元数据中移除机器人昵称字段及其相关元数据,简化 KOOK 适配器配置。
Original summary in English

Summary by Sourcery

Use KOOK bot ID from the platform client to identify and ignore messages sent by the bot itself, and remove the now-unnecessary bot nickname configuration.

Bug Fixes:

  • Prevent incorrect self-message filtering by relying on the KOOK bot ID instead of a manually configured bot nickname.

Enhancements:

  • Simplify KOOK adapter configuration by removing the bot nickname field and its related metadata from core config and dashboard i18n metadata.

@auto-assign auto-assign bot requested review from LIghtJUNction and Soulter March 3, 2026 08:18
@dosubot dosubot bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Mar 3, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在提升 KOOK 平台适配器的消息处理准确性和用户体验。通过直接利用 KOOK 接口提供的 bot_id 来识别和过滤机器人自身发送的消息,解决了以往依赖昵称可能导致的误判问题,并减少了用户在配置时需要手动输入的信息。

Highlights

  • KOOK 机器人消息过滤优化: 将 KOOK 机器人自身消息的过滤机制从依赖用户手动输入的 bot_nickname 更改为使用 KOOK 接口获取的精确 bot_id
  • 配置项简化: 移除了 kook_bot_nickname 配置项,简化了用户配置流程。
Changelog
  • astrbot/core/config/default.py
    • 移除了 kook_bot_nickname 默认配置项。
    • 移除了 kook_bot_nickname 的配置元数据。
  • astrbot/core/platform/sources/kook/kook_adapter.py
    • 重构了 _should_ignore_event_by_bot_nickname 函数,更名为 _should_ignore_event_by_bot_self,并修改其逻辑以使用 bot_id 进行判断。
    • 更新了 _on_received 方法中对消息过滤函数的调用,以使用新的 _should_ignore_event_by_bot_self
  • astrbot/core/platform/sources/kook/kook_config.py
    • KookConfig 类中移除了 bot_nickname 属性。
    • from_dict 方法中移除了对 bot_nickname 的处理。
  • dashboard/src/i18n/locales/en-US/features/config-metadata.json
    • 移除了 kook_bot_nickname 的英文配置描述。
  • dashboard/src/i18n/locales/zh-CN/features/config-metadata.json
    • 移除了 kook_bot_nickname 的中文配置描述。
Activity
  • 目前没有人工活动。
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

@dosubot dosubot bot added the area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. label Mar 3, 2026
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey - 我在这里给了一些高层次的反馈:

  • _should_ignore_event_by_bot_self 中,建议考虑对 self.client.bot_idNone 或未设置的情况进行保护(例如,当其为假值时直接返回 False),以避免在客户端尚未完全初始化之前出现意外行为。
  • 之前的过滤逻辑使用的是 extra.author,而新版本使用的是 author_id;请再次确认所有受支持的 KOOK 消息事件类型(例如类型 9 和 10)是否都能稳定地在顶层包含 author_id 字段,或者添加一个简短注释说明这是一个前提假设。
给 AI 代理的提示
Please address the comments from this code review:

## Overall Comments
- In `_should_ignore_event_by_bot_self`, consider guarding against `self.client.bot_id` being `None` or unset (e.g., return `False` if it's falsy) to avoid unexpected behavior before the client has fully initialized.
- Previously the filter logic used `extra.author` while the new version uses `author_id`; please double-check that all supported KOOK message event types (e.g., type 9 and 10) reliably include `author_id` at the top level, or add a brief comment explaining this assumption.

Sourcery 对开源项目是免费的——如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的评审。
Original comment in English

Hey - I've left some high level feedback:

  • In _should_ignore_event_by_bot_self, consider guarding against self.client.bot_id being None or unset (e.g., return False if it's falsy) to avoid unexpected behavior before the client has fully initialized.
  • Previously the filter logic used extra.author while the new version uses author_id; please double-check that all supported KOOK message event types (e.g., type 9 and 10) reliably include author_id at the top level, or add a brief comment explaining this assumption.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `_should_ignore_event_by_bot_self`, consider guarding against `self.client.bot_id` being `None` or unset (e.g., return `False` if it's falsy) to avoid unexpected behavior before the client has fully initialized.
- Previously the filter logic used `extra.author` while the new version uses `author_id`; please double-check that all supported KOOK message event types (e.g., type 9 and 10) reliably include `author_id` at the top level, or add a brief comment explaining this assumption.

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@dosubot
Copy link

dosubot bot commented Mar 3, 2026

Related Documentation

Checked 1 published document(s) in 1 knowledge base(s). No updates required.

How did I do? Any feedback?  Join Discord

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

本次重构通过使用从 KOOK 接口获取的 bot_id 来判断并过滤机器人自身发送的消息,替代了之前依赖用户手动输入 bot_nickname 的方式,这是一个很好的改进,使得消息过滤更加健壮和可靠。代码的改动清晰地反映了这一目的,并且相应地移除了不再需要的配置项。

我发现了一个与新实现相关的潜在问题,并提供了一个修复建议,以确保在边缘情况下(如机器人 ID 获取失败时)消息不会被错误地忽略。

@shuiping233 shuiping233 force-pushed the refactor/kook-adapter-ignore-event-by-self branch from ce41798 to 931e01c Compare March 4, 2026 03:37
@shuiping233
Copy link
Contributor Author

#5719 已经把这个包含了,所以关掉这个pr)

    def _should_ignore_event_by_bot_nickname(self, author_id: str) -> bool:
        return self.client.bot_id == author_id

@shuiping233 shuiping233 closed this Mar 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:platform The bug / feature is about IM platform adapter, such as QQ, Lark, Telegram, WebChat and so on. size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant