-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
fix: 修复 aiocqhttp 适配器 at 会获取群昵称而消息不会获取的逻辑不一致 #2769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Conversation
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
Contributor
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
你好 - 我已审阅了你的更改,它们看起来很棒!
AI 代理的提示
请处理此代码审查中的评论:
## 个人评论
### 评论 1
<location> `astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py:168-172` </location>
<code_context>
if "sub_type" in event:
if event["sub_type"] == "poke" and "target_id" in event:
abm.message.append(
Poke(qq=str(event["target_id"]), type="poke")
) # noqa: F405
</code_context>
<issue_to_address>
**suggestion (code-quality):** 合并嵌套的 if 条件 ([`merge-nested-ifs`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/merge-nested-ifs))
```suggestion
if "sub_type" in event and (event["sub_type"] == "poke" and "target_id" in event):
abm.message.append(
Poke(qq=str(event["target_id"]), type="poke")
) # noqa: F405
```
<br/><details><summary>解释</summary>过多的嵌套会使代码难以理解,在 Python 中尤其如此,因为它没有括号来帮助区分不同的嵌套级别。
阅读深度嵌套的代码会令人困惑,因为你必须跟踪哪些条件与哪些级别相关。因此,我们力求在可能的情况下减少嵌套,而使用 `and` 组合两个 `if` 条件的情况是一个简单的改进。
</details>
</issue_to_address>帮助我更有用!请点击每个评论上的 👍 或 👎,我将使用反馈来改进您的评论。
Original comment in English
Hey there - I've reviewed your changes and they look great!
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location> `astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py:168-172` </location>
<code_context>
if "sub_type" in event:
if event["sub_type"] == "poke" and "target_id" in event:
abm.message.append(
Poke(qq=str(event["target_id"]), type="poke")
) # noqa: F405
</code_context>
<issue_to_address>
**suggestion (code-quality):** Merge nested if conditions ([`merge-nested-ifs`](https://docs.sourcery.ai/Reference/Rules-and-In-Line-Suggestions/Python/Default-Rules/merge-nested-ifs))
```suggestion
if "sub_type" in event and (event["sub_type"] == "poke" and "target_id" in event):
abm.message.append(
Poke(qq=str(event["target_id"]), type="poke")
) # noqa: F405
```
<br/><details><summary>Explanation</summary>Too much nesting can make code difficult to understand, and this is especially
true in Python, where there are no brackets to help out with the delineation of
different nesting levels.
Reading deeply nested code is confusing, since you have to keep track of which
conditions relate to which levels. We therefore strive to reduce nesting where
possible, and the situation where two `if` conditions can be combined using
`and` is an easy win.
</details>
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
astrbot/core/platform/sources/aiocqhttp/aiocqhttp_platform_adapter.py
Outdated
Show resolved
Hide resolved
Member
|
修复一下 ci 给出的 code format 错误 |
Member
Author
|
我怎么记得几天前format过了, 是不是时间线不太对 |
Soulter
approved these changes
Sep 19, 2025
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.
Motivation / 动机
当前存在逻辑不一致, 消息段标记的昵称没能获取群昵称(而@可以)
Modifications / 改动点
仅改动获取字段, 优先获取card, 不存在时执行原来逻辑
Verification Steps / 验证步骤
如图
Screenshots or Test Results / 运行截图或测试结果
Compatibility & Breaking Changes / 兼容性与破坏性变更
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.Sourcery 概要
错误修复:
Original summary in English
Summary by Sourcery
Bug Fixes: