perf(OneBot): add a whitespace after At component#6238
Conversation
修复 At 组件后的空格在发送时被 strip 移除的问题。在消息解析时检测 At 组件并在其后额外插入空格。
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
Changelog
Activity
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. 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
|
There was a problem hiding this comment.
Hey - I've left some high level feedback:
- The logic for handling
Atsegments largely duplicates the common_from_segment_to_dict+ret.appendpath; consider restructuring the loop to call this once per segment and only conditionally append the extra space to reduce branching and repetition. - Unconditionally inserting a space after every
Atmay introduce double spaces if the followingPlainsegment already begins with whitespace; consider peeking at the next segment or the next text’s leading character(s) so the behavior is more context-aware.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- The logic for handling `At` segments largely duplicates the common `_from_segment_to_dict` + `ret.append` path; consider restructuring the loop to call this once per segment and only conditionally append the extra space to reduce branching and repetition.
- Unconditionally inserting a space after every `At` may introduce double spaces if the following `Plain` segment already begins with whitespace; consider peeking at the next segment or the next text’s leading character(s) so the behavior is more context-aware.Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
There was a problem hiding this comment.
Code Review
The pull request introduces support for the At message component within the aiocqhttp_message_event.py file. It imports the At component and modifies the _parse_onebot_json function to correctly process At components by appending a space after them to prevent text concatenation issues. The parsing logic for message segments has also been generalized to ensure all component types are handled.
在 _parse_onebot_json 方法中,仅在检测到 At 组件存在,才在其后插入一个空格,最小化干涉。 |
修复 #6237:发送 At 消息时后面的空格丢失的问题。
Modifications / 改动点
修改了
astrbot/core/platform/sources/aiocqhttp/aiocqhttp_message_event.py:At组件到 import_parse_onebot_json方法中,仅在检测到 At 组件存在,才在其后插入一个空格,最小化干涉Screenshots or Test Results / 运行截图或测试结果
修复前:
修好 [At:xxxxxx] 了吗(有空格)修好 @xxx(xxxxx)了吗(空格丢失)修复后:
修好 @xxx(xxxxx) 了吗(空格保留)Checklist / 检查清单
requirements.txt和pyproject.toml文件相应位置。/ I have ensured that no new dependencies are introduced, OR if new dependencies are introduced, they have been added to the appropriate locations inrequirements.txtandpyproject.toml.Summary by Sourcery
Bug Fixes: