Skip to content

fix(pipeline): skip waking on empty messages#6893

Open
Reisenbug wants to merge 1 commit intoAstrBotDevs:masterfrom
Reisenbug:fix/empty-message-wake-filter
Open

fix(pipeline): skip waking on empty messages#6893
Reisenbug wants to merge 1 commit intoAstrBotDevs:masterfrom
Reisenbug:fix/empty-message-wake-filter

Conversation

@Reisenbug
Copy link
Contributor

@Reisenbug Reisenbug commented Mar 24, 2026

Fixes #6000
我遇到了相同的问题。我的触发词为baka,当我手机私聊输入baka后:
输入1-3个文字,或者删除文字到空,或者进入退出窗口时都会触发一次空信息的回复。
我注意到了 #5797 ,其中Soulter提到了“应该如果消息是空的的话,不会触发llm吧?”
确实,单纯发送“ ”不会触发,但是:bot有唤醒词(比如baka),只输入唤醒词仍然会触发回答

Modifications / 改动点

若 is_wake 为 true 但 message_str和 messages 均为空,则调用 stop_event()阻止空消息进入后续管道阶段。此方案保留了事件下发给pipeline的设计,同时防止只发送唤醒词导致的空消息触发

  • This is NOT a breaking change. / 这不是一个破坏性变更。

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

改动前,输入bot的唤醒词,并在手机上输入一些字符,会触发一些对空白消息的回复
改动后一切正常:
[16:09:32.922] [Core] [INFO] [core.event_bus:61]: [default] [chatbot1(aiocqhttp)] 1441308506/1441308506:
[16:09:33.412] [Core] [INFO] [core.event_bus:61]: [default] [chatbot1(aiocqhttp)] 1441308506/1441308506:
[16:09:34.673] [Core] [INFO] [core.event_bus:61]: [default] [chatbot1(aiocqhttp)] 1441308506/1441308506:
像这样

Checklist / 检查清单

  • 😊 If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
    / 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。

  • 👀 My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
    / 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”

  • 🤓 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.
    / 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到 requirements.txtpyproject.toml 文件相应位置。

  • 😮 My changes do not introduce malicious code.
    / 我的更改没有引入恶意代码。

@auto-assign auto-assign bot requested review from Fridemn and Raven95676 March 24, 2026 08:33
@dosubot dosubot bot added the size:XS This PR changes 0-9 lines, ignoring generated files. label Mar 24, 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!

此拉取请求旨在解决机器人因唤醒词而意外处理空消息的问题。通过在管道的唤醒检查阶段引入一个条件判断,当机器人被唤醒但接收到的消息内容为空时,事件处理流程将被立即终止。这确保了机器人只对有实际内容的消息进行响应,从而提升了用户体验并避免了不必要的回复。

Highlights

  • 阻止空消息处理: 当检测到唤醒词但实际消息内容(message_strmessages)为空时,立即停止事件处理,防止机器人对空消息做出响应。
  • 解决意外触发: 修复了在手机端输入唤醒词后,因输入少量文字、删除文字或切换窗口等操作导致空消息意外触发机器人回复的问题。
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.

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:core The bug / feature is about astrbot's core, backend label Mar 24, 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 - I've found 1 issue, and left some high level feedback:

  • Consider adding a short inline comment above the new if is_wake and not event.message_str and not messages: block explaining the specific scenario it handles (wakeup word with no actual content) so future maintainers understand why both message_str and messages must be empty before stopping the event.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider adding a short inline comment above the new `if is_wake and not event.message_str and not messages:` block explaining the specific scenario it handles (wakeup word with no actual content) so future maintainers understand why both `message_str` and `messages` must be empty before stopping the event.

## Individual Comments

### Comment 1
<location path="astrbot/core/pipeline/waking_check/stage.py" line_range="146-148" />
<code_context>
                 event.is_at_or_wake_command = True
                 wake_prefix = ""

+        if is_wake and not event.message_str and not messages:
+            event.stop_event()
+            return
+
</code_context>
<issue_to_address>
**suggestion:** Consider normalizing/stripping message text before treating it as empty.

Right now `not event.message_str` treats `None` and `""` as empty, but whitespace-only messages still pass through. If those should also count as empty, consider something like:

```python
if is_wake and not (event.message_str and event.message_str.strip()) and not messages:
    ...
```

so wake events with only spaces/newlines are also stopped.

```suggestion
        if is_wake and not (event.message_str and event.message_str.strip()) and not messages:
            event.stop_event()
            return
```
</issue_to_address>

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.

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

此拉取请求解决了在唤醒词触发后处理空消息的问题,这对于改善用户体验是一个有价值的修复。新增的逻辑能够正确识别并停止此类事件,从而避免了不必要的处理。代码改动清晰且直接地解决了描述中的问题,没有发现需要进一步改进的地方。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core The bug / feature is about astrbot's core, backend size:XS This PR changes 0-9 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Bug]私聊消息被重复触发(或者说被重复请求?)

1 participant