Skip to content

Conversation

@clansty
Copy link
Contributor

@clansty clansty commented Jan 6, 2026

Summary by Sourcery

Bug Fixes:

  • 确保在缺少 peerUin 或其值为 0 时,friend_nudge 事件会回退为通过 peerUid 解析 user_id
Original summary in English

Summary by Sourcery

Bug Fixes:

  • Ensure friend_nudge events fall back to resolving user_id from peerUid when peerUin is missing or zero.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 6, 2026

审阅者指南(在小型 PR 上折叠)

审阅者指南

调整 friend_nudge 事件的转换逻辑,当 peerUin 缺失或为 0 时,通过 UID 到 UIN 的查找回退机制,正确推导出一个非零的 user_id

在 transformPrivateMessageEvent 中解析 friend_nudge 的 user_id 的时序图

sequenceDiagram
    participant EventSource
    participant transformPrivateMessageEvent
    participant NTUserApi as ntUserApi
    participant EventConsumer

    EventSource->>transformPrivateMessageEvent: message, ctx, selfInfo
    transformPrivateMessageEvent->>transformPrivateMessageEvent: check elements for busiId 1061
    alt peerUin is non zero
        transformPrivateMessageEvent->>transformPrivateMessageEvent: userId = +message.peerUin
    else peerUin is zero or missing
        transformPrivateMessageEvent->>NTUserApi: getUinByUid(message.peerUid)
        NTUserApi-->>transformPrivateMessageEvent: resolvedUin
        transformPrivateMessageEvent->>transformPrivateMessageEvent: userId = +resolvedUin
    end
    transformPrivateMessageEvent-->>EventConsumer: event { eventType friend_nudge, data.user_id = userId }
Loading

friend_nudge 的 user_id 回退逻辑流程图

flowchart TD
    A[Start: friend_nudge element detected] --> B[Read message.peerUin]
    B --> C{Is +message.peerUin truthy?}
    C -- Yes --> D[Set userId = +message.peerUin]
    C -- No --> E["Call ctx.ntUserApi.getUinByUid(message.peerUid)"]
    E --> F[Set userId = +returnedUin]
    D --> G[Set data.user_id = userId]
    F --> G[Set data.user_id = userId]
    G --> H[Return friend_nudge event with non zero user_id]
    H --> I[End]
Loading

文件级变更

变更 详情 文件
修复 friend_nudge 事件的 user_id 解析逻辑,以处理 peerUin 缺失或为 0 的情况。
  • 引入一个 userId 局部变量,优先使用数值型的 peerUin,如果不可用则通过 ctx.ntUserApi.getUinByUid 使用 peerUid 来解析 UIN
  • 更新 friend_nudge 事件负载,使 user_id 字段使用新的 userId 变量
src/milky/transform/event.ts

提示与命令

与 Sourcery 交互

  • 触发新审查: 在 pull request 中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审查评论。
  • 从审查评论生成 GitHub issue: 通过回复某条审查评论来让 Sourcery 从该评论创建一个 issue。你也可以回复审查评论 @sourcery-ai issue 来从中创建 issue。
  • 生成 pull request 标题: 在 pull request 标题的任意位置写上 @sourcery-ai,即可随时生成标题。你也可以在 pull request 中评论 @sourcery-ai title 来(重新)生成标题。
  • 生成 pull request 摘要: 在 pull request 正文任意位置写上 @sourcery-ai summary,即可在你想要的位置生成 PR 摘要。你也可以在 pull request 中评论 @sourcery-ai summary 来(重新)生成摘要。
  • 生成审阅者指南: 在 pull request 中评论 @sourcery-ai guide,即可在任意时间(重新)生成审阅者指南。
  • 一次性解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve,即可解决所有 Sourcery 评论。适用于你已经处理完所有评论且不想再看到它们的情况。
  • 一次性忽略所有 Sourcery 审查: 在 pull request 中评论 @sourcery-ai dismiss,即可忽略所有现有的 Sourcery 审查。特别适合你希望从一次新的审查重新开始的情况——别忘了再评论 @sourcery-ai review 来触发新的审查!

自定义使用体验

前往你的 控制面板 以:

  • 启用或禁用诸如 Sourcery 生成的 pull request 摘要、审阅者指南等审查功能。
  • 更改审查语言。
  • 添加、移除或编辑自定义审查说明。
  • 调整其他审查相关设置。

获取帮助

Original review guide in English
Reviewer's guide (collapsed on small PRs)

Reviewer's Guide

Adjusts the friend_nudge event transformation to correctly derive a non-zero user_id by falling back to a UID-to-UIN lookup when peerUin is missing or zero.

Sequence diagram for friend_nudge user_id resolution in transformPrivateMessageEvent

sequenceDiagram
    participant EventSource
    participant transformPrivateMessageEvent
    participant NTUserApi as ntUserApi
    participant EventConsumer

    EventSource->>transformPrivateMessageEvent: message, ctx, selfInfo
    transformPrivateMessageEvent->>transformPrivateMessageEvent: check elements for busiId 1061
    alt peerUin is non zero
        transformPrivateMessageEvent->>transformPrivateMessageEvent: userId = +message.peerUin
    else peerUin is zero or missing
        transformPrivateMessageEvent->>NTUserApi: getUinByUid(message.peerUid)
        NTUserApi-->>transformPrivateMessageEvent: resolvedUin
        transformPrivateMessageEvent->>transformPrivateMessageEvent: userId = +resolvedUin
    end
    transformPrivateMessageEvent-->>EventConsumer: event { eventType friend_nudge, data.user_id = userId }
Loading

Flow diagram for friend_nudge user_id fallback logic

flowchart TD
    A[Start: friend_nudge element detected] --> B[Read message.peerUin]
    B --> C{Is +message.peerUin truthy?}
    C -- Yes --> D[Set userId = +message.peerUin]
    C -- No --> E["Call ctx.ntUserApi.getUinByUid(message.peerUid)"]
    E --> F[Set userId = +returnedUin]
    D --> G[Set data.user_id = userId]
    F --> G[Set data.user_id = userId]
    G --> H[Return friend_nudge event with non zero user_id]
    H --> I[End]
Loading

File-Level Changes

Change Details Files
Fix friend_nudge event user_id resolution to handle cases where peerUin is missing or zero.
  • Introduce a userId local variable that prefers numeric peerUin but falls back to resolving UIN from peerUid via ctx.ntUserApi.getUinByUid
  • Update the friend_nudge event payload to use the new userId variable for the user_id field
src/milky/transform/event.ts

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

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.

Hey - 我在这里给出了一些总体反馈:

  • 建议处理这样一种情况:当 peerUingetUinByUid(peerUid) 的结果同时缺失或无效时,+message.peerUin || +(...) 可能会返回 NaN,但当前没有任何后备逻辑或错误处理。
面向 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- Consider handling the case where both `peerUin` and the result of `getUinByUid(peerUid)` are missing or invalid, since `+message.peerUin || +(...)` could yield `NaN` without any fallback or error handling.

Sourcery 对开源项目免费 —— 如果你觉得我们的评审有帮助,欢迎分享 ✨
帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续评审。
Original comment in English

Hey - I've left some high level feedback:

  • Consider handling the case where both peerUin and the result of getUinByUid(peerUid) are missing or invalid, since +message.peerUin || +(...) could yield NaN without any fallback or error handling.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- Consider handling the case where both `peerUin` and the result of `getUinByUid(peerUid)` are missing or invalid, since `+message.peerUin || +(...)` could yield `NaN` without any fallback or error handling.

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.

@clansty
Copy link
Contributor Author

clansty commented Jan 6, 2026

onebot 也是这么修的,napcat 也是这么修的

@linyuchen linyuchen merged commit b2eda7b into LLOneBot:main Jan 7, 2026
1 check 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