-
Notifications
You must be signed in to change notification settings - Fork 18
fix: 修复pokeUser参数错误的问题close #576 #609
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
base: main
Are you sure you want to change the base?
Conversation
📝 WalkthroughWalkthroughAdded a new Changes
Sequence DiagramsequenceDiagram
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>
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Poem
🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
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. Comment |
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
适配器和 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
文件级变更
技巧和命令与 Sourcery 交互
自定义你的体验访问你的 dashboard 以:
获取帮助Original review guide in EnglishReviewer's GuideImplements 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 adaptersequenceDiagram
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
Class diagram for updated pokeUser flow in adapters and OneBot coreclassDiagram
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
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Summary of ChangesHello @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! 此拉取请求解决了 Highlights
🧠 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 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.
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>帮我变得更有用!请在每条评论上点 👍 或 👎,我会根据你的反馈改进后续的 Review。
Original comment in English
Hey - I've found 2 issues, and left some high level feedback:
- In
OneBotFriendApiAction.lgl_friendPokethe enum value is'lgl_friend_poke'but the corresponding API interface usesaction: 'friend_poke'; this mismatch is likely to cause requests to be sent with the wrong action name and should be aligned. - The
pokeUserimplementation performs_countsequential pokes withawaitin 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>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
| if (!['group', 'friend'].includes(_contact.scene)) { | ||
| throw new Error('不支持的场景') | ||
| } | ||
| const peerId = +_contact.peer | ||
| const targetId = +_targetId | ||
|
|
||
| let pokeOnce: () => Promise<null> |
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.
suggestion (bug_risk): 通过一元 + 进行隐式数字类型转换可能会在不显式报错的情况下产生 NaN;建议使用更严格的类型或校验逻辑。
这里依赖 +_contact.peer 和 +_targetId 始终为数字字符串;任何非数字或空字符串都会变成 NaN 并传给 OneBot,导致难以排查的问题。可以考虑在调用方就将这些值声明为 number 并移除这里的强制转换,或者在转换后进行校验(例如检查是否为有限数字),如果无效则抛出明确的错误。
| 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.
| 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> |
| async lgl_friendPoke ( | ||
| user_id?: number, | ||
| target_id?: number |
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.
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.
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.
Code Review
你好,感谢你对项目的贡献。这次的 Pull Request 修复了 pokeUser 的参数问题,并为 Lagrange 和 NapCat 适配器实现了「戳一戳」功能,整体实现思路清晰,代码结构合理。我主要针对代码的可维护性和文档清晰度提出了一些建议,希望能帮助你进一步完善代码。请查看具体的审查评论。
| 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} 不支持戳一戳功能`) | ||
| } |
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.
为了提高代码的可读性和可扩展性,建议重构此处的 if/else if 逻辑。您可以使用一个映射表(map)来根据适配器名称和场景动态选择对应的 poke 函数。这样可以避免未来增加新适配器时需要不断追加 else if 分支,使代码更易于维护。
| 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] | |
| /** | ||
| * 合并转发 karin -> adapter | ||
| * @param elements 消息元素 | ||
| * @param options 首层小卡片外显参数 | ||
| * @returns 适配器消息元素 | ||
| */ | ||
| * 合并转发 karin -> adapter | ||
| * @param elements 消息元素 | ||
| * @param options 首层小卡片外显参数 | ||
| * @returns 适配器消息元素 | ||
| */ |
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.
这个 JSDoc 注释块的缩进似乎不正确,导致其内容没有与 /** 对齐。为了保持代码风格统一,建议修正此处的缩进。
| /** | |
| * 合并转发 karin -> adapter | |
| * @param elements 消息元素 | |
| * @param options 首层小卡片外显参数 | |
| * @returns 适配器消息元素 | |
| */ | |
| * 合并转发 karin -> adapter | |
| * @param elements 消息元素 | |
| * @param options 首层小卡片外显参数 | |
| * @returns 适配器消息元素 | |
| */ | |
| /** | |
| * 合并转发 karin -> adapter | |
| * @param elements 消息元素 | |
| * @param options 首层小卡片外显参数 | |
| * @returns 适配器消息元素 | |
| */ |
| async lgl_friendPoke ( | ||
| user_id?: number, | ||
| target_id?: number | ||
| ) { |
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.
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.
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
pokeUserJSDoc 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
📒 Files selected for processing (6)
packages/core/src/adapter/base/index.tspackages/core/src/adapter/onebot/core/core.tspackages/core/src/types/adapter/class.tspackages/onebot/src/api/friend.tspackages/onebot/src/api/group.tspackages/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_groupPokemethod implementation correctly mirrors the existingnc_groupPokepattern and properly invokes the API action with the expected parameters.packages/onebot/src/api/group.ts (1)
14-14: LGTM!The new
lgl_groupPokeenum member and interface entry correctly mirror the existingnc_groupPokepattern. 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_setGroupLeaveandsetGroupLeave).Also applies to: 533-541
packages/onebot/src/api/friend.ts (1)
23-23: LGTM!The new
lgl_friendPokeenum member and interface entry correctly mirror the existingnc_friendPokepattern, 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
pokeUsersignature with the new_targetIdparameter, maintaining consistency with theAdapterTypeinterface definition.packages/core/src/types/adapter/class.ts (1)
442-447: Breaking API change - all implementations verified and updated.The
pokeUsermethod signature now includes a requiredtargetIdparameter (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 AdapterBaseThe breaking change is appropriately scoped and complete.
| /** | ||
| * 戳一戳用户 | ||
| * @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 | ||
| } |
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.
🧩 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 -20Repository: 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.
|
你可以通过以下命令安装该版本: |
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.
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
📒 Files selected for processing (2)
packages/core/src/adapter/onebot/core/core.tspackages/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.
| 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 |
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.
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.
| 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.
Summary by Sourcery
为 OneBot 修复并实现跨适配器的「戳一戳用户」功能,通过核心适配器和 OneBot API 将其接入 Lagrange 和 NapCat。
Bug 修复:
pokeUser适配器方法的函数签名以包含目标用户 ID,解决参数使用错误的问题。增强内容:
pokeUser逻辑,为 Lagrange 和 NapCat 提供群聊和好友两种场景的支持。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:
Enhancements:
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.