Repository navigation
Conversation
Contributor
There was a problem hiding this comment.
Hey - I've found 1 issue
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="astrbot/core/platform/sources/telegram/tg_adapter.py" line_range="617" />
<code_context>
- )
+ command, bot_name = command_parts[0].split("@", 1)
+ if bot_name.casefold() != context.bot.username.casefold():
+ return None
+ plain_text = command + (
+ f" {command_parts[1]}" if len(command_parts) > 1 else ""
</code_context>
<issue_to_address>
**issue (broader_impact):** A command addressed to another bot is filtered only after the message's reply chain has already been recursively converted. If the ignored message replies to `/start`, the recursive conversion invokes `self.start()` and sends AstrBot's start message even though the outer command should be ignored.
**Triggers:** When a user sends `/command@OtherBot` as a reply to a Telegram `/start` message.
**Suggested fix:** Normalize and reject explicitly addressed commands before recursively converting the reply message, or suppress side effects while converting reply chains.
</issue_to_address>Sourcery assessment
Approval pending. 1 finding to address first.
Blocking findings: astrbot/core/platform/sources/telegram/tg_adapter.py:617
5 tasks done
| and update.message.text | ||
| and update.message.text.startswith("/") | ||
| ): | ||
| command_token = update.message.text.split(" ", 1)[0] |
Contributor
There was a problem hiding this comment.
command_token splits on the first space, so a command with a newline before any space merges into bot_name.
A mismatched comparison drops a command addressed to this bot instead of processing it.
This branch has not been deployed
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 #10240.
Telegram currently leaves
/command@OtherBotunchanged when the target username does not match the current bot. The generic waking stage can then treat the leading/as a wake prefix before command matching, so a command intended for another Telegram bot may wake AstrBot and reach LLM handling.Modifications / 改动点
Ignore Telegram commands explicitly addressed to another bot before they enter AstrBot's event pipeline.
Strip the
@usernamesuffix from commands addressed to the current bot.Compare Telegram bot usernames case-insensitively.
Preserve bare commands such as
/help, leaving their behavior to the existing AstrBot configuration.Add regression tests for current-bot targets, case-insensitive targets, arguments, bare commands, and other-bot targets.
This is NOT a breaking change. / 这不是一个破坏性变更。
Screenshots or Test Results / 运行截图或测试结果
The warning is the existing Python 3.12
audioopdeprecation warning fromtencent_record_helper.py.Checklist / 检查清单
Summary by Sourcery
Prevent Telegram commands intended for other bots from waking AstrBot while preserving existing command behavior.
Bug Fixes:
Tests: