Skip to content

Feature: 支持自定义快捷指令#13

Merged
FrostN0v0 merged 2 commits into
masterfrom
feat/custom-shortcut
Jun 4, 2025
Merged

Feature: 支持自定义快捷指令#13
FrostN0v0 merged 2 commits into
masterfrom
feat/custom-shortcut

Conversation

@FrostN0v0
Copy link
Copy Markdown
Owner

@FrostN0v0 FrostN0v0 commented Apr 30, 2025

好的,这是翻译成中文的 pull request 总结:

Sourcery 总结

为 NoneBot 的 Skland 插件添加自定义快捷方式支持

新特性:

  • 实现 Skland 命令的自定义快捷方式管理
  • 增加添加、删除和列出自定义快捷方式的功能

增强功能:

  • 改进命令命名空间和快捷方式处理
  • 为自定义快捷方式添加持久化存储

文档:

  • 使用自定义快捷方式功能的文档更新 README
Original summary in English

Summary by Sourcery

Add support for custom shortcuts in the Skland plugin for NoneBot

New Features:

  • Implement custom shortcut management for Skland commands
  • Add ability to add, delete, and list custom shortcuts

Enhancements:

  • Improve command namespace and shortcut handling
  • Add persistent storage for custom shortcuts

Documentation:

  • Update README with documentation for custom shortcut feature

@sourcery-ai
Copy link
Copy Markdown

sourcery-ai Bot commented Apr 30, 2025

## 审查者指南

此 pull request 引入了对用户自定义命令快捷方式的支持,利用了 Alconna 的命名空间和命令管理器功能。快捷方式现在会在关闭时持久化到缓存文件,并在启动时加载。

### 文件级别变更

| 变更 | 详情 | 文件 |
| ------ | ------- | ----- |
| 集成 Alconna 命名空间和命令管理器以处理快捷方式。 | <ul><li>定义并将 'skland' 命名空间应用于主命令。</li><li>添加启动钩子以从缓存加载快捷方式。</li><li>添加关闭钩子以将快捷方式保存到缓存。</li></ul> | `nonebot_plugin_skland/__init__.py`<br/>`nonebot_plugin_skland/hook.py` |
| 更新自定义快捷方式的文档。 | <ul><li>添加了一个新章节,解释如何使用 '/skland --shortcut' 命令添加、删除和列出自定义快捷方式。</li><li>提供了快捷方式管理命令的使用示例。</li></ul> | `README.md` |
| 应用代码格式化。 | <ul><li>调整了多个文件中函数定义、参数和调用中的代码格式(换行、缩进)。</li></ul> | `nonebot_plugin_skland/__init__.py`<br/>`nonebot_plugin_skland/download.py`<br/>`nonebot_plugin_skland/hook.py` |

---

<details>
<summary>提示和命令</summary>

#### 与 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` 以触发新的审查!

#### 自定义您的体验

访问您的 [仪表板](https://app.sourcery.ai) 以:
- 启用或禁用审查功能,例如 Sourcery 生成的 pull request 摘要、审查者指南等。
- 更改审查语言。
- 添加、删除或编辑自定义审查说明。
- 调整其他审查设置。

#### 获取帮助

- [联系我们的支持团队](mailto:support@sourcery.ai) 提出问题或反馈。
- 访问我们的 [文档](https://docs.sourcery.ai) 获取详细的指南和信息。
- 通过在 [X/Twitter](https://x.com/SourceryAI), [LinkedIn](https://www.linkedin.com/company/sourcery-ai/) 或 [GitHub](https://github.com/sourcery-ai) 上关注我们,与 Sourcery 团队保持联系。

</details>
Original review guide in English

Reviewer's Guide

This pull request introduces support for user-defined command shortcuts by leveraging Alconna's namespace and command manager features. Shortcuts are now persisted to a cache file on shutdown and loaded on startup.

File-Level Changes

Change Details Files
Integrate Alconna namespace and command manager for shortcut handling.
  • Defined and applied a 'skland' namespace to the main command.
  • Added startup hook to load shortcuts from cache.
  • Added shutdown hook to save shortcuts to cache.
nonebot_plugin_skland/__init__.py
nonebot_plugin_skland/hook.py
Update documentation for custom shortcuts.
  • Added a new section explaining how to add, delete, and list custom shortcuts using the '/skland --shortcut' command.
  • Provided usage examples for the shortcut management commands.
README.md
Apply code formatting.
  • Adjusted code formatting (line breaks, indentation) in function definitions, arguments, and calls across multiple files.
nonebot_plugin_skland/__init__.py
nonebot_plugin_skland/download.py
nonebot_plugin_skland/hook.py

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
Copy Markdown

@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 @FrostN0v0 - 我已经查看了你的更改 - 这里有一些反馈:

  • 考虑运行代码格式化程序以确保一致的样式,尤其是在函数调用和定义中的换行符方面。
以下是我在审查期间查看的内容
  • 🟡 General issues: 发现 2 个问题
  • 🟢 Security: 一切看起来都很好
  • 🟢 Testing: 一切看起来都很好
  • 🟢 Complexity: 一切看起来都很好
  • 🟢 Documentation: 一切看起来都很好

Sourcery 对于开源是免费的 - 如果你喜欢我们的评论,请考虑分享它们 ✨
帮助我更有用!请点击每个评论上的 👍 或 👎,我将使用反馈来改进你的评论。
Original comment in English

Hey @FrostN0v0 - I've reviewed your changes - here's some feedback:

  • Consider running a code formatter to ensure consistent styling, particularly regarding line breaks in function calls and definitions.
Here's what I looked at during the review
  • 🟡 General issues: 2 issues found
  • 🟢 Security: all looks good
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

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 +14 to +15
command_manager.load_cache(shortcut_cache)
logger.debug("Skland shortcuts cache loaded")
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion (bug_risk): Cache operations on startup are clear.

将启动时的缓存加载和转储操作包装在 try/except 块中,以捕获启动或关闭期间的 IO 错误。

Suggested implementation:

@driver.on_startup
async def startup():
    try:
        command_manager.load_cache(shortcut_cache)
        logger.debug("Skland shortcuts cache loaded")
    except Exception as e:
        logger.error("Failed to load shortcut cache on startup", exc_info=e)

    if config.check_res_update:
        try:
            if version := await GameResourceDownloader.check_update():
                for route in RESOURCE_ROUTES:
                    logger.info(f"正在下载: {route}")
                    await GameResourceDownloader.download_all(
                        owner="yuanyan3060",
                        repo="ArknightsGameResource",
                        route=route,
                        branch="main",
                    )
        except Exception as e:
            logger.error("Error during resource update", exc_info=e)

If there is a cache dump operation in your shutdown function (for example, within a @driver.on_shutdown decorated function), Wrap that operation in a similar try/except block to catch and log any IO errors during shutdown.

Original comment in English

suggestion (bug_risk): Cache operations on startup are clear.

Wrap cache load and dump in a try/except to catch IO errors during startup or shutdown.

Suggested implementation:

@driver.on_startup
async def startup():
    try:
        command_manager.load_cache(shortcut_cache)
        logger.debug("Skland shortcuts cache loaded")
    except Exception as e:
        logger.error("Failed to load shortcut cache on startup", exc_info=e)

    if config.check_res_update:
        try:
            if version := await GameResourceDownloader.check_update():
                for route in RESOURCE_ROUTES:
                    logger.info(f"正在下载: {route}")
                    await GameResourceDownloader.download_all(
                        owner="yuanyan3060",
                        repo="ArknightsGameResource",
                        route=route,
                        branch="main",
                    )
        except Exception as e:
            logger.error("Error during resource update", exc_info=e)

If there is a cache dump operation in your shutdown function (for example, within a @driver.on_shutdown decorated function), Wrap that operation in a similar try/except block to catch and log any IO errors during shutdown.

Comment thread README.md

#### 🪄 自定义快捷指令

> 该特性依赖于 [Alconna 快捷指令](https://nonebot.dev/docs/best-practice/alconna/command#command%E7%9A%84%E4%BD%BF%E7%94%A8)。自定义指令不带 `COMMAND_START`,若有必要需手动填写
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

suggestion: 澄清关于自定义命令的 COMMAND_START 的说明。

“自定义指令不带 COMMAND_START” 一句不太清晰,因为示例别名 /兔兔签到 已包含 /。请说明“自定义指令”指的是快捷别名还是目标命令字符串,并举例说明何时需手动添加 COMMAND_START

Original comment in English

suggestion: Clarify the note about COMMAND_START for custom commands.

“自定义指令不带 COMMAND_START” 一句不太清晰,因为示例别名 /兔兔签到 已包含 /。请说明“自定义指令”指的是快捷别名还是目标命令字符串,并举例说明何时需手动添加 COMMAND_START

@FrostN0v0
Copy link
Copy Markdown
Owner Author

ArcletProject/Alconna#97 发版才支持指令缓存。

@FrostN0v0 FrostN0v0 merged commit 4206a19 into master Jun 4, 2025
3 checks passed
@FrostN0v0 FrostN0v0 deleted the feat/custom-shortcut branch June 4, 2025 00:13
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.

1 participant