Skip to content
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

✨ 添加小真寻的口癖配置 #1738

Merged
merged 1 commit into from
Nov 23, 2024
Merged

✨ 添加小真寻的口癖配置 #1738

merged 1 commit into from
Nov 23, 2024

Conversation

HibiKier
Copy link
Owner

@HibiKier HibiKier commented Nov 23, 2024

Summary by Sourcery

新功能:

  • 为 Zhenxun 机器人引入一个新的插件配置,用于在消息末尾添加口号。
Original summary in English

Summary by Sourcery

New Features:

  • Introduce a new plugin configuration for adding a catchphrase to the end of messages in the Zhenxun bot.

Copy link

sourcery-ai bot commented Nov 23, 2024

审核者指南 by Sourcery

此 PR 添加了一个新功能,用于配置并附加口号到 Zhenxun 机器人的文本消息中。该实现使用 Nonebot 的 API 调用钩子来拦截传出的消息,并将配置的口号附加到最后一个文本段。

附加口号到消息的序列图

sequenceDiagram
    actor User
    participant Bot
    participant Config
    participant Logger

    User->>Bot: 发送消息
    Bot->>Config: 获取 CATCHPHRASE 配置
    Config-->>Bot: 返回口号
    Bot->>Bot: 检查消息是否包含文本
    alt 消息包含文本
        Bot->>Bot: 将口号附加到最后一个文本段
        Bot->>Logger: 记录附加的口号
    end
    Bot-->>User: 发送修改后的消息
Loading

新口号功能的类图

classDiagram
    class Config {
        +add_plugin_config(name: str, key: str, default_value: Any, help: str)
        +get_config(name: str, key: str) : Any
    }
    class Bot {
        +on_calling_api(func: Callable)
    }
    class Logger {
        +debug(message: str)
    }

    Config <|-- Bot
    Bot <|-- Logger

    note for Config "处理插件的配置"
    note for Bot "拦截 API 调用以附加口号"
    note for Logger "记录调试信息"
Loading

文件级更改

更改 详情 文件
为机器人的口号功能添加了配置支持
  • 为口号文本添加了插件配置,默认值为空
  • 添加了说明口号功能的帮助文本
zhenxun/builtin_plugins/catchphrase.py
实现了消息拦截和口号附加逻辑
  • 添加了 API 调用钩子以拦截 send_msg 操作
  • 实现了查找并修改消息中最后一个文本段的逻辑
  • 为口号添加了调试日志记录
zhenxun/builtin_plugins/catchphrase.py

提示和命令

与 Sourcery 互动

  • 触发新审核: 在拉取请求上评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审核评论。
  • 从审核评论生成 GitHub 问题: 通过回复审核评论请求 Sourcery 创建一个问题。
  • 生成拉取请求标题: 在拉取请求标题的任何地方写 @sourcery-ai 以随时生成标题。
  • 生成拉取请求摘要: 在拉取请求正文的任何地方写 @sourcery-ai summary 以随时生成 PR 摘要。您也可以使用此命令指定摘要应插入的位置。

自定义您的体验

访问您的仪表板以:

  • 启用或禁用审核功能,如 Sourcery 生成的拉取请求摘要、审核者指南等。
  • 更改审核语言。
  • 添加、删除或编辑自定义审核说明。
  • 调整其他审核设置。

获取帮助

Original review guide in English

Reviewer's Guide by Sourcery

This PR adds a new feature to configure and append a catchphrase to Zhenxun bot's text messages. The implementation uses Nonebot's API calling hook to intercept outgoing messages and append the configured catchphrase to the last text segment.

Sequence diagram for appending catchphrase to messages

sequenceDiagram
    actor User
    participant Bot
    participant Config
    participant Logger

    User->>Bot: Send message
    Bot->>Config: Get CATCHPHRASE config
    Config-->>Bot: Return catchphrase
    Bot->>Bot: Check if message contains text
    alt Message contains text
        Bot->>Bot: Append catchphrase to last text segment
        Bot->>Logger: Log the appended catchphrase
    end
    Bot-->>User: Send modified message
Loading

Class diagram for the new catchphrase feature

classDiagram
    class Config {
        +add_plugin_config(name: str, key: str, default_value: Any, help: str)
        +get_config(name: str, key: str) : Any
    }
    class Bot {
        +on_calling_api(func: Callable)
    }
    class Logger {
        +debug(message: str)
    }

    Config <|-- Bot
    Bot <|-- Logger

    note for Config "Handles configuration for plugins"
    note for Bot "Intercepts API calls to append catchphrase"
    note for Logger "Logs debug information"
Loading

File-Level Changes

Change Details Files
Added configuration support for bot's catchphrase feature
  • Added plugin configuration for catchphrase text with empty default value
  • Added help text explaining the catchphrase functionality
zhenxun/builtin_plugins/catchphrase.py
Implemented message interception and catchphrase appending logic
  • Added API calling hook to intercept send_msg operations
  • Implemented logic to find and modify the last text segment in messages
  • Added debug logging for catchphrase additions
zhenxun/builtin_plugins/catchphrase.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.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a 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. You can also use
    this command to specify where the summary should be inserted.

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

@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.

@HibiKier - 我已经审查了你的更改 - 这里有一些反馈:

总体评论

  • 考虑为口号配置添加验证(例如,最大长度限制),以防止极长消息的潜在问题。
  • 代码应处理消息数组中不存在文本组件的边缘情况,以防止潜在错误。
这是我在审查期间查看的内容
  • 🟡 一般问题:发现1个问题
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟢 复杂性:一切看起来都很好
  • 🟢 文档:一切看起来都很好

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

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

Overall Comments:

  • Consider adding validation for the catchphrase configuration (e.g., maximum length limit) to prevent potential issues with extremely long messages.
  • The code should handle the edge case where no text components exist in the message array to prevent potential errors.
Here's what I looked at during the review
  • 🟡 General issues: 1 issue 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.


Config.add_plugin_config(
"catchphrase",
"CATCHPHRASE",
Copy link

Choose a reason for hiding this comment

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

建议: 考虑为口号配置添加最大长度限制

无限制的口号长度可能会导致消息过大。考虑在设置配置时验证长度。

    "CATCHPHRASE",
    max_length=50,
Original comment in English

suggestion: Consider adding a maximum length limit for the catchphrase configuration

An unbounded catchphrase length could potentially lead to oversized messages. Consider validating the length when setting the config.

    "CATCHPHRASE",
    max_length=50,

@HibiKier HibiKier merged commit 3b1a399 into main Nov 23, 2024
1 of 2 checks passed
@HibiKier HibiKier deleted the feature/catchphrase branch November 23, 2024 13:37
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