Skip to content

Conversation

@anka-afk
Copy link
Member

@anka-afk anka-afk commented Sep 15, 2025


Motivation / 动机

当前存在逻辑不一致, 消息段标记的昵称没能获取群昵称(而@可以)

Modifications / 改动点

仅改动获取字段, 优先获取card, 不存在时执行原来逻辑

Verification Steps / 验证步骤

如图

Screenshots or Test Results / 运行截图或测试结果

image

Compatibility & Breaking Changes / 兼容性与破坏性变更

  • 这是一个破坏性变更 (Breaking Change)。/ This is a breaking change.
  • 这不是一个破坏性变更。/ This is NOT a breaking change.

Checklist / 检查清单

  • 😊 如果 PR 中有新加入的功能,已经通过 Issue / 邮件等方式和作者讨论过。/ If there are new features added in the PR, I have discussed it with the authors through issues/emails, etc.
  • 👀 我的更改经过了良好的测试,并已在上方提供了“验证步骤”和“运行截图”。/ My changes have been well-tested, and "Verification Steps" and "Screenshots" have been provided above.
  • 🤓 我确保没有引入新依赖库,或者引入了新依赖库的同时将其添加到了 requirements.txtpyproject.toml 文件相应位置。/ 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.txt and pyproject.toml.
  • 😮 我的更改没有引入恶意代码。/ My changes do not introduce malicious code.

Sourcery 概要

错误修复:

  • 在构建群聊消息发送者时,优先使用 'card' 字段而非 'nickname',以解决群昵称检索不一致的问题
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Prefer the 'card' field over 'nickname' when constructing the sender for group messages to resolve inconsistent group nickname retrieval

@auto-assign auto-assign bot requested review from Raven95676 and Soulter September 15, 2025 15:38
Copy link
Contributor

@sourcery-ai sourcery-ai bot left a 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>

Sourcery 对开源免费 - 如果您喜欢我们的评论,请考虑分享它们 ✨
帮助我更有用!请点击每个评论上的 👍 或 👎,我将使用反馈来改进您的评论。
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>

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

@Soulter Soulter changed the title fix⚒️: 修复aiocqhttp适配器at会获取群昵称而消息不会获取的逻辑不一致 fix: 修复aiocqhttp适配器at会获取群昵称而消息不会获取的逻辑不一致 Sep 16, 2025
@Soulter
Copy link
Member

Soulter commented Sep 16, 2025

修复一下 ci 给出的 code format 错误

@anka-afk
Copy link
Member Author

我怎么记得几天前format过了, 是不是时间线不太对

@Soulter Soulter changed the title fix: 修复aiocqhttp适配器at会获取群昵称而消息不会获取的逻辑不一致 fix: 修复 aiocqhttp 适配器 at 会获取群昵称而消息不会获取的逻辑不一致 Sep 19, 2025
@Soulter Soulter merged commit a4b43b8 into AstrBotDevs:master Sep 19, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants