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

版本更新 #1666

Merged
merged 73 commits into from
Sep 30, 2024
Merged

版本更新 #1666

merged 73 commits into from
Sep 30, 2024

Conversation

HibiKier
Copy link
Owner

@HibiKier HibiKier commented Sep 30, 2024

Sourcery的总结

重构帮助系统和QQ群事件处理,引入对多个数据库随机函数的支持,并添加个人信息命令和插件商店API等新功能。修复与插件管理相关的各种错误,并通过缓存增强插件商店。更新CI工作流程和文档,并为自动更新功能添加测试。

新功能:

  • 引入对MySQL、PostgreSQL和SQLite随机函数的支持。
  • 添加新的个人信息命令。
  • 实现用于管理插件的插件商店API。
  • 添加检测群组发言时间的功能,并提供可配置的开关。
  • 引入超级用户和管理员帮助的新模板。
  • 添加优先使用GitHub API进行某些操作的功能。

错误修复:

  • 修复群组权限和插件级别匹配的问题。
  • 解决插件商店未能检查插件更新的错误。
  • 修复签到逻辑中的错误,使代码在配置上更灵活。
  • 解决添加插件时返回403错误的问题。
  • 修复Web UI路径提取和挂载不正确的错误。
  • 解决商店项目列表为空时的错误。

增强:

  • 重构帮助系统以限制普通用户查询管理员插件。
  • 重构QQ群事件处理以提高性能。
  • 通过新的安装和移除方法增强插件管理系统。
  • 通过缓存插件数据60秒来改进插件商店。
  • 重构自检UI以改善用户体验。

构建:

  • 移除名为'爬'的默认图片文件夹。

CI:

  • 更新CI工作流程以优先使用GitHub API。

文档:

  • 更新README,包含新的项目信息和格式改进。

测试:

  • 为自动更新功能添加测试以确保正确功能。

杂务:

  • 移除未使用的导入并清理代码库以提高可维护性。
Original summary in English

Summary by Sourcery

Refactor the help system and QQ group event handling, introduce support for multiple database random functions, and add new features like a personal information command and plugin store API. Fix various bugs related to plugin management and enhance the plugin store with caching. Update the CI workflow and documentation, and add tests for the auto-update feature.

New Features:

  • Introduce support for MySQL, PostgreSQL, and SQLite random functions.
  • Add a new personal information command.
  • Implement a plugin store API for managing plugins.
  • Add a feature to detect group speaking time with a configurable switch.
  • Introduce a new template for superuser and admin help.
  • Add a feature to prioritize using the GitHub API for certain operations.

Bug Fixes:

  • Fix an issue with group permissions and plugin level matching.
  • Resolve a bug where the plugin store failed to check for plugin updates.
  • Fix a bug in the sign-in logic to make the code more flexible for configuration.
  • Address an issue where adding a plugin returned a 403 error.
  • Fix a bug where the web UI path extraction and mounting were incorrect.
  • Resolve an error when the store item list was empty.

Enhancements:

  • Refactor the help system to restrict normal users from querying admin plugins.
  • Refactor the QQ group event handling for improved performance.
  • Enhance the plugin management system with new installation and removal methods.
  • Improve the plugin store by caching plugin data for 60 seconds.
  • Refactor the self-check UI for better user experience.

Build:

  • Remove the default image folder named '爬'.

CI:

  • Update the CI workflow to prioritize using the GitHub API.

Documentation:

  • Update the README with new project information and formatting improvements.

Tests:

  • Add tests for the auto-update feature to ensure correct functionality.

Chores:

  • Remove unused imports and clean up the codebase for better maintainability.

HibiKier and others added 30 commits August 30, 2024 23:50
* ✅ 测试更新与添加插件

* ✅ Sourcery建议

* 👷 添加pytest

* 🎨 优化代码
* 完善测试方法
* vscode测试配置
* 重构插件安装过程
* 🐛 修复插件商店检查插件更新问题

* 🐛 恶意命令检测问题
* ✅ 优化测试用例

* 🐛 更改插件更新与安装逻辑
* 修复签到功能已知问题

* 修复签到功能已知问题

* 修改参数名称

* 修改uid判断

---------

Co-authored-by: HibiKier <[email protected]>
* 🐛 修复自检在ARM上的问题

* ✅ 优化测试
HibiKier and others added 27 commits September 14, 2024 16:29
* 🎈 perf(github_utils): 支持github url下载遍历

* 🐞 fix(http_utils): 修复一些下载问题

* 🦄 refactor(http_utils): 部分重构

* chore(version): Update version to v0.2.2-e6f17c4

---------

Co-authored-by: AkashiCoin <[email protected]>
* 🎈 perf: 使用commit号下载插件

* chore(version): Update version to v0.2.2-f9c7360

---------

Co-authored-by: AkashiCoin <[email protected]>
* 🐳 chore: 修改运行检查触发路径

* 🐳 chore: 添加tests目录
* 🐛 修复webui下载后首次启动错误

* chore(version): Update version to v0.2.2-4a8ef85

---------

Co-authored-by: HibiKier <[email protected]>
* ✨ 新增插件商店api

* chore(version): Update version to v0.2.2-7e15f20

---------

Co-authored-by: HibiKier <[email protected]>
Copy link
Contributor

sourcery-ai bot commented Sep 30, 2024

审核指南 by Sourcery

这个名为“版本更新”的拉取请求在 zhenxun_bot 项目中包含了多个文件的重大更改。更改包括各种改进、错误修复和新功能。重点领域包括重构帮助功能、添加新命令、更新插件系统、改进错误处理以及增强代码库的整体结构和效率。

序列图

插件安装过程

sequenceDiagram
    participant U as User
    participant PM as PluginManager
    participant PI as PluginInit
    participant DB as Database
    U->>PM: Install plugin
    PM->>PI: Call install method
    PI->>DB: Initialize plugin data
    DB-->>PI: Confirm initialization
    PI-->>PM: Installation complete
    PM-->>U: Plugin installed successfully
Loading

帮助命令执行

sequenceDiagram
    participant U as User
    participant HC as HelpCommand
    participant PC as PermissionChecker
    participant HD as HelpDisplay
    U->>HC: Request help
    HC->>PC: Check user permissions
    PC-->>HC: Permission granted
    HC->>HD: Generate help content
    HD-->>HC: Help content
    HC-->>U: Display help information
Loading

文件级更改

更改 详情 文件
重构了普通用户的帮助功能限制
  • 添加了用户权限检查以访问帮助信息
  • 实现了不同的帮助显示方法(HTML, zhenxun, normal)
  • 更新了帮助命令以支持特定群组的帮助图片
zhenxun/builtin_plugins/help/__init__.py
zhenxun/builtin_plugins/help/_data_source.py
zhenxun/builtin_plugins/help/_utils.py
增强了插件管理系统
  • 引入了用于插件安装和移除的 PluginInit 类
  • 添加了对父插件的支持
  • 实现了新的插件类型:PARENT
  • 更新了插件存储功能
zhenxun/services/plugin_init.py
zhenxun/models/plugin_info.py
zhenxun/utils/enum.py
zhenxun/builtin_plugins/plugin_store/__init__.py
zhenxun/builtin_plugins/plugin_store/data_source.py
改进了错误处理和日志记录
  • 为数据库相关错误添加了新的异常类型
  • 增强了插件初始化和执行的日志记录
  • 改进了错误消息和调试信息
zhenxun/services/db_context.py
zhenxun/services/log.py
更新了配置和实用功能
  • 重构了配置加载和管理
  • 为常见任务添加了新的实用功能
  • 更新了图像处理实用工具
zhenxun/configs/config.py
zhenxun/configs/utils/__init__.py
zhenxun/utils/common_utils.py
zhenxun/utils/image_utils.py
增强了 Web UI 功能
  • 为仪表板和插件管理添加了新的 API 端点
  • 更新了 WebSocket 处理以实现实时更新
  • 改进了 Web UI 中的文件管理
zhenxun/builtin_plugins/web_ui/__init__.py
zhenxun/builtin_plugins/web_ui/api/tabs/main/__init__.py
zhenxun/builtin_plugins/web_ui/api/tabs/system/__init__.py
更新并添加了新插件
  • 重构了签到插件,添加了新功能
  • 更新了自动更新插件,改进了版本检查
  • 添加了新插件:gold_redbag, word_clouds
zhenxun/builtin_plugins/sign_in/__init__.py
zhenxun/builtin_plugins/auto_update/_data_source.py
plugins/gold_redbag/__init__.py
plugins/word_clouds/__init__.py

提示和命令

与 Sourcery 互动

  • 触发新审核: 在拉取请求中评论 @sourcery-ai review
  • 继续讨论: 直接回复 Sourcery 的审核评论。
  • 从审核评论生成 GitHub 问题: 通过回复审核评论请求 Sourcery 创建问题。

自定义您的体验

访问您的仪表板以:

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

