fix(pipeline): skip waking on empty messages#6893
fix(pipeline): skip waking on empty messages#6893Reisenbug wants to merge 1 commit intoAstrBotDevs:masterfrom
Conversation
Summary of ChangesHello, 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
Using Gemini Code AssistThe 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
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 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
|
There was a problem hiding this comment.
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 bothmessage_strandmessagesmust 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Fixes #6000
我遇到了相同的问题。我的触发词为baka,当我手机私聊输入baka后:
输入1-3个文字,或者删除文字到空,或者进入退出窗口时都会触发一次空信息的回复。
我注意到了 #5797 ,其中Soulter提到了“应该如果消息是空的的话,不会触发llm吧?”
确实,单纯发送“ ”不会触发,但是:bot有唤醒词(比如baka),只输入唤醒词仍然会触发回答
Modifications / 改动点
若 is_wake 为 true 但 message_str和 messages 均为空,则调用 stop_event()阻止空消息进入后续管道阶段。此方案保留了事件下发给pipeline的设计,同时防止只发送唤醒词导致的空消息触发
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.txtandpyproject.toml./ 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到
requirements.txt和pyproject.toml文件相应位置。😮 My changes do not introduce malicious code.
/ 我的更改没有引入恶意代码。