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

✨ 提供一个插件好感度限制 #1846

Merged
merged 2 commits into from
Feb 10, 2025
Merged

✨ 提供一个插件好感度限制 #1846

merged 2 commits into from
Feb 10, 2025

Conversation

HibiKier
Copy link
Owner

No description provided.

Copy link
Contributor

sourcery-ai bot commented Feb 10, 2025

## Sourcery 评审者指南

此 Pull Request 引入了一个新功能,用于强制执行插件的最低“好感度”(impression)限制。 该实现涉及修改身份验证过程以检查用户的好感度,更新插件模型和设置以包含新字段,以及增强实用程序以支持数据库模式更改。

#### 插件和 SignUser 模型的类图(带有好感度字段)

```mermaid
classDiagram
    class PluginInfo {
        +Boolean is_show
        +Float impression
        +String module
        +Boolean ignore_prompt
        ...
    }

    class SignUser {
        +String user_id
        +Float impression
        +async get_user(user_id, platform: String|None)
        +async sign(...)
        ...
    }

    note for PluginInfo "添加了新字段 'impression' 以强制执行最低好感度限制"
    note for SignUser "添加了 get_user 方法来获取或创建 SignUser 实例"

文件级别更改

变更 详情 文件
更新了身份验证检查以强制执行插件好感度限制
  • 修改了 is_send_limit_message 方法,以便在设置插件的 ignore_prompt 标志时绕过检查。
  • 在 auth_plugin 函数中添加了一个新块,以验证用户的好感度是否满足插件所需的最低好感度阈值。
  • 删除了发送限制消息时的冗余条件(特别是对 'is_poke' 的检查)。
  • 添加了日志记录和响应消息,以在未满足好感度要求时通知用户。
zhenxun/builtin_plugins/hooks/_auth_checker.py
引入了一种检索用户签名信息的方法
  • 在 SignUser 模型中添加了一个新的异步类方法 get_user,用于获取或创建用户的签名记录。
zhenxun/models/sign_user.py
扩展了实用程序函数以支持模式更改
  • 在 common_utils 模块中实现了一个新的类方法 add_column,用于生成 SQL 以更改表和添加列。
zhenxun/utils/common_utils.py
更新了 PluginInfo 模型以包含好感度字段
  • 在 PluginInfo 模型中添加了一个新的 'impression' 字段,并设置了默认值。
  • 包含了一个相应的 SQL 迁移命令,用于在 plugin_info 表中添加好感度列。
zhenxun/models/plugin_info.py
将好感度配置传播到插件初始化
  • 修改了 init_plugin 模块,以便在初始化期间从插件设置传递好感度值。
  • 从更新列表中删除了 ignore_prompt 字段更新,因为在此上下文中不需要它。
zhenxun/builtin_plugins/init/init_plugin.py
更新了插件设置以包含好感度限制
  • 在 PluginSetting 模型中添加了一个带有默认值的好感度属性。
zhenxun/configs/utils/__init__.py

提示和命令

与 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 以触发新的审查!
  • 为 issue 生成行动计划: 在 issue 上评论 @sourcery-ai plan 以为其生成行动计划。

自定义您的体验

访问您的 仪表板 以:

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

获得帮助

```
Original review guide in English

Reviewer's Guide by Sourcery

This pull request introduces a new feature to enforce a minimum '好感度' (impression) limit for plugins. The implementation involves modifications in the authentication process to check a user's impression, updates to the plugin model and settings to include the new field, and utility enhancements to support database schema changes.

Class Diagram for Plugin and SignUser Models (with Impression Field)

classDiagram
    class PluginInfo {
        +Boolean is_show
        +Float impression
        +String module
        +Boolean ignore_prompt
        ...
    }

    class SignUser {
        +String user_id
        +Float impression
        +async get_user(user_id, platform: String|None)
        +async sign(...)
        ...
    }

    note for PluginInfo "New field 'impression' added to enforce minimum impression limit"
    note for SignUser "Added get_user method to fetch or create SignUser instance"
Loading

File-Level Changes

Change Details Files
Updated authentication checks to enforce plugin impression limits
  • Modified the is_send_limit_message method to bypass checks when the plugin's ignore_prompt flag is set.
  • Added a new block in the auth_plugin function to verify if the user's impression meets the plugin's required impression threshold.
  • Removed redundant conditionals (specifically the check for 'is_poke') when sending limit messages.
  • Added logging and a response message to notify the user when the impression requirement is not met.
zhenxun/builtin_plugins/hooks/_auth_checker.py
Introduced a method to retrieve a user's sign information
  • Added a new asynchronous class method get_user in the SignUser model to fetch or create a user's sign record.
zhenxun/models/sign_user.py
Extended utility functions to support schema alterations
  • Implemented a new class method add_column in the common_utils module to generate SQL for altering tables and adding columns.
zhenxun/utils/common_utils.py
Updated the PluginInfo model to include the impression field
  • Added a new 'impression' field with a default value in the PluginInfo model.
  • Included a corresponding SQL migration command to add the impression column in the plugin_info table.
zhenxun/models/plugin_info.py
Propagated the impression configuration to plugin initialization
  • Modified the init_plugin module to pass the impression value from the plugin settings during initialization.
  • Removed the ignore_prompt field update from the update list as it's not needed in this context.
zhenxun/builtin_plugins/init/init_plugin.py
Updated plugin settings to include impression limits
  • Added an impression property with a default value in the PluginSetting model.
zhenxun/configs/utils/__init__.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!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

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

@AkashiCoin AkashiCoin added the enhancement New feature or request label Feb 10, 2025
@HibiKier HibiKier marked this pull request as ready for review February 10, 2025 07:39
@HibiKier HibiKier merged commit 41613c0 into main Feb 10, 2025
3 checks passed
@HibiKier HibiKier deleted the feature/more-limit-d branch February 10, 2025 07:39
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 @HibiKier - I've reviewed your changes - here's some feedback:

Overall Comments:

  • Consider adding a database migration to populate the impression column for existing plugins.
  • The logic for checking plugin.impression is duplicated in auth_plugin; can this be refactored?
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🟢 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 +214 to +216
if plugin.ignore_prompt:
return False
return self._flmt_s.check(sid)
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (code-quality): We've found these issues:

Suggested change
if plugin.ignore_prompt:
return False
return self._flmt_s.check(sid)
return False if plugin.ignore_prompt else self._flmt_s.check(sid)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants