HibiKier / zhenxun_bot

基于 Nonebot2 开发,非常可爱的绪山真寻bot
GNU Affero General Public License v3.0
3.36k stars 605 forks source link

✨ 重构帮助,限制普通用户查询管理插件 #1626

Closed HibiKier closed 1 month ago

HibiKier commented 1 month ago

Summary by Sourcery

重构帮助插件以限制普通用户查询管理插件,并将图像构建过程模块化。引入函数以分类插件并确定其状态,并添加方法以检索用户头像URL。

增强功能:

Original summary in English ## Summary by Sourcery Refactor the help plugin to restrict normal users from querying management plugins and modularize the image building process. Introduce functions to classify plugins and determine their status, and add a method to retrieve user avatar URLs. Enhancements: - Refactor the help plugin to modularize the image building process into separate files for HTML, normal, and Zhenxun help images. - Introduce a new function to classify plugins and determine their status based on group and user permissions. - Add a new method to retrieve user avatar URLs based on the platform.
sourcery-ai[bot] commented 1 month ago

审核指南由 Sourcery 提供

此拉取请求重构了 Zhenxun 机器人的帮助功能,重点在于改进代码组织、降低复杂性,并添加用户权限检查。更改包括将帮助生成拆分为不同类型的帮助(HTML、Zhenxun 和普通)的独立模块,引入一个新函数来检查用户权限,并更新主帮助命令以使用这些新模块。

文件级更改

更改 详情 文件
将帮助图像生成重构为独立模块
  • 为不同的帮助类型创建了新文件:html_help.py、normal_help.py 和 zhenxun_help.py
  • 将生成不同类型帮助图像的逻辑移至各自的模块中
  • 更新主帮助命令以使用新模块进行图像生成
zhenxun/builtin_plugins/help/_utils.py
zhenxun/builtin_plugins/help/_data_source.py
zhenxun/builtin_plugins/help/html_help.py
zhenxun/builtin_plugins/help/normal_help.py
zhenxun/builtin_plugins/help/zhenxun_help.py
为帮助命令实现用户权限检查
  • 添加了 get_user_allow_help 函数以确定用户可以访问哪些插件类型
  • 更新 get_plugin_help 函数以在检索插件信息时使用用户权限
zhenxun/builtin_plugins/help/_data_source.py
简化并重组与帮助相关的配置
  • 将配置相关代码移至 _config.py
  • 删除冗余代码并简化配置处理
zhenxun/builtin_plugins/help/_config.py
zhenxun/builtin_plugins/help/__init__.py
更新平台实用工具以包含头像 URL 检索
  • 向 PlatformUtils 类添加了 get_user_avatar_url 方法
zhenxun/utils/platform.py

提示 - 通过在拉取请求中评论 `@sourcery-ai review` 来触发新的 Sourcery 审核。 - 通过直接回复审核评论继续与 Sourcery 的讨论。 - 您可以随时通过访问您的[仪表板](https://app.sourcery.ai)更改审核设置: - 启用或禁用 Sourcery 生成的拉取请求摘要或审核指南; - 更改审核语言; - 如果您有任何问题或反馈,您可以随时[联系我们](mailto:support@sourcery.ai)。
Original review guide in English ## Reviewer's Guide by Sourcery This pull request refactors the help functionality in the Zhenxun bot, focusing on improving code organization, reducing complexity, and adding user permission checks. The changes include splitting the help generation into separate modules for different types of help (HTML, Zhenxun, and normal), introducing a new function to check user permissions, and updating the main help command to use these new modules. ### File-Level Changes | Change | Details | Files | | ------ | ------- | ----- | | Refactored help image generation into separate modules |
  • Created new files for different help types: html_help.py, normal_help.py, and zhenxun_help.py
  • Moved logic for generating different types of help images into their respective modules
  • Updated main help command to use new modules for image generation
| `zhenxun/builtin_plugins/help/_utils.py`
`zhenxun/builtin_plugins/help/_data_source.py`
`zhenxun/builtin_plugins/help/html_help.py`
`zhenxun/builtin_plugins/help/normal_help.py`
`zhenxun/builtin_plugins/help/zhenxun_help.py` | | Implemented user permission checks for help command |
  • Added get_user_allow_help function to determine which plugin types a user can access
  • Updated get_plugin_help function to use user permissions when retrieving plugin information
| `zhenxun/builtin_plugins/help/_data_source.py` | | Simplified and reorganized help-related configurations |
  • Moved configuration-related code to _config.py
  • Removed redundant code and simplified configuration handling
| `zhenxun/builtin_plugins/help/_config.py`
`zhenxun/builtin_plugins/help/__init__.py` | | Updated platform utility to include avatar URL retrieval |
  • Added get_user_avatar_url method to PlatformUtils class
| `zhenxun/utils/platform.py` | ---
Tips - Trigger a new Sourcery review by commenting `@sourcery-ai review` on the pull request. - Continue your discussion with Sourcery by replying directly to review comments. - You can change your review settings at any time by accessing your [dashboard](https://app.sourcery.ai): - Enable or disable the Sourcery-generated pull request summary or reviewer's guide; - Change the review language; - You can always [contact us](mailto:support@sourcery.ai) if you have any questions or feedback.