Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

✨ 新增好感度/金币设置和详细帮助 #1831

Merged
merged 2 commits into from
Jan 10, 2025
Merged

Conversation

HibiKier
Copy link
Owner

No description provided.

Copy link
Contributor

sourcery-ai bot commented Jan 10, 2025

Here's the translation to Chinese:

审阅者指南 by Sourcery

此拉取请求实现了详细帮助功能,并添加了好感度和金币设置。

详细帮助生成的序列图

sequenceDiagram
    actor User
    participant Bot
    participant HelpSystem
    participant PluginSystem

    User->>Bot: 发送详细帮助命令
    Bot->>HelpSystem: 请求详细帮助
    HelpSystem->>PluginSystem: 获取插件信息
    PluginSystem-->>HelpSystem: 返回带命令的插件数据
    HelpSystem->>HelpSystem: 生成详细帮助图像
    HelpSystem-->>Bot: 返回帮助图像
    Bot-->>User: 显示详细帮助图像
Loading

更新的插件模型类图

classDiagram
  class Item {
    +str plugin_name
    +list[str] commands
  }

  class PluginInfo {
    +str id
    +str name
    +str module
    +int admin_level
    +bool ignore_prompt
    +bool is_delete
    +str parent
  }

  class Command {
    +str command
    +list[str] params
    +str description
  }

  class PluginExtraData {
    +str author
    +str version
    +list[Command] commands
    +bool ignore_prompt
    +list[Task] tasks
    +str superuser_help
  }

  PluginExtraData -- Command
  Item -- Command
Loading

文件级变更

变更 详情 文件
添加了详细帮助功能,显示每个插件的可用命令。
  • 为函数添加了 is_detail 参数,控制是否显示详细帮助。
  • 添加了详细帮助的快捷命令。
  • 更新了帮助图像生成逻辑以处理详细帮助。
  • 修改帮助命令以接受 -d--detail 选项进行详细帮助。
  • 更新帮助图像路径以包含详细信息。
  • 添加了在 HTML 和 Zhenxun 帮助图像中显示命令详情的逻辑。
  • 添加了在普通帮助图像中显示命令详情的逻辑
zhenxun/builtin_plugins/help/zhenxun_help.py
zhenxun/builtin_plugins/help/__init__.py
zhenxun/builtin_plugins/help/_data_source.py
zhenxun/builtin_plugins/help/_utils.py
zhenxun/builtin_plugins/help/html_help.py
zhenxun/builtin_plugins/help/normal_help.py
zhenxun/builtin_plugins/help/_config.py
为多个插件添加命令元数据。
  • PluginExtraData 添加 commands 字段以存储命令元数据。
  • 使用每个插件的可用命令填充 commands 字段。
  • 更新插件元数据以包含新的 commands 字段。
zhenxun/builtin_plugins/statistics/statistics_handle.py
zhenxun/builtin_plugins/shop/__init__.py
zhenxun/builtin_plugins/chat_history/chat_message_handle.py
zhenxun/builtin_plugins/withdraw.py
zhenxun/builtin_plugins/sign_in/__init__.py
zhenxun/builtin_plugins/nickname.py
zhenxun/builtin_plugins/info/__init__.py
添加好感度和金币设置。
  • 为超级用户命令创建新插件。
  • 添加设置用户金币和好感度的命令。
  • 实现处理新命令和更新用户数据的逻辑。
/dev/null
zhenxun/builtin_plugins/superuser/super_power.py
更新用户头像 URL 检索。
  • 将频道用户默认头像大小更改为 640px。
  • 更新头像 URL 检索逻辑以使用新大小。
  • 更新用户信息显示以使用新的头像 URL 检索逻辑。
zhenxun/utils/platform.py
zhenxun/builtin_plugins/web_ui/api/tabs/dashboard/data_source.py
zhenxun/builtin_plugins/info/my_info.py
在插件设置中添加 ignore_prompt 字段。
  • PluginExtraDataPluginInfo 模型中添加 ignore_prompt 字段。
  • 更新插件初始化逻辑以处理新字段。
  • 添加数据库迁移以在 plugin_info 表中添加新字段。
zhenxun/configs/utils/__init__.py
zhenxun/builtin_plugins/init/init_plugin.py
zhenxun/models/plugin_info.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 pull request implements a detailed help feature and adds settings for favorability and gold.

Sequence diagram for detailed help generation

sequenceDiagram
    actor User
    participant Bot
    participant HelpSystem
    participant PluginSystem

    User->>Bot: Send detailed help command
    Bot->>HelpSystem: Request detailed help
    HelpSystem->>PluginSystem: Get plugin information
    PluginSystem-->>HelpSystem: Return plugin data with commands
    HelpSystem->>HelpSystem: Generate detailed help image
    HelpSystem-->>Bot: Return help image
    Bot-->>User: Show detailed help image
Loading

Class diagram for updated plugin models

classDiagram
  class Item {
    +str plugin_name
    +list[str] commands
  }

  class PluginInfo {
    +str id
    +str name
    +str module
    +int admin_level
    +bool ignore_prompt
    +bool is_delete
    +str parent
  }

  class Command {
    +str command
    +list[str] params
    +str description
  }

  class PluginExtraData {
    +str author
    +str version
    +list[Command] commands
    +bool ignore_prompt
    +list[Task] tasks
    +str superuser_help
  }

  PluginExtraData -- Command
  Item -- Command
Loading

File-Level Changes

Change Details Files
Added a detailed help feature that displays the available commands for each plugin.
  • Added is_detail parameter to functions to control whether to display detailed help.
  • Added a shortcut command for detailed help.
  • Updated help image generation logic to handle detailed help.
  • Modified help command to accept -d or --detail option for detailed help.
  • Updated help image paths to include detail information.
  • Added logic to display command details in HTML and Zhenxun help images.
  • Added logic to display command details in normal help images
zhenxun/builtin_plugins/help/zhenxun_help.py
zhenxun/builtin_plugins/help/__init__.py
zhenxun/builtin_plugins/help/_data_source.py
zhenxun/builtin_plugins/help/_utils.py
zhenxun/builtin_plugins/help/html_help.py
zhenxun/builtin_plugins/help/normal_help.py
zhenxun/builtin_plugins/help/_config.py
Added commands metadata to several plugins.
  • Added commands field to PluginExtraData to store command metadata.
  • Populated the commands field with the available commands for each plugin.
  • Updated plugin metadata to include the new commands field.
zhenxun/builtin_plugins/statistics/statistics_handle.py
zhenxun/builtin_plugins/shop/__init__.py
zhenxun/builtin_plugins/chat_history/chat_message_handle.py
zhenxun/builtin_plugins/withdraw.py
zhenxun/builtin_plugins/sign_in/__init__.py
zhenxun/builtin_plugins/nickname.py
zhenxun/builtin_plugins/info/__init__.py
Added favorability and gold settings.
  • Created a new plugin for superuser commands.
  • Added commands to set user gold and favorability.
  • Implemented logic to handle the new commands and update user data.
/dev/null
zhenxun/builtin_plugins/superuser/super_power.py
Updated user avatar URL retrieval.
  • Changed the default avatar size to 640px for channel users.
  • Updated avatar URL retrieval logic to use the new size.
  • Updated user info display to use the new avatar URL retrieval logic.
zhenxun/utils/platform.py
zhenxun/builtin_plugins/web_ui/api/tabs/dashboard/data_source.py
zhenxun/builtin_plugins/info/my_info.py
Added ignore_prompt field to plugin settings.
  • Added ignore_prompt field to PluginExtraData and PluginInfo models.
  • Updated plugin initialization logic to handle the new field.
  • Added database migration to add the new field to the plugin_info table.
zhenxun/configs/utils/__init__.py
zhenxun/builtin_plugins/init/init_plugin.py
zhenxun/models/plugin_info.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

@AkashiCoin AkashiCoin added the enhancement New feature or request label Jan 10, 2025
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.

@HibiKier - 我已经审查了你的更改,看起来非常棒!

以下是我在审查期间关注的内容
  • 🟡 一般性问题:发现1个问题
  • 🟢 安全性:一切看起来都很好
  • 🟢 测试:一切看起来都很好
  • 🟢 复杂度:一切看起来都很好
  • 🟢 文档:一切看起来都很好

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

Hey @HibiKier - I've reviewed your changes and they look great!

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.

user_id=at_user.target,
defaults={"user_console": user_console, "platform": platform},
)
user.impression = Decimal(impression)
Copy link
Contributor

Choose a reason for hiding this comment

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

建议 (bug_risk): 添加边界检查并处理小数精度

考虑为合理的印象值范围添加验证,并确保在将浮点数转换为 Decimal 时正确处理小数精度,以防止无效状态。

建议的实现:

async def _(session: Uninfo, arparma: Arparma, impression: float, at_user: At):
    # 验证印象值边界
    if not 0 <= impression <= 1000000:
        raise ValueError("印象值必须在 0 到 1,000,000 之间"platform = PlatformUtils.get_platform(session)
    user_console = await UserConsole.get_user(at_user.target, platform)
    user, _ = await SignUser.get_or_create(
        user_id=at_user.target,
        defaults={"user_console": user_console, "platform": platform},
    )

    # 转换为带有 2 位小数精度的 Decimal
    try:
        decimal_impression = Decimal(str(round(impression, 2)))
        user.impression = decimal_impression
        await user.save(update_fields=["impression"])
    except (ValueError, DecimalException) as e:
        raise ValueError(f"无效的印象值:{e}"

你需要:

  1. 如果尚未导入,从 decimal 模块导入 Decimal
  2. 从 decimal 模块导入 DecimalException
  3. 考虑在此函数周围添加错误处理,以根据应用程序的需求捕获和处理 ValueError
Original comment in English

suggestion (bug_risk): Add bounds checking and handle decimal precision

Consider adding validation for reasonable impression value bounds and ensure proper decimal precision handling when converting from float to Decimal to prevent invalid states.

Suggested implementation:

async def _(session: Uninfo, arparma: Arparma, impression: float, at_user: At):
    # Validate impression bounds
    if not 0 <= impression <= 1000000:
        raise ValueError("Impression value must be between 0 and 1,000,000")

    platform = PlatformUtils.get_platform(session)
    user_console = await UserConsole.get_user(at_user.target, platform)
    user, _ = await SignUser.get_or_create(
        user_id=at_user.target,
        defaults={"user_console": user_console, "platform": platform},
    )

    # Convert to Decimal with 2 decimal places precision
    try:
        decimal_impression = Decimal(str(round(impression, 2)))
        user.impression = decimal_impression
        await user.save(update_fields=["impression"])
    except (ValueError, DecimalException) as e:
        raise ValueError(f"Invalid impression value: {e}")

You'll need to:

  1. Import Decimal from decimal module if not already imported
  2. Import DecimalException from decimal module
  3. Consider adding error handling around this function to catch and handle the ValueError appropriately based on your application's needs

@HibiKier HibiKier merged commit 264929e into main Jan 10, 2025
3 checks passed
@HibiKier HibiKier deleted the feature/menu-child-cmd branch January 10, 2025 10:39
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants