fix: ignore face-attached text when matching wake prefix#9395
Open
tangtaizong666 wants to merge 1 commit into
Open
fix: ignore face-attached text when matching wake prefix#9395tangtaizong666 wants to merge 1 commit into
tangtaizong666 wants to merge 1 commit into
Conversation
Contributor
|
Caution The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased. |
Soulter
reviewed
Jul 26, 2026
| (seg for seg in messages if not isinstance(seg, (At, Reply))), | ||
| None, | ||
| ) | ||
| if isinstance(first_content_seg, Face): |
Member
There was a problem hiding this comment.
hi,下面的情况是否也会被 break
[QQ表情] 你好 @xxxx
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #9341.
When a QQ yellow-face emoji is sent from the mobile client, some OneBot implementations (SnowLuma v1.12.5, NapCat ≤ 4.17.x) serialize it as a
facesegment plus a text segment holding the face's display name, e.g.[face:475] + "/干饭". Sincemessage_stris built by concatenating only text segments, such a message producesmessage_str = "/干饭", which starts with the default wake prefix/— so a plain emoji message falsely wakes the bot and triggers an LLM reply.WakingCheckStagealready guards against a related case (first segment is an At to someone else), but any other non-text leading segment slipped through. The wake prefix should only match text the user actually typed at the head of the message, not text attached to a leading face segment.Modifications / 改动点
astrbot/core/pipeline/waking_check/stage.py: in the wake-prefix branch, locate the first message segment that is not a leadingAt/Reply. If that segment is aFace, the prefix match comes from face-attached text rather than a user-typed command, so the prefix does not wake the bot. All other wake paths (@bot, reply-to-bot, private chat, plugin handler filters) are untouched.tests/test_waking_check_stage.py: new unit tests covering the regression and guarding against over-reach:[Face(475), "/干饭"](group) → no wake ✅ (the reported bug)[Reply, Face(475), "/干饭"](replying to a member with an emoji) → no wake ✅[Face(475), "/干饭"]in private chat withfriend_message_needs_wake_prefix→ no wake ✅["/help"],[Image, "/ocr"](image pasted, then command typed),[At(bot), "/help"],["/help", Face]→ still wake, prefix stripped as before ✅The scope is deliberately narrow: only a leading face segment suppresses the prefix match, so commands that carry media (e.g. an image pasted before
/ocr) and trailing emojis keep working exactly as today. The desktop client serializes the same emoji as[干饭](no/prefix), which never matched a wake prefix and is unaffected.Screenshots or Test Results / 运行截图或测试结果
Verification steps
[face:475]+ text"/干饭", as logged by the reporter:[表情:475] /干饭) and run it throughWakingCheckStagewithwake_prefix = ["/"].RED — on current master, the new tests reproduce the bug (3 failing cases are the false wakes):
GREEN — with the fix:
Full local CI-style validation (
make pr-test-neo):Neighboring pipeline-stage tests also pass (
tests/test_preprocess_stage.py,tests/test_rate_limit_stage.py, 10 passed total with the new file).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.
/ 我的更改没有引入恶意代码。
Summary by Sourcery
Prevent wake-prefix detection from triggering on QQ face-attached text while preserving normal command wake behavior.
Bug Fixes:
Tests: