Skip to content

Conversation

@yusheng929
Copy link
Contributor

@yusheng929 yusheng929 commented Jan 12, 2026

Summary by Sourcery

为 OneBot 修复并实现跨适配器的「戳一戳用户」功能,通过核心适配器和 OneBot API 将其接入 Lagrange 和 NapCat。

Bug 修复:

  • 修正 pokeUser 适配器方法的函数签名以包含目标用户 ID,解决参数使用错误的问题。

增强内容:

  • 在 OneBot 适配器中实现 pokeUser 逻辑,为 Lagrange 和 NapCat 提供群聊和好友两种场景的支持。
  • 在 OneBot 核心层和 API 层中新增 Lagrange 好友和群组「戳一戳」操作及其对应的 API 定义。
Original summary in English

Summary by Sourcery

Fix and implement cross-adapter "poke user" support for OneBot, wiring it through the core adapter and OneBot APIs for Lagrange and NapCat.

Bug Fixes:

  • Correct the pokeUser adapter method signature to include the target user ID, resolving incorrect parameter usage.

Enhancements:

  • Implement pokeUser logic in the OneBot adapter with support for group and friend contexts on Lagrange and NapCat.
  • Add Lagrange friend and group poke actions and API definitions in the OneBot core and API layer.

Summary by CodeRabbit

  • New Features
    • Enhanced poke functionality allowing callers to specify a target recipient for friend and group pokes.
    • Implemented adapter-level poke handling so poke requests are executed across supported adapters.
    • Added new OneBot/Lagrange poke API actions and corresponding core methods to send friend and group poke requests.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link

coderabbitai bot commented Jan 12, 2026

📝 Walkthrough

Walkthrough

Added a new targetId parameter to adapter poke APIs, implemented pokeUser in the OneBot adapter to forward pokes, and introduced Lagrange OneBot API actions and OneBot core methods for friend/group poke operations.

Changes

Cohort / File(s) Summary
Adapter Base & Types
packages/core/src/adapter/base/index.ts, packages/core/src/types/adapter/class.ts
pokeUser signature updated to include targetId: string (JSDoc updated).
OneBot Adapter Implementation
packages/core/src/adapter/onebot/core/core.ts
Added async pokeUser(_contact: Contact, _targetId: string, _count: number = 1): Promise<boolean> with scene validation, ID coercion, adapter-specific poke handling, and looped execution _count times.
OneBot API Extensions
packages/onebot/src/api/friend.ts, packages/onebot/src/api/group.ts
Added lgl_friendPoke and lgl_groupPoke enum members and corresponding API entries mapping to friend_poke / group_poke actions with parameter shapes.
OneBot Core Methods
packages/onebot/src/core/core.ts
Added lgl_friendPoke(user_id?: number, target_id?: number) and lgl_groupPoke(group_id: number, user_id: number) that call sendApi with the new actions.

Sequence Diagram

sequenceDiagram
    participant Client as Client Code
    participant Adapter as AdapterOneBot
    participant OneBot as OneBotCore
    participant API as OneBot API

    Client->>Adapter: pokeUser(contact, targetId, count)
    activate Adapter
    Adapter->>Adapter: validate scene & extract IDs
    alt friend scene
        Adapter->>OneBot: lgl_friendPoke(user_id, target_id)
    else group scene
        Adapter->>OneBot: lgl_groupPoke(group_id, user_id)
    end
    deactivate Adapter

    activate OneBot
    OneBot->>API: sendApi(action, params)
    API-->>OneBot: response
    OneBot-->>Adapter: result
    deactivate OneBot

    Adapter-->>Client: Promise<boolean>
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Poem

🐰 A little hop, a gentle prod so spry,
Target ID in paw, I nudge and say hi,
OneBot carries whispers through group and friend,
From interface to action, the pokes now extend,
Hooray — a rabbit's cheer for code that will send!

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective: fixing the pokeUser parameter error by adding the missing _targetId parameter across the adapter base class, OneBot implementation, and related API definitions.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Jan 12, 2026

Reviewer 的指南

在 OneBot 适配器和核心中实现 pokeUser 功能,使其在 Lagrange 和 NapCat 上都可用,增加对 targetId 的正确处理以及好友和群戳一戳操作对应的 OneBot API 定义,同时更新基础适配器接口签名,并修复一个轻微的 JSDoc 缩进问题。

通过 OneBot 适配器进行 pokeUser 交互的时序图

sequenceDiagram
  actor User
  participant Client as BotClient
  participant Adapter as AdapterOneBot
  participant Core as OneBotCore
  participant OB as OneBotBackend

  User->>Client: request pokeUser(contact, targetId, count)
  Client->>Adapter: pokeUser(contact, targetId, count)
  Adapter->>Adapter: validate scene (group or friend)
  Adapter->>Adapter: peerId = +contact.peer
  Adapter->>Adapter: targetNum = +targetId

  alt adapter.name == Lagrange.OneBot
    alt contact.scene == group
      loop count times
        Adapter->>Core: lgl_groupPoke(peerId, targetNum)
        Core->>OB: sendApi(lgl_group_poke, {group_id, user_id})
        OB-->>Core: null
      end
    else contact.scene == friend
      loop count times
        Adapter->>Core: lgl_friendPoke(targetNum, targetNum)
        Core->>OB: sendApi(lgl_friend_poke, {user_id, target_id})
        OB-->>Core: null
      end
    end
  else adapter.name == NapCat.Onebot
    alt contact.scene == group
      loop count times
        Adapter->>Core: nc_groupPoke(peerId, targetNum)
        Core->>OB: sendApi(nc_group_poke, {group_id, user_id})
        OB-->>Core: null
      end
    else contact.scene == friend
      loop count times
        Adapter->>Core: nc_friendPoke(targetNum)
        Core->>OB: sendApi(nc_friend_poke, {user_id})
        OB-->>Core: null
      end
    end
  else unsupported adapter
    Adapter->>Client: throw Error(adapter.name + " 不支持戳一戳功能")
  end

  Adapter-->>Client: true
  Client-->>User: poke success response
Loading

适配器和 OneBot 核心中更新后的 pokeUser 流程类图

classDiagram
  class Contact {
    +string scene
    +string peer
  }

  class AdapterBase {
    <<abstract>>
    +pokeUser(contact: Contact, targetId: string, count: number) Promise~boolean~
  }

  class AdapterOneBot {
    <<generic>>
    -adapter: any
    -_onebot: OneBotCore
    +pokeUser(contact: Contact, targetId: string, count: number) Promise~boolean~
  }

  class OneBotCore {
    <<abstract>>
    +lgl_friendPoke(user_id: number, target_id: number) Promise~any~
    +lgl_groupPoke(group_id: number, user_id: number) Promise~any~
    +nc_friendPoke(user_id: number) Promise~any~
    +nc_groupPoke(group_id: number, user_id: number) Promise~any~
  }

  class OneBotFriendApiAction {
    <<enumeration>>
    nc_friendPoke
    lgl_friendPoke
  }

  class OneBotGroupApiAction {
    <<enumeration>>
    lgl_groupPoke
  }

  class OneBotFriendApi {
    <<interface>>
    +[nc_friendPoke]: nc_friendPoke
    +[lgl_friendPoke]: lgl_friendPoke
  }

  class OneBotGroupApi {
    <<interface>>
    +[lgl_groupPoke]: lgl_groupPoke
  }

  AdapterOneBot ..|> AdapterBase
  OneBotCore <.. AdapterOneBot
  OneBotFriendApiAction <.. OneBotCore
  OneBotGroupApiAction <.. OneBotCore
  OneBotFriendApiAction <.. OneBotFriendApi
  OneBotGroupApiAction <.. OneBotGroupApi
  Contact <.. AdapterBase
  Contact <.. AdapterOneBot
Loading

文件级变更

Change Details Files
在 OneBot 适配器中为 Lagrange 和 NapCat 实现带目标用户支持和可配置次数的 pokeUser 行为。
  • 用一个具体的 pokeUser 实现替换未实现的 PokeMember 方法,该实现会校验场景(群聊/好友)并将 ID 转为数字。
  • 根据联系人场景和适配器名称(Lagrange.OneBot 或 NapCat.Onebot)选择合适的戳一戳 API(群或好友),不支持时抛出异常。
  • 将选定的戳一戳操作循环执行 _count 次,并在成功时返回 true。
  • 调整 forwardKarinConvertAdapter 方法的 JSDoc 缩进。
packages/core/src/adapter/onebot/core/core.ts
为 Lagrange 的好友和群戳一戳操作添加 OneBot 核心层和 API 层支持。
  • 新增 OneBotCore.lgl_friendPoke 和 lgl_groupPoke 帮助方法,这些方法委托给 sendApi 并使用新的 action。
  • 在 OneBotFriendApiAction 中扩展 lgl_friendPoke,并在 OneBotFriendApi 中定义其请求/响应结构。
  • 在 OneBotGroupApiAction 中扩展 lgl_groupPoke,并在 OneBotGroupApi 中定义其请求/响应结构。
packages/onebot/src/core/core.ts
packages/onebot/src/api/friend.ts
packages/onebot/src/api/group.ts
更新通用适配器基类和类型接口,使其在 pokeUser 中接收 targetId 参数。
  • 将 AdapterBase.pokeUser 的签名修改为在 count 参数之前包含 _targetId: string,同时保留默认的错误行为。
  • 更新 AdapterType.pokeUser 的接口定义,使其与新的 (contact, targetId, count?) 签名及 JSDoc 保持一致。
packages/core/src/adapter/base/index.ts
packages/core/src/types/adapter/class.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 以在任何时间(重新)生成摘要。
  • 生成 reviewer 的指南: 在 pull request 中评论 @sourcery-ai guide,即可在任何时间(重新)生成 reviewer 的指南。
  • 解决所有 Sourcery 评论: 在 pull request 中评论 @sourcery-ai resolve 来解决所有 Sourcery 评论。如果你已经处理了所有评论且不想再看到它们,这非常有用。
  • 关闭所有 Sourcery 评审: 在 pull request 中评论 @sourcery-ai dismiss 来关闭所有现有的 Sourcery 评审。如果你想从一个新的评审开始,这尤其有用——别忘了再评论 @sourcery-ai review 来触发新的评审!

自定义你的体验

访问你的 dashboard 以:

  • 启用或禁用评审功能,如 Sourcery 生成的 pull request 摘要、reviewer 的指南等。
  • 更改评审语言。
  • 添加、移除或编辑自定义评审指令。
  • 调整其他评审设置。

获取帮助

Original review guide in English

Reviewer's Guide

Implements the pokeUser feature across the OneBot adapter and core for both Lagrange and NapCat, adding proper targetId handling and corresponding OneBot API definitions for friend and group poke actions, while updating the base adapter interface signature and fixing a minor JSDoc indentation issue.

Sequence diagram for pokeUser interaction via OneBot adapter

sequenceDiagram
  actor User
  participant Client as BotClient
  participant Adapter as AdapterOneBot
  participant Core as OneBotCore
  participant OB as OneBotBackend

  User->>Client: request pokeUser(contact, targetId, count)
  Client->>Adapter: pokeUser(contact, targetId, count)
  Adapter->>Adapter: validate scene (group or friend)
  Adapter->>Adapter: peerId = +contact.peer
  Adapter->>Adapter: targetNum = +targetId

  alt adapter.name == Lagrange.OneBot
    alt contact.scene == group
      loop count times
        Adapter->>Core: lgl_groupPoke(peerId, targetNum)
        Core->>OB: sendApi(lgl_group_poke, {group_id, user_id})
        OB-->>Core: null
      end
    else contact.scene == friend
      loop count times
        Adapter->>Core: lgl_friendPoke(targetNum, targetNum)
        Core->>OB: sendApi(lgl_friend_poke, {user_id, target_id})
        OB-->>Core: null
      end
    end
  else adapter.name == NapCat.Onebot
    alt contact.scene == group
      loop count times
        Adapter->>Core: nc_groupPoke(peerId, targetNum)
        Core->>OB: sendApi(nc_group_poke, {group_id, user_id})
        OB-->>Core: null
      end
    else contact.scene == friend
      loop count times
        Adapter->>Core: nc_friendPoke(targetNum)
        Core->>OB: sendApi(nc_friend_poke, {user_id})
        OB-->>Core: null
      end
    end
  else unsupported adapter
    Adapter->>Client: throw Error(adapter.name + " 不支持戳一戳功能")
  end

  Adapter-->>Client: true
  Client-->>User: poke success response
Loading

Class diagram for updated pokeUser flow in adapters and OneBot core

classDiagram
  class Contact {
    +string scene
    +string peer
  }

  class AdapterBase {
    <<abstract>>
    +pokeUser(contact: Contact, targetId: string, count: number) Promise~boolean~
  }

  class AdapterOneBot {
    <<generic>>
    -adapter: any
    -_onebot: OneBotCore
    +pokeUser(contact: Contact, targetId: string, count: number) Promise~boolean~
  }

  class OneBotCore {
    <<abstract>>
    +lgl_friendPoke(user_id: number, target_id: number) Promise~any~
    +lgl_groupPoke(group_id: number, user_id: number) Promise~any~
    +nc_friendPoke(user_id: number) Promise~any~
    +nc_groupPoke(group_id: number, user_id: number) Promise~any~
  }

  class OneBotFriendApiAction {
    <<enumeration>>
    nc_friendPoke
    lgl_friendPoke
  }

  class OneBotGroupApiAction {
    <<enumeration>>
    lgl_groupPoke
  }

  class OneBotFriendApi {
    <<interface>>
    +[nc_friendPoke]: nc_friendPoke
    +[lgl_friendPoke]: lgl_friendPoke
  }

  class OneBotGroupApi {
    <<interface>>
    +[lgl_groupPoke]: lgl_groupPoke
  }

  AdapterOneBot ..|> AdapterBase
  OneBotCore <.. AdapterOneBot
  OneBotFriendApiAction <.. OneBotCore
  OneBotGroupApiAction <.. OneBotCore
  OneBotFriendApiAction <.. OneBotFriendApi
  OneBotGroupApiAction <.. OneBotGroupApi
  Contact <.. AdapterBase
  Contact <.. AdapterOneBot
Loading

File-Level Changes

Change Details Files
Implement pokeUser behavior in the OneBot adapter for Lagrange and NapCat with target user support and configurable count.
  • Replace the unimplemented PokeMember method with a concrete pokeUser implementation that validates scene (group/friend) and converts IDs to numbers.
  • Select appropriate poke API (group or friend) based on contact scene and adapter name (Lagrange.OneBot or NapCat.Onebot), throwing if unsupported.
  • Loop the selected poke operation _count times and return true on success.
  • Adjust JSDoc for the forwardKarinConvertAdapter method indentation.
packages/core/src/adapter/onebot/core/core.ts
Add OneBot core and API-layer support for Lagrange friend and group poke operations.
  • Introduce OneBotCore.lgl_friendPoke and lgl_groupPoke helper methods that delegate to sendApi with the new actions.
  • Extend OneBotFriendApiAction with lgl_friendPoke and define its request/response shape in OneBotFriendApi.
  • Extend OneBotGroupApiAction with lgl_groupPoke and define its request/response shape in OneBotGroupApi.
packages/onebot/src/core/core.ts
packages/onebot/src/api/friend.ts
packages/onebot/src/api/group.ts
Update the generic adapter base and type interface to accept a targetId parameter for pokeUser.
  • Change AdapterBase.pokeUser signature to include _targetId: string before the count parameter, keeping default error behavior.
  • Update AdapterType.pokeUser interface definition to match the new (contact, targetId, count?) signature and JSDoc.
packages/core/src/adapter/base/index.ts
packages/core/src/types/adapter/class.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

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @yusheng929, 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!

此拉取请求解决了pokeUser方法缺少必要的targetId参数以及在OneBot适配器中未完全实现的问题。它标准化了pokeUser接口,并为OneBot提供了具体的实现,从而为Lagrange和NapCat平台启用了“戳一戳”功能。

Highlights

  • 方法签名更新: 更新了核心适配器和类型定义中pokeUser方法的签名,以包含目标用户ID参数。
  • OneBot适配器实现: 为OneBot适配器实现了pokeUser功能,支持Lagrange和NapCat平台的“戳一戳”操作。
  • Lagrange扩展API: 引入了Lagrange特有的“戳一戳”API动作和相应的实现方法。

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The 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 /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

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 .gemini/ folder in the base of the repository. Detailed instructions can be found here.

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

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

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 - 我发现了两个问题,并且给出了一些整体反馈:

  • OneBotFriendApiAction.lgl_friendPoke 中,枚举值是 'lgl_friend_poke',但对应的 API 接口使用的是 action: 'friend_poke';这个不一致很可能会导致请求使用错误的 action 名称发送,需要进行对齐。
  • pokeUser 的实现会在一个循环中用 await 顺序调用 _count 次戳一戳;如果预期会有较大的次数,建议限制最大值或者在文档中说明只支持较小的次数,以避免产生阻塞行为。
供 AI Agent 使用的提示词
Please address the comments from this code review:

## Overall Comments
- In `OneBotFriendApiAction.lgl_friendPoke` the enum value is `'lgl_friend_poke'` but the corresponding API interface uses `action: 'friend_poke'`; this mismatch is likely to cause requests to be sent with the wrong action name and should be aligned.
- The `pokeUser` implementation performs `_count` sequential pokes with `await` in a loop; if higher counts are expected, consider guarding against large values or clarifying that only small counts are supported to avoid blocking behavior.

## Individual Comments

### Comment 1
<location> `packages/core/src/adapter/onebot/core/core.ts:1007-1013` </location>
<code_context>
+    if (!['group', 'friend'].includes(_contact.scene)) {
+      throw new Error('不支持的场景')
+    }
+    const peerId = +_contact.peer
+    const targetId = +_targetId
+
+    let pokeOnce: () => Promise<null>
</code_context>

<issue_to_address>
**suggestion (bug_risk):** The implicit numeric coercion via unary `+` may silently produce `NaN`; consider stricter typing or validation.

This relies on `+_contact.peer` and `+_targetId` always being numeric strings; any non-numeric or empty value will become `NaN` and be passed to OneBot, causing opaque failures. Either ensure these are typed as `number` at the call sites and drop the coercion, or validate the result (e.g., check for finite numbers) and throw a clear error if invalid.

```suggestion
    if (!['group', 'friend'].includes(_contact.scene)) {
      throw new Error('不支持的场景')
    }

    const peerId = Number(_contact.peer)
    const targetId = Number(_targetId)

    if (!Number.isFinite(targetId) || (_contact.scene === 'group' && !Number.isFinite(peerId))) {
      throw new Error('无效的戳一戳目标或来源 ID')
    }

    let pokeOnce: () => Promise<null>
```
</issue_to_address>

### Comment 2
<location> `packages/onebot/src/core/core.ts:1013-1015` </location>
<code_context>
+  /** Lagrange扩展: 好友戳一戳
+   * @param user_id - 目标ID
+   */
+  async lgl_friendPoke (
+    user_id?: number,
+    target_id?: number
+  ) {
+    return this.sendApi(OneBotFriendApiAction.lgl_friendPoke, {
</code_context>

<issue_to_address>
**suggestion:** The JSDoc for `lgl_friendPoke` doesn’t match the two-parameter signature and can cause confusion.

The doc currently describes only `user_id` as the target, but the method takes both `user_id?` and `target_id?`. Please clarify which parameter is the actor and which is the friend being poked, and update the naming/docs to match how `pokeUser` supplies these arguments to avoid misuse.

Suggested implementation:

```typescript
  /** Lagrange扩展: 好友戳一戳
   * @param user_id - 发起戳一戳的用户 ID(操作者);如果省略则使用当前登录账号
   * @param target_id - 被戳一戳的好友 ID(目标)
   */
  async lgl_friendPoke (
    user_id?: number,
    target_id?: number
  ) {

```

If `pokeUser` (or any other helper) relies on a specific ordering/semantics (e.g. first argument is always the bot/self, second is the friend), consider adding a short reference in this JSDoc (e.g. “参数顺序与 pokeUser 保持一致”) or updating `pokeUser`’s own documentation to mirror this description so callers see consistent semantics across both APIs.
</issue_to_address>

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

Hey - I've found 2 issues, and left some high level feedback:

  • In OneBotFriendApiAction.lgl_friendPoke the enum value is 'lgl_friend_poke' but the corresponding API interface uses action: 'friend_poke'; this mismatch is likely to cause requests to be sent with the wrong action name and should be aligned.
  • The pokeUser implementation performs _count sequential pokes with await in a loop; if higher counts are expected, consider guarding against large values or clarifying that only small counts are supported to avoid blocking behavior.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `OneBotFriendApiAction.lgl_friendPoke` the enum value is `'lgl_friend_poke'` but the corresponding API interface uses `action: 'friend_poke'`; this mismatch is likely to cause requests to be sent with the wrong action name and should be aligned.
- The `pokeUser` implementation performs `_count` sequential pokes with `await` in a loop; if higher counts are expected, consider guarding against large values or clarifying that only small counts are supported to avoid blocking behavior.

## Individual Comments

### Comment 1
<location> `packages/core/src/adapter/onebot/core/core.ts:1007-1013` </location>
<code_context>
+    if (!['group', 'friend'].includes(_contact.scene)) {
+      throw new Error('不支持的场景')
+    }
+    const peerId = +_contact.peer
+    const targetId = +_targetId
+
+    let pokeOnce: () => Promise<null>
</code_context>

<issue_to_address>
**suggestion (bug_risk):** The implicit numeric coercion via unary `+` may silently produce `NaN`; consider stricter typing or validation.

This relies on `+_contact.peer` and `+_targetId` always being numeric strings; any non-numeric or empty value will become `NaN` and be passed to OneBot, causing opaque failures. Either ensure these are typed as `number` at the call sites and drop the coercion, or validate the result (e.g., check for finite numbers) and throw a clear error if invalid.

```suggestion
    if (!['group', 'friend'].includes(_contact.scene)) {
      throw new Error('不支持的场景')
    }

    const peerId = Number(_contact.peer)
    const targetId = Number(_targetId)

    if (!Number.isFinite(targetId) || (_contact.scene === 'group' && !Number.isFinite(peerId))) {
      throw new Error('无效的戳一戳目标或来源 ID')
    }

    let pokeOnce: () => Promise<null>
```
</issue_to_address>

### Comment 2
<location> `packages/onebot/src/core/core.ts:1013-1015` </location>
<code_context>
+  /** Lagrange扩展: 好友戳一戳
+   * @param user_id - 目标ID
+   */
+  async lgl_friendPoke (
+    user_id?: number,
+    target_id?: number
+  ) {
+    return this.sendApi(OneBotFriendApiAction.lgl_friendPoke, {
</code_context>

<issue_to_address>
**suggestion:** The JSDoc for `lgl_friendPoke` doesn’t match the two-parameter signature and can cause confusion.

The doc currently describes only `user_id` as the target, but the method takes both `user_id?` and `target_id?`. Please clarify which parameter is the actor and which is the friend being poked, and update the naming/docs to match how `pokeUser` supplies these arguments to avoid misuse.

Suggested implementation:

```typescript
  /** Lagrange扩展: 好友戳一戳
   * @param user_id - 发起戳一戳的用户 ID(操作者);如果省略则使用当前登录账号
   * @param target_id - 被戳一戳的好友 ID(目标)
   */
  async lgl_friendPoke (
    user_id?: number,
    target_id?: number
  ) {

```

If `pokeUser` (or any other helper) relies on a specific ordering/semantics (e.g. first argument is always the bot/self, second is the friend), consider adding a short reference in this JSDoc (e.g. “参数顺序与 pokeUser 保持一致”) or updating `pokeUser`’s own documentation to mirror this description so callers see consistent semantics across both APIs.
</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.

Comment on lines 1007 to 1013
if (!['group', 'friend'].includes(_contact.scene)) {
throw new Error('不支持的场景')
}
const peerId = +_contact.peer
const targetId = +_targetId

let pokeOnce: () => Promise<null>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion (bug_risk): 通过一元 + 进行隐式数字类型转换可能会在不显式报错的情况下产生 NaN;建议使用更严格的类型或校验逻辑。

这里依赖 +_contact.peer+_targetId 始终为数字字符串;任何非数字或空字符串都会变成 NaN 并传给 OneBot,导致难以排查的问题。可以考虑在调用方就将这些值声明为 number 并移除这里的强制转换,或者在转换后进行校验(例如检查是否为有限数字),如果无效则抛出明确的错误。

Suggested change
if (!['group', 'friend'].includes(_contact.scene)) {
throw new Error('不支持的场景')
}
const peerId = +_contact.peer
const targetId = +_targetId
let pokeOnce: () => Promise<null>
if (!['group', 'friend'].includes(_contact.scene)) {
throw new Error('不支持的场景')
}
const peerId = Number(_contact.peer)
const targetId = Number(_targetId)
if (!Number.isFinite(targetId) || (_contact.scene === 'group' && !Number.isFinite(peerId))) {
throw new Error('无效的戳一戳目标或来源 ID')
}
let pokeOnce: () => Promise<null>
Original comment in English

suggestion (bug_risk): The implicit numeric coercion via unary + may silently produce NaN; consider stricter typing or validation.

This relies on +_contact.peer and +_targetId always being numeric strings; any non-numeric or empty value will become NaN and be passed to OneBot, causing opaque failures. Either ensure these are typed as number at the call sites and drop the coercion, or validate the result (e.g., check for finite numbers) and throw a clear error if invalid.

Suggested change
if (!['group', 'friend'].includes(_contact.scene)) {
throw new Error('不支持的场景')
}
const peerId = +_contact.peer
const targetId = +_targetId
let pokeOnce: () => Promise<null>
if (!['group', 'friend'].includes(_contact.scene)) {
throw new Error('不支持的场景')
}
const peerId = Number(_contact.peer)
const targetId = Number(_targetId)
if (!Number.isFinite(targetId) || (_contact.scene === 'group' && !Number.isFinite(peerId))) {
throw new Error('无效的戳一戳目标或来源 ID')
}
let pokeOnce: () => Promise<null>

Comment on lines +1013 to +1015
async lgl_friendPoke (
user_id?: number,
target_id?: number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

suggestion: lgl_friendPoke 的 JSDoc 与其两个参数的函数签名不匹配,可能会引起误解。

当前文档只把 user_id 描述为目标,但方法实际接收 user_id?target_id? 两个参数。请明确说明哪个参数是发起戳一戳的用户,哪个是被戳的好友,并根据 pokeUser 传参方式调整命名/文档,避免被误用。

建议实现如下:

  /** Lagrange扩展: 好友戳一戳
   * @param user_id - 发起戳一戳的用户 ID(操作者);如果省略则使用当前登录账号
   * @param target_id - 被戳一戳的好友 ID(目标)
   */
  async lgl_friendPoke (
    user_id?: number,
    target_id?: number
  ) {

如果 pokeUser(或其他辅助方法)依赖特定的参数顺序/语义(例如第一个参数总是机器人/自身,第二个是好友),建议在这个 JSDoc 中加一句简短说明(例如“参数顺序与 pokeUser 保持一致”),或者在 pokeUser 自身的文档中补充相同描述,让调用方在两个 API 之间得到一致的语义预期。

Original comment in English

suggestion: The JSDoc for lgl_friendPoke doesn’t match the two-parameter signature and can cause confusion.

The doc currently describes only user_id as the target, but the method takes both user_id? and target_id?. Please clarify which parameter is the actor and which is the friend being poked, and update the naming/docs to match how pokeUser supplies these arguments to avoid misuse.

Suggested implementation:

  /** Lagrange扩展: 好友戳一戳
   * @param user_id - 发起戳一戳的用户 ID(操作者);如果省略则使用当前登录账号
   * @param target_id - 被戳一戳的好友 ID(目标)
   */
  async lgl_friendPoke (
    user_id?: number,
    target_id?: number
  ) {

If pokeUser (or any other helper) relies on a specific ordering/semantics (e.g. first argument is always the bot/self, second is the friend), consider adding a short reference in this JSDoc (e.g. “参数顺序与 pokeUser 保持一致”) or updating pokeUser’s own documentation to mirror this description so callers see consistent semantics across both APIs.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

你好,感谢你对项目的贡献。这次的 Pull Request 修复了 pokeUser 的参数问题,并为 Lagrange 和 NapCat 适配器实现了「戳一戳」功能,整体实现思路清晰,代码结构合理。我主要针对代码的可维护性和文档清晰度提出了一些建议,希望能帮助你进一步完善代码。请查看具体的审查评论。

Comment on lines 1015 to 1025
if (this.adapter.name === 'Lagrange.OneBot') {
pokeOnce = _contact.scene === 'group'
? () => this._onebot.lgl_groupPoke(peerId, targetId)
: () => this._onebot.lgl_friendPoke(targetId)
} else if (this.adapter.name === 'NapCat.Onebot') {
pokeOnce = _contact.scene === 'group'
? () => this._onebot.nc_groupPoke(peerId, targetId)
: () => this._onebot.nc_friendPoke(targetId)
} else {
throw new Error(`${this.adapter.name} 不支持戳一戳功能`)
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

为了提高代码的可读性和可扩展性,建议重构此处的 if/else if 逻辑。您可以使用一个映射表(map)来根据适配器名称和场景动态选择对应的 poke 函数。这样可以避免未来增加新适配器时需要不断追加 else if 分支,使代码更易于维护。

Suggested change
if (this.adapter.name === 'Lagrange.OneBot') {
pokeOnce = _contact.scene === 'group'
? () => this._onebot.lgl_groupPoke(peerId, targetId)
: () => this._onebot.lgl_friendPoke(targetId)
} else if (this.adapter.name === 'NapCat.Onebot') {
pokeOnce = _contact.scene === 'group'
? () => this._onebot.nc_groupPoke(peerId, targetId)
: () => this._onebot.nc_friendPoke(targetId)
} else {
throw new Error(`${this.adapter.name} 不支持戳一戳功能`)
}
const pokeActions = {
'Lagrange.OneBot': {
group: () => this._onebot.lgl_groupPoke(peerId, targetId),
friend: () => this._onebot.lgl_friendPoke(targetId)
},
'NapCat.Onebot': {
group: () => this._onebot.nc_groupPoke(peerId, targetId),
friend: () => this._onebot.nc_friendPoke(targetId)
}
}
const adapterActions = pokeActions[this.adapter.name as keyof typeof pokeActions]
if (!adapterActions) {
throw new Error(`${this.adapter.name} 不支持戳一戳功能`)
}
pokeOnce = adapterActions[_contact.scene as keyof typeof adapterActions]

Comment on lines 1066 to +1071
/**
* 合并转发 karin -> adapter
* @param elements 消息元素
* @param options 首层小卡片外显参数
* @returns 适配器消息元素
*/
* 合并转发 karin -> adapter
* @param elements 消息元素
* @param options 首层小卡片外显参数
* @returns 适配器消息元素
*/
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

这个 JSDoc 注释块的缩进似乎不正确,导致其内容没有与 /** 对齐。为了保持代码风格统一,建议修正此处的缩进。

Suggested change
/**
* 合并转发 karin -> adapter
* @param elements 消息元素
* @param options 首层小卡片外显参数
* @returns 适配器消息元素
*/
* 合并转发 karin -> adapter
* @param elements 消息元素
* @param options 首层小卡片外显参数
* @returns 适配器消息元素
*/
/**
* 合并转发 karin -> adapter
* @param elements 消息元素
* @param options 首层小卡片外显参数
* @returns 适配器消息元素
*/

Comment on lines +1013 to +1016
async lgl_friendPoke (
user_id?: number,
target_id?: number
) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

lgl_friendPoke 函数签名中包含了 target_id 参数,但在 JSDoc 中没有对应的文档说明。为了代码清晰和易于维护,请为 target_id 参数添加说明,解释其用途。如果该参数没有实际用途,建议从函数签名中移除以避免混淆。

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Fix all issues with AI agents
In @packages/core/src/adapter/onebot/core/core.ts:
- Around line 1000-1032: In pokeUser, friend poke calls pass only targetId
causing it to bind to user_id; update the friend calls so both parameters are
passed in the correct order (user_id, target_id) — i.e. call
lgl_friendPoke(peerId, targetId) and nc_friendPoke(peerId, targetId) instead of
the single-argument versions inside the pokeUser method so the user context and
target are both provided.

In @packages/onebot/src/core/core.ts:
- Around line 1010-1021: The JSDoc for async lgl_friendPoke is wrong/incomplete:
update the comment above lgl_friendPoke to document both parameters correctly
(user_id and target_id) with accurate descriptions and types and a short summary
of the method’s purpose; specifically, make user_id the caller/initiator ID,
target_id the target/recipient ID, and include the return type/description for
the Promise returned by sendApi (or a brief "Promise resolving to API
response"). Ensure the docblock references the function name lgl_friendPoke and
the parameters user_id and target_id so the comment matches the signature.
🧹 Nitpick comments (1)
packages/core/src/adapter/onebot/core/core.ts (1)

1067-1071: Minor: JSDoc indentation is inconsistent with the rest of the file.

The JSDoc block uses extra leading spaces compared to other method documentation in the file (e.g., compare with pokeUser JSDoc above). This is purely cosmetic.

🔧 Suggested fix
   /**
-     * 合并转发 karin -> adapter
-     * @param elements 消息元素
-     * @param options 首层小卡片外显参数
-     * @returns 适配器消息元素
-     */
+   * 合并转发 karin -> adapter
+   * @param elements 消息元素
+   * @param options 首层小卡片外显参数
+   * @returns 适配器消息元素
+   */
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between fc7b3cf and 51f4ecc.

📒 Files selected for processing (6)
  • packages/core/src/adapter/base/index.ts
  • packages/core/src/adapter/onebot/core/core.ts
  • packages/core/src/types/adapter/class.ts
  • packages/onebot/src/api/friend.ts
  • packages/onebot/src/api/group.ts
  • packages/onebot/src/core/core.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Sourcery review
  • GitHub Check: publish-temp
🔇 Additional comments (5)
packages/onebot/src/core/core.ts (1)

1538-1550: LGTM!

The lgl_groupPoke method implementation correctly mirrors the existing nc_groupPoke pattern and properly invokes the API action with the expected parameters.

packages/onebot/src/api/group.ts (1)

14-14: LGTM!

The new lgl_groupPoke enum member and interface entry correctly mirror the existing nc_groupPoke pattern. Using the same underlying action value 'group_poke' while having distinct enum keys is consistent with how other Lagrange/NapCat extension pairs are defined in this codebase (e.g., lgl_setGroupLeave and setGroupLeave).

Also applies to: 533-541

packages/onebot/src/api/friend.ts (1)

23-23: LGTM!

The new lgl_friendPoke enum member and interface entry correctly mirror the existing nc_friendPoke pattern, maintaining consistency with the Lagrange extension naming convention used throughout the codebase.

Also applies to: 282-291

packages/core/src/adapter/base/index.ts (1)

550-558: LGTM!

The base adapter class correctly implements the updated pokeUser signature with the new _targetId parameter, maintaining consistency with the AdapterType interface definition.

packages/core/src/types/adapter/class.ts (1)

442-447: Breaking API change - all implementations verified and updated.

The pokeUser method signature now includes a required targetId parameter (fixing issue #576). All active adapter implementations have been updated to match:

  • AdapterBase: pokeUser(_contact, _targetId, _count?)
  • AdapterOneBot: pokeUser(_contact, _targetId, _count = 1)
  • AdapterConsole: inherits from AdapterBase

The breaking change is appropriately scoped and complete.

Comment on lines 1000 to 1032
/**
* 戳一戳用户
* @param _contact 事件来源
* @param _targetId 被戳目标ID
* @param _count 戳一戳次数,默认1
*/
async pokeUser (_contact: Contact, _targetId: string, _count: number = 1): Promise<boolean> {
if (!['group', 'friend'].includes(_contact.scene)) {
throw new Error('不支持的场景')
}
const peerId = +_contact.peer
const targetId = +_targetId

let pokeOnce: () => Promise<null>

if (this.adapter.name === 'Lagrange.OneBot') {
pokeOnce = _contact.scene === 'group'
? () => this._onebot.lgl_groupPoke(peerId, targetId)
: () => this._onebot.lgl_friendPoke(targetId)
} else if (this.adapter.name === 'NapCat.Onebot') {
pokeOnce = _contact.scene === 'group'
? () => this._onebot.nc_groupPoke(peerId, targetId)
: () => this._onebot.nc_friendPoke(targetId)
} else {
throw new Error(`${this.adapter.name} 不支持戳一戳功能`)
}

for (let i = 0; i < _count; i++) {
await pokeOnce()
}

return true
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🔴 Critical

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Verify the poke API methods are defined
echo "=== Searching for lgl_groupPoke and lgl_friendPoke ==="
rg -n "lgl_groupPoke|lgl_friendPoke" --type ts -C 2

echo ""
echo "=== Searching for nc_groupPoke and nc_friendPoke ==="
rg -n "nc_groupPoke|nc_friendPoke" --type ts -C 2

echo ""
echo "=== Checking structure of @karinjs/onebot or similar package references ==="
find . -name "*onebot*" -type f -name "*.ts" -o -name "*.d.ts" | head -20

Repository: KarinJS/Karin

Length of output: 6548


Fix parameter passing for friend poke methods.

All four poke API methods (lgl_groupPoke, lgl_friendPoke, nc_groupPoke, nc_friendPoke) exist in the codebase, but there is a critical parameter mismatch in the friend poke calls.

The friend poke methods are defined as:

  • lgl_friendPoke(user_id?: number, target_id?: number)
  • nc_friendPoke(user_id?: number, target_id?: number)

However, in the pokeUser method, they are called with only one argument:

  • this._onebot.lgl_friendPoke(targetId) (line 1018)
  • this._onebot.nc_friendPoke(targetId) (line 1022)

This causes the targetId to be assigned to the first parameter (user_id) instead of the second parameter (target_id), leaving target_id undefined. The friend poke calls require both parameters to be passed correctly. Either pass both arguments with the correct user context, or adjust the method calls to explicitly specify which parameter receives the value.

The group poke calls are correct and properly pass both peerId and targetId arguments.

🤖 Prompt for AI Agents
In @packages/core/src/adapter/onebot/core/core.ts around lines 1000 - 1032, In
pokeUser, friend poke calls pass only targetId causing it to bind to user_id;
update the friend calls so both parameters are passed in the correct order
(user_id, target_id) — i.e. call lgl_friendPoke(peerId, targetId) and
nc_friendPoke(peerId, targetId) instead of the single-argument versions inside
the pokeUser method so the user context and target are both provided.

@github-actions
Copy link
Contributor

你可以通过以下命令安装该版本:

pnpm add https://pkg.pr.new/KarinJS/Karin/node-karin@f6f6e10 -w

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In @packages/core/src/adapter/onebot/core/core.ts:
- Around line 1006-1036: In pokeUser, _count can be 0 or negative so the loop
may never run while the function still returns true; validate _count at the
start of the function (pokeUser) by either throwing a descriptive error when
_count < 1 or normalizing it (e.g., set _count = Math.max(1, _count)) before the
for-loop, and update the error message/behavior accordingly so callers know no
poke was performed if an invalid count was passed.
🧹 Nitpick comments (1)
packages/core/src/adapter/onebot/core/core.ts (1)

1071-1076: Fix inconsistent docblock indentation.

The docblock content lines have extra indentation (5 spaces) compared to the standard 2-space indentation used elsewhere in this file.

✏️ Suggested fix
   /**
-     * 合并转发 karin -> adapter
-     * @param elements 消息元素
-     * @param options 首层小卡片外显参数
-     * @returns 适配器消息元素
-     */
+   * 合并转发 karin -> adapter
+   * @param elements 消息元素
+   * @param options 首层小卡片外显参数
+   * @returns 适配器消息元素
+   */
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 51f4ecc and f6f6e10.

📒 Files selected for processing (2)
  • packages/core/src/adapter/onebot/core/core.ts
  • packages/onebot/src/core/core.ts
🚧 Files skipped from review as they are similar to previous changes (1)
  • packages/onebot/src/core/core.ts
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: Sourcery review
  • GitHub Check: publish-temp
🔇 Additional comments (1)
packages/core/src/adapter/onebot/core/core.ts (1)

1014-1023: Clean handler pattern for adapter-specific poke implementations.

The handler map approach is well-structured and makes it easy to add support for additional adapters in the future while maintaining type safety with as const.

Comment on lines +1006 to +1036
async pokeUser (_contact: Contact, _targetId: string, _count: number = 1): Promise<boolean> {
if (!['group', 'friend'].includes(_contact.scene)) {
throw new Error('不支持的场景')
}
const peerId = Number(_contact.peer)
const targetId = Number(_targetId)
const scene = _contact.scene as 'group' | 'friend'

const handlers = {
'Lagrange.OneBot': {
group: () => this._onebot.lgl_groupPoke(peerId, targetId),
friend: () => this._onebot.lgl_friendPoke(targetId),
},
'NapCat.Onebot': {
group: () => this._onebot.nc_groupPoke(peerId, targetId),
friend: () => this._onebot.nc_friendPoke(targetId),
},
} as const

const adapterHandlers = handlers[this.adapter.name as keyof typeof handlers]
if (!adapterHandlers) {
throw new Error(`${this.adapter.name} 不支持戳一戳功能`)
}

const pokeOnce = adapterHandlers[scene]

for (let i = 0; i < _count; i++) {
await pokeOnce()
}

return true
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

Validate _count to ensure at least one poke is performed.

If _count is 0 or negative, the loop won't execute but the method returns true, which is misleading as no action was taken. Consider validating the parameter.

🔧 Suggested fix
  async pokeUser (_contact: Contact, _targetId: string, _count: number = 1): Promise<boolean> {
+   if (_count < 1) {
+     throw new Error('戳一戳次数必须大于0')
+   }
    if (!['group', 'friend'].includes(_contact.scene)) {
      throw new Error('不支持的场景')
    }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
async pokeUser (_contact: Contact, _targetId: string, _count: number = 1): Promise<boolean> {
if (!['group', 'friend'].includes(_contact.scene)) {
throw new Error('不支持的场景')
}
const peerId = Number(_contact.peer)
const targetId = Number(_targetId)
const scene = _contact.scene as 'group' | 'friend'
const handlers = {
'Lagrange.OneBot': {
group: () => this._onebot.lgl_groupPoke(peerId, targetId),
friend: () => this._onebot.lgl_friendPoke(targetId),
},
'NapCat.Onebot': {
group: () => this._onebot.nc_groupPoke(peerId, targetId),
friend: () => this._onebot.nc_friendPoke(targetId),
},
} as const
const adapterHandlers = handlers[this.adapter.name as keyof typeof handlers]
if (!adapterHandlers) {
throw new Error(`${this.adapter.name} 不支持戳一戳功能`)
}
const pokeOnce = adapterHandlers[scene]
for (let i = 0; i < _count; i++) {
await pokeOnce()
}
return true
async pokeUser (_contact: Contact, _targetId: string, _count: number = 1): Promise<boolean> {
if (_count < 1) {
throw new Error('戳一戳次数必须大于0')
}
if (!['group', 'friend'].includes(_contact.scene)) {
throw new Error('不支持的场景')
}
const peerId = Number(_contact.peer)
const targetId = Number(_targetId)
const scene = _contact.scene as 'group' | 'friend'
const handlers = {
'Lagrange.OneBot': {
group: () => this._onebot.lgl_groupPoke(peerId, targetId),
friend: () => this._onebot.lgl_friendPoke(targetId),
},
'NapCat.Onebot': {
group: () => this._onebot.nc_groupPoke(peerId, targetId),
friend: () => this._onebot.nc_friendPoke(targetId),
},
} as const
const adapterHandlers = handlers[this.adapter.name as keyof typeof handlers]
if (!adapterHandlers) {
throw new Error(`${this.adapter.name} 不支持戳一戳功能`)
}
const pokeOnce = adapterHandlers[scene]
for (let i = 0; i < _count; i++) {
await pokeOnce()
}
return true
}
🤖 Prompt for AI Agents
In @packages/core/src/adapter/onebot/core/core.ts around lines 1006 - 1036, In
pokeUser, _count can be 0 or negative so the loop may never run while the
function still returns true; validate _count at the start of the function
(pokeUser) by either throwing a descriptive error when _count < 1 or normalizing
it (e.g., set _count = Math.max(1, _count)) before the for-loop, and update the
error message/behavior accordingly so callers know no poke was performed if an
invalid count was 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