获取帮助

Original review guide in English

Reviewer's Guide by Sourcery

This pull request titled '版本更新' includes a significant number of changes across multiple files in the zhenxun_bot project. The changes encompass various improvements, bug fixes, and new features. Key areas of focus include refactoring help functionality, adding new commands, updating the plugin system, improving error handling, and enhancing the overall structure and efficiency of the codebase.

Sequence Diagrams

Plugin Installation Process

sequenceDiagram
    participant U as User
    participant PM as PluginManager
    participant PI as PluginInit
    participant DB as Database
    U->>PM: Install plugin
    PM->>PI: Call install method
    PI->>DB: Initialize plugin data
    DB-->>PI: Confirm initialization
    PI-->>PM: Installation complete
    PM-->>U: Plugin installed successfully
Loading

Help Command Execution

sequenceDiagram
    participant U as User
    participant HC as HelpCommand
    participant PC as PermissionChecker
    participant HD as HelpDisplay
    U->>HC: Request help
    HC->>PC: Check user permissions
    PC-->>HC: Permission granted
    HC->>HD: Generate help content
    HD-->>HC: Help content
    HC-->>U: Display help information
Loading

File-Level Changes

Change Details Files
Refactored help functionality with limitations for regular users
  • Added user permission checks for accessing help information
  • Implemented different help display methods (HTML, zhenxun, normal)
  • Updated help command to support group-specific help images
zhenxun/builtin_plugins/help/__init__.py
zhenxun/builtin_plugins/help/_data_source.py
zhenxun/builtin_plugins/help/_utils.py
Enhanced plugin management system
  • Introduced PluginInit class for plugin installation and removal
  • Added support for parent plugins
  • Implemented new plugin type: PARENT
  • Updated plugin store functionality
zhenxun/services/plugin_init.py
zhenxun/models/plugin_info.py
zhenxun/utils/enum.py
zhenxun/builtin_plugins/plugin_store/__init__.py
zhenxun/builtin_plugins/plugin_store/data_source.py
Improved error handling and logging
  • Added new exception types for database-related errors
  • Enhanced logging for plugin initialization and execution
  • Improved error messages and debugging information
zhenxun/services/db_context.py
zhenxun/services/log.py
Updated configuration and utility functions
  • Refactored configuration loading and management
  • Added new utility functions for common tasks
  • Updated image processing utilities
zhenxun/configs/config.py
zhenxun/configs/utils/__init__.py
zhenxun/utils/common_utils.py
zhenxun/utils/image_utils.py
Enhanced web UI functionality
  • Added new API endpoints for dashboard and plugin management
  • Updated WebSocket handling for real-time updates
  • Improved file management in web UI
zhenxun/builtin_plugins/web_ui/__init__.py
zhenxun/builtin_plugins/web_ui/api/tabs/main/__init__.py
zhenxun/builtin_plugins/web_ui/api/tabs/system/__init__.py
Updated and added new plugins
  • Refactored sign-in plugin with new features
  • Updated auto-update plugin with improved version checking
  • Added new plugins: gold_redbag, word_clouds
zhenxun/builtin_plugins/sign_in/__init__.py
zhenxun/builtin_plugins/auto_update/_data_source.py
plugins/gold_redbag/__init__.py
plugins/word_clouds/__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.

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

@HibiKier HibiKier merged commit 4e33bf3 into main Sep 30, 2024
1 check passed
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 and found some issues that need to be addressed.

Blocking issues:

  • Potential hard-coded message template with sensitive information. (link)

Overall Comments:

  • This PR introduces many positive changes, but its large scope makes it difficult to review thoroughly. Consider breaking future large changes into smaller, more focused PRs.
  • Given the critical nature of the update mechanism changes, it would be helpful to see more information about testing, especially around edge cases and potential failure scenarios.
Here's what I looked at during the review
  • 🟡 General issues: 11 issues found
  • 🔴 Security: 1 blocking issue
  • 🟡 Testing: 8 issues found
  • 🟡 Complexity: 2 issues found
  • 🟡 Documentation: 1 issue found

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.

@classmethod
async def __get_data(cls) -> dict:
@cached(60)
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (performance): Consider if 60 seconds is an appropriate cache duration for plugin data

The caching duration might need adjustment based on how frequently the plugin data changes and how critical it is to have the most up-to-date information. Consider making this value configurable.

    @cached(ttl=config.PLUGIN_DATA_CACHE_TTL)

github_url_split = plugin_info.github_url.split("/tree/")
plugin_info.github_url = f"{github_url_split[0]}/tree/{version_split[1]}"
logger.info(f"正在安装插件 {plugin_key}...")
await cls.install_plugin_with_repo(
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Improve error handling in install_plugin_with_repo method

The current implementation silently ignores some errors. Consider adding more robust error handling and logging to help diagnose issues during plugin installation.

Suggested change
await cls.install_plugin_with_repo(
try:
await cls.install_plugin_with_repo(
plugin_info.github_url,
plugin_info.module_path,
)
except Exception as e:
logger.error(f"Failed to install plugin {plugin_key}: {str(e)}")
raise

)

@classmethod
async def _get_first_successful(
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion (performance): Optimize the _get_first_successful method for better performance

Consider using asyncio.as_completed() to process URLs concurrently and return as soon as the first successful request is made. This could significantly improve performance when dealing with multiple URLs.

    @classmethod
    async def _get_first_successful(
        cls,
        urls: list[str],
        *,
        return_exceptions: bool = False
    ) -> tuple[Any, str]:
        async def fetch(url):
            try:
                return await cls.get(url), url
            except Exception as e:
                return e if return_exceptions else None

        for result in asyncio.as_completed(fetch(url) for url in urls):
            response, url = await result
            if response is not None:
                return response, url

@@ -295,6 +393,39 @@ async def gather_download_file(
tasks.clear()
return result_

@classmethod
async def get_fastest_mirror(cls, url_list: list[str]) -> list[str]:
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Improve error handling in get_fastest_mirror method

The current implementation logs warnings for failed requests but doesn't provide a way to handle or report these errors to the caller. Consider adding a mechanism to return both successful and failed results, allowing the caller to decide how to handle partial failures.

    @classmethod
    async def get_fastest_mirror(cls, url_list: list[str]) -> tuple[list[str], list[str]]:
        assert url_list
        successful_urls = []
        failed_urls = []

GROUP_HELP_PATH = DATA_PATH / "group_help"


def delete_help_image(gid: str | None = None):
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: Consider adding error handling to delete_help_image function

The function currently doesn't handle potential exceptions that could occur during file operations. Consider adding try-except blocks to catch and log any errors that might occur when deleting files.

def delete_help_image(gid: str | None = None):
    try:
        # Existing function implementation here
        pass
    except OSError as e:
        logger.error(f"Error deleting help image for group {gid}: {e}")
    except Exception as e:
        logger.error(f"Unexpected error deleting help image for group {gid}: {e}")


from tests.config import BotId, UserId, GroupId, MessageId
from tests.utils import get_response_json as _get_response_json
from tests.utils import _v11_group_message_event, _v11_private_message_send
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Don't import test modules. (dont-import-test-modules)

ExplanationDon't import test modules.

Tests should be self-contained and don't depend on each other.

If a helper function is used by multiple tests,
define it in a helper module,
instead of importing one test from the other.

from nonebot.adapters.onebot.v11 import Bot
from nonebot.adapters.onebot.v11.event import GroupMessageEvent

from tests.utils import _v11_group_message_event
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Don't import test modules. (dont-import-test-modules)

ExplanationDon't import test modules.

Tests should be self-contained and don't depend on each other.

If a helper function is used by multiple tests,
define it in a helper module,
instead of importing one test from the other.

from nonebot.adapters.onebot.v11.event import GroupMessageEvent

from tests.utils import _v11_group_message_event
from tests.config import BotId, UserId, GroupId, MessageId
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Don't import test modules. (dont-import-test-modules)

ExplanationDon't import test modules.

Tests should be self-contained and don't depend on each other.

If a helper function is used by multiple tests,
define it in a helper module,
instead of importing one test from the other.

from nonebot.adapters.onebot.v11.message import Message
from nonebot.adapters.onebot.v11.event import GroupMessageEvent

from tests.utils import _v11_group_message_event
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Don't import test modules. (dont-import-test-modules)

ExplanationDon't import test modules.

Tests should be self-contained and don't depend on each other.

If a helper function is used by multiple tests,
define it in a helper module,
instead of importing one test from the other.

from nonebot.adapters.onebot.v11.event import GroupMessageEvent

from tests.utils import _v11_group_message_event
from tests.config import BotId, UserId, GroupId, MessageId
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (code-quality): Don't import test modules. (dont-import-test-modules)

ExplanationDon't import test modules.

Tests should be self-contained and don't depend on each other.

If a helper function is used by multiple tests,
define it in a helper module,
instead of importing one test from the other.

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.

4 participants