Skip to content

feat(onebot): add rename_group_file action#719

Merged
linyuchen merged 1 commit intoLLOneBot:devfrom
clansty:feat/rename-group-file
Mar 6, 2026
Merged

feat(onebot): add rename_group_file action#719
linyuchen merged 1 commit intoLLOneBot:devfrom
clansty:feat/rename-group-file

Conversation

@clansty
Copy link
Contributor

@clansty clansty commented Mar 5, 2026

增加 rename_group_file API,对齐 napcat 的行为

LLBot 目前没有修改群文件名称的 API,但是 napcat 有这个 API (是我加的)

Summary

  • Add rename_group_file OneBot11 action for renaming files in QQ group file system
  • The underlying ntGroupApi.renameGroupFile API already exists; this PR exposes it as an OneBot action

Details

Action name: rename_group_file

Parameters (compatible with NapCat):

Parameter Type Description
group_id number | string Group ID
file_id string File ID to rename
current_parent_directory string Current parent folder ID (e.g., /)
new_name string New file name

Changes:

  • New file: src/onebot11/action/llbot/file/RenameGroupFile.ts
  • Register action name RenameGroupFile = 'rename_group_file' in ActionName enum
  • Register handler in initActionMap

Implementation follows the same pattern as the existing RenameGroupFileFolder and MoveGroupFile actions.

Summary by Sourcery

新功能:

  • 添加 rename_group_file OneBot11 动作用于在群文件系统中重命名文件。
Original summary in English

Summary by Sourcery

New Features:

  • Add a rename_group_file OneBot11 action for renaming files within a group’s file system.

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Mar 5, 2026

Reviewer's Guide

新增一个 OneBot11 动作 rename_group_file,对现有的 QQ 群文件 API ntGroupApi.renameGroupFile 进行封装,包括基于 schema 的载荷校验、错误传播,以及在动作映射和枚举中与现有文件相关动作一起完成注册。

处理 rename_group_file 动作的时序图

sequenceDiagram
  actor Client
  participant OneBotAdapter
  participant RenameGroupFile
  participant NtGroupApi

  Client->>OneBotAdapter: send action rename_group_file with payload
  OneBotAdapter->>RenameGroupFile: dispatch with payload
  RenameGroupFile->>RenameGroupFile: validate payloadSchema
  RenameGroupFile->>NtGroupApi: renameGroupFile(groupId, fileId, currentParentDirectory, newName)
  NtGroupApi-->>RenameGroupFile: RenameGroupFileResponse
  alt retCode != 0
    RenameGroupFile->>RenameGroupFile: throw Error(clientWording)
    RenameGroupFile-->>OneBotAdapter: error
    OneBotAdapter-->>Client: error response
  else retCode == 0
    RenameGroupFile-->>OneBotAdapter: null
    OneBotAdapter-->>Client: ok response
  end
Loading

新的 rename_group_file OneBot11 动作的类图

classDiagram
  class BaseAction {
    <<abstract>>
    ctx
    +payloadSchema
    +actionName
    +_handle(payload)
  }

  class RenameGroupFile {
    +actionName
    +payloadSchema
    +_handle(payload Payload) Promise~null~
  }

  class Payload {
    +group_id number|string
    +file_id string
    +current_parent_directory string
    +new_name string
  }

  class NtGroupApi {
    +renameGroupFile(groupId string, fileId string, currentParentDirectory string, newName string) Promise~RenameGroupFileResponse~
  }

  class RenameGroupFileResponse {
    +renameGroupFileResult ResultWrapper
  }

  class ResultWrapper {
    +result Result
  }

  class Result {
    +retCode number
    +clientWording string
  }

  BaseAction <|-- RenameGroupFile
  RenameGroupFile --> Payload
  RenameGroupFile --> NtGroupApi : uses
  NtGroupApi --> RenameGroupFileResponse
  RenameGroupFileResponse --> ResultWrapper
  ResultWrapper --> Result
Loading

File-Level Changes

Change Details Files
引入 RenameGroupFile OneBot11 动作,对 ntGroupApi.renameGroupFile 进行封装,并带有经过校验的载荷与错误处理。
  • 定义包含 group_id、file_id、current_parent_directory 和 new_name 字段的 Payload 接口。
  • 创建继承自 BaseAction 的 RenameGroupFile 类,使用 ActionName.RenameGroupFile,并基于 Schema 定义 payloadSchema,强制要求必要参数以及与 NapCat 兼容的类型。
  • 实现 _handle,将 group_id 规范化为字符串,使用给定参数调用 ctx.ntGroupApi.renameGroupFile,当 retCode 非 0 时抛出带有 clientWording 的 Error,成功时返回 null。
src/onebot11/action/llbot/file/RenameGroupFile.ts
将新的 RenameGroupFile 动作接入 OneBot11 动作系统。
  • 在 ActionName 枚举中新增 RenameGroupFile = 'rename_group_file' 以便统一引用。
  • 在 initActionMap 中注册新的 RenameGroupFile(adapter),并与现有的 MoveGroupFile、RenameGroupFileFolder 等文件相关动作一起使用。
src/onebot11/action/types.ts
src/onebot11/action/index.ts

Tips and commands

Interacting with 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 来触发新的审查!

Customizing Your Experience

访问你的 dashboard 以:

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

Getting Help

Original review guide in English

Reviewer's Guide

Adds a new OneBot11 action rename_group_file that exposes the existing ntGroupApi.renameGroupFile QQ group file API, including schema-validated payload handling, error propagation, and registration in the action map and enum alongside existing file actions.

Sequence diagram for handling the rename_group_file action

sequenceDiagram
  actor Client
  participant OneBotAdapter
  participant RenameGroupFile
  participant NtGroupApi

  Client->>OneBotAdapter: send action rename_group_file with payload
  OneBotAdapter->>RenameGroupFile: dispatch with payload
  RenameGroupFile->>RenameGroupFile: validate payloadSchema
  RenameGroupFile->>NtGroupApi: renameGroupFile(groupId, fileId, currentParentDirectory, newName)
  NtGroupApi-->>RenameGroupFile: RenameGroupFileResponse
  alt retCode != 0
    RenameGroupFile->>RenameGroupFile: throw Error(clientWording)
    RenameGroupFile-->>OneBotAdapter: error
    OneBotAdapter-->>Client: error response
  else retCode == 0
    RenameGroupFile-->>OneBotAdapter: null
    OneBotAdapter-->>Client: ok response
  end
Loading

Class diagram for the new rename_group_file OneBot11 action

classDiagram
  class BaseAction {
    <<abstract>>
    ctx
    +payloadSchema
    +actionName
    +_handle(payload)
  }

  class RenameGroupFile {
    +actionName
    +payloadSchema
    +_handle(payload Payload) Promise~null~
  }

  class Payload {
    +group_id number|string
    +file_id string
    +current_parent_directory string
    +new_name string
  }

  class NtGroupApi {
    +renameGroupFile(groupId string, fileId string, currentParentDirectory string, newName string) Promise~RenameGroupFileResponse~
  }

  class RenameGroupFileResponse {
    +renameGroupFileResult ResultWrapper
  }

  class ResultWrapper {
    +result Result
  }

  class Result {
    +retCode number
    +clientWording string
  }

  BaseAction <|-- RenameGroupFile
  RenameGroupFile --> Payload
  RenameGroupFile --> NtGroupApi : uses
  NtGroupApi --> RenameGroupFileResponse
  RenameGroupFileResponse --> ResultWrapper
  ResultWrapper --> Result
Loading

File-Level Changes

Change Details Files
Introduce RenameGroupFile OneBot11 action that wraps ntGroupApi.renameGroupFile with validated payload and error handling.
  • Define a Payload interface with group_id, file_id, current_parent_directory, and new_name fields.
  • Create RenameGroupFile class extending BaseAction with ActionName.RenameGroupFile and a Schema-based payloadSchema enforcing required parameters and types compatible with NapCat.
  • Implement _handle to normalize group_id to string, call ctx.ntGroupApi.renameGroupFile with the provided parameters, and throw an Error with clientWording when retCode is non-zero, returning null on success.
src/onebot11/action/llbot/file/RenameGroupFile.ts
Wire the new RenameGroupFile action into the OneBot11 action system.
  • Add RenameGroupFile = 'rename_group_file' to the ActionName enum so it can be referenced consistently.
  • Register new RenameGroupFile(adapter) in initActionMap alongside existing file actions such as MoveGroupFile and RenameGroupFileFolder.
src/onebot11/action/types.ts
src/onebot11/action/index.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 - 我在这里给出了一些高层次的反馈:

  • _handle 中,建议在访问 retCodeclientWording 之前,对 res.renameGroupFileResult?.result 做好防护(例如使用可选链或显式检查),这样当 API 返回的结构异常时,可以以更清晰的错误失败,而不是在访问嵌套属性时直接抛出异常。
面向 AI Agent 的提示
Please address the comments from this code review:

## Overall Comments
- In `_handle`, consider guarding `res.renameGroupFileResult?.result` (e.g., with optional chaining or explicit checks) before accessing `retCode` and `clientWording` so that unexpected API responses fail with a clearer error instead of throwing on a nested property access.

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

Hey - I've left some high level feedback:

  • In _handle, consider guarding res.renameGroupFileResult?.result (e.g., with optional chaining or explicit checks) before accessing retCode and clientWording so that unexpected API responses fail with a clearer error instead of throwing on a nested property access.
Prompt for AI Agents
Please address the comments from this code review:

## Overall Comments
- In `_handle`, consider guarding `res.renameGroupFileResult?.result` (e.g., with optional chaining or explicit checks) before accessing `retCode` and `clientWording` so that unexpected API responses fail with a clearer error instead of throwing on a nested property access.

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.

@linyuchen linyuchen changed the base branch from main to dev March 6, 2026 03:01
@linyuchen linyuchen merged commit b18e13e into LLOneBot:dev Mar 6, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants