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

重构webui适配 #1801

Merged
merged 15 commits into from
Dec 25, 2024
Merged

重构webui适配 #1801

merged 15 commits into from
Dec 25, 2024

Conversation

HibiKier
Copy link
Owner

@HibiKier HibiKier commented Dec 25, 2024

Summary by Sourcery

文档:

  • 更新了README文件,添加了新的徽章,更新了链接,改进了格式,并重新组织了部分内容以提高可读性。
Original summary in English

Summary by Sourcery

Documentation:

  • Updated the README file with new badges, updated links, improved formatting, and reorganized sections for better readability.

Copy link
Contributor

sourcery-ai bot commented Dec 25, 2024

Sourcery 审查指南

此拉取请求重构了 WebUI 以提高兼容性。

ApiDataSource 和相关模型的类图

classDiagram
    class ApiDataSource {
        +get_base_info(bot_id: str) list[BaseInfo]
        +get_all_chat_count(bot_id: str) QueryCount
        +get_all_call_count(bot_id: str) QueryCount
        +get_active_group(date_type: QueryDateType, bot_id: str) list[ActiveGroup]
        +get_hot_plugin(date_type: QueryDateType, bot_id: str) list[HotPlugin]
        +get_bot_block_module(bot_id: str) BotBlockModule
        -__build_bot_info(bot: Bot) TemplateBaseInfo
        -__get_bot_version() str
        -__init_bot_base_data(select_bot: TemplateBaseInfo)
        -__get_query(base_query, date_type, bot_id)
    }

    class PlatformUtils {
        +get_platform(bot: Bot) str
        +get_group_list(bot: Bot) tuple[list, str]
        +get_friend_list(bot: Bot) tuple[list, str]
        +send_message(bot: Bot, user_id: str, group_id: str, message: str)
    }

    class BaseInfo {
        +self_id: str
        +nickname: str
        +ava_url: str
        +received_messages: int
        +group_count: int
        +friend_count: int
        +day_call: int
        +version: str
        +connect_time: int
        +connect_date: str
        +connect_count: int
        +status: bool
        +is_select: bool
    }

    ApiDataSource ..> PlatformUtils : uses
    ApiDataSource ..> BaseInfo : creates
Loading

文件级别更改

更改 详情 文件
更新了 README 文件中的项目元数据和依赖项。
  • 添加了 markdownlint 禁用注释。
  • 更新了项目徽标图像来源。
  • 用更新的版本和链接替换了项目徽章。
  • 更新了 Python 版本兼容性。
  • 更新了 NoneBot 和 OneBot 徽章。
  • 添加了代码风格和类型检查工具的徽章。
  • 更新了 QQ 群链接。
  • 更新了 Star Trend 图像来源。
  • 更新了帮助页面图像和布局。
  • 更新了 WebUI 预览链接。
  • 改进了文档链接和格式。
  • 更新了部署说明。
  • 更新了贡献者信息并添加了统计徽章。
  • 在整个文件中进行了小的文本和格式更改以提高清晰度和一致性。
README.md
重构了 WebUI API 以提高兼容性和代码质量。
  • 简化了群组信息检索。
  • 改进了机器人连接和断开连接的处理。
  • 在用户数据中添加了对频道 ID 的支持。
  • 在各个平台上标准化了群组成员列表检索。
  • 简化了用户信息检索。
  • 简化了消息发送逻辑。
  • 更新了机器人基础数据初始化。
  • 改进了插件列表检索。
  • 增强了插件数据更新。
  • 添加了插件详细信息检索。
  • 重构了数据库表和列的检索。
  • 改进了 WebSocket 连接处理。
  • 优化了插件加载和初始化。
  • 增强了身份验证检查。
  • 改进了商店插件中的道具检索。
  • 简化了调度器中的聊天检查。
  • 添加了一个菜单 API 端点。
  • 在主 API 路由器中包含了菜单路由器。
zhenxun/builtin_plugins/web_ui/api/tabs/manage/__init__.py
zhenxun/utils/platform.py
zhenxun/builtin_plugins/web_ui/api/tabs/main/data_source.py
zhenxun/builtin_plugins/web_ui/api/tabs/main/__init__.py
zhenxun/builtin_plugins/web_ui/api/tabs/plugin_manage/__init__.py
zhenxun/builtin_plugins/web_ui/api/tabs/dashboard/data_source.py
zhenxun/builtin_plugins/web_ui/api/tabs/dashboard/__init__.py
zhenxun/builtin_plugins/web_ui/api/tabs/database/__init__.py
zhenxun/builtin_plugins/web_ui/api/tabs/manage/chat.py
zhenxun/builtin_plugins/init/init_plugin.py
zhenxun/builtin_plugins/web_ui/__init__.py
zhenxun/builtin_plugins/hooks/_auth_checker.py
zhenxun/builtin_plugins/shop/__init__.py
zhenxun/builtin_plugins/scheduler/chat_check.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 refactors the WebUI for better compatibility.

Class diagram for ApiDataSource and related models

classDiagram
    class ApiDataSource {
        +get_base_info(bot_id: str) list[BaseInfo]
        +get_all_chat_count(bot_id: str) QueryCount
        +get_all_call_count(bot_id: str) QueryCount
        +get_active_group(date_type: QueryDateType, bot_id: str) list[ActiveGroup]
        +get_hot_plugin(date_type: QueryDateType, bot_id: str) list[HotPlugin]
        +get_bot_block_module(bot_id: str) BotBlockModule
        -__build_bot_info(bot: Bot) TemplateBaseInfo
        -__get_bot_version() str
        -__init_bot_base_data(select_bot: TemplateBaseInfo)
        -__get_query(base_query, date_type, bot_id)
    }

    class PlatformUtils {
        +get_platform(bot: Bot) str
        +get_group_list(bot: Bot) tuple[list, str]
        +get_friend_list(bot: Bot) tuple[list, str]
        +send_message(bot: Bot, user_id: str, group_id: str, message: str)
    }

    class BaseInfo {
        +self_id: str
        +nickname: str
        +ava_url: str
        +received_messages: int
        +group_count: int
        +friend_count: int
        +day_call: int
        +version: str
        +connect_time: int
        +connect_date: str
        +connect_count: int
        +status: bool
        +is_select: bool
    }

    ApiDataSource ..> PlatformUtils : uses
    ApiDataSource ..> BaseInfo : creates
Loading

File-Level Changes

Change Details Files
Updated project metadata and dependencies in the README file.
  • Added markdownlint disable comments.
  • Updated the project logo image source.
  • Replaced project badges with updated versions and links.
  • Updated Python version compatibility.
  • Updated NoneBot and OneBot badges.
  • Added badges for code style and type checking tools.
  • Updated QQ group links.
  • Updated Star Trend image source.
  • Updated help page images and layout.
  • Updated WebUI preview link.
  • Improved documentation links and formatting.
  • Updated deployment instructions.
  • Updated contributor information and added statistics badges.
  • Minor text and formatting changes throughout the file to improve clarity and consistency.
README.md
Refactored WebUI API to improve compatibility and code quality.
  • Simplified group information retrieval.
  • Improved handling of bot connections and disconnections.
  • Added support for channel IDs in user data.
  • Standardized group member list retrieval across platforms.
  • Streamlined user information retrieval.
  • Simplified message sending logic.
  • Updated bot base data initialization.
  • Improved plugin list retrieval.
  • Enhanced plugin data updating.
  • Added plugin detail retrieval.
  • Refactored database table and column retrieval.
  • Improved WebSocket connection handling.
  • Optimized plugin loading and initialization.
  • Enhanced authentication checking.
  • Improved prop retrieval in the shop plugin.
  • Simplified chat checking in the scheduler.
  • Added a menu API endpoint.
  • Included menu router in the main API router.
zhenxun/builtin_plugins/web_ui/api/tabs/manage/__init__.py
zhenxun/utils/platform.py
zhenxun/builtin_plugins/web_ui/api/tabs/main/data_source.py
zhenxun/builtin_plugins/web_ui/api/tabs/main/__init__.py
zhenxun/builtin_plugins/web_ui/api/tabs/plugin_manage/__init__.py
zhenxun/builtin_plugins/web_ui/api/tabs/dashboard/data_source.py
zhenxun/builtin_plugins/web_ui/api/tabs/dashboard/__init__.py
zhenxun/builtin_plugins/web_ui/api/tabs/database/__init__.py
zhenxun/builtin_plugins/web_ui/api/tabs/manage/chat.py
zhenxun/builtin_plugins/init/init_plugin.py
zhenxun/builtin_plugins/web_ui/__init__.py
zhenxun/builtin_plugins/hooks/_auth_checker.py
zhenxun/builtin_plugins/shop/__init__.py
zhenxun/builtin_plugins/scheduler/chat_check.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 documentation Improvements or additions to documentation resources labels Dec 25, 2024
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 - 我已经审查了你的更改,它们看起来很棒!

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

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: 2 issues 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.

@@ -28,15 +28,15 @@

@driver.on_shutdown
async def _():
if ws_conn:
if ws_conn and ws_conn.client_state == WebSocketState.CONNECTED:
await ws_conn.close()


@ws_router.websocket("/chat")
async def _(websocket: WebSocket):
global ws_conn
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): 考虑使用连接管理器而不是全局变量来管理WebSocket连接

使用全局变量来管理WebSocket连接可能会导致多个客户端连接时出现竞争条件和连接问题。考虑实现一个可以处理多个同时连接的适当连接管理器。

建议的实现:

  1. 确保更新代码中之前使用ws_conn全局变量的任何其他部分,以使用适当的连接管理器方法
  2. 如果需要广播消息给所有连接,您可能需要为ConnectionManager类添加方法
  3. 考虑为连接失败添加错误处理
Original comment in English

suggestion (bug_risk): Consider using a connection manager instead of a global variable for websocket connections

Using a global variable for websocket connections could lead to race conditions and connection issues when multiple clients connect. Consider implementing a proper connection manager that can handle multiple simultaneous connections.

Suggested implementation:

from zhenxun.models.group_member_info import GroupInfoUser
from typing import List


class ConnectionManager:
    def __init__(self):
        self.active_connections: List[WebSocket] = []

    async def connect(self, websocket: WebSocket):
        await websocket.accept()
        self.active_connections.append(websocket)

    def disconnect(self, websocket: WebSocket):
        if websocket in self.active_connections:
            self.active_connections.remove(websocket)

    async def close_all(self):
        for connection in self.active_connections:
            if connection.client_state == WebSocketState.CONNECTED:
                await connection.close()
        self.active_connections.clear()


manager = ConnectionManager()
@driver.on_shutdown
async def _():
    await manager.close_all()


async def _(websocket: WebSocket):
    await manager.connect(websocket)
    try:
        while websocket.client_state == WebSocketState.CONNECTED:
  1. Make sure to update any other parts of the code that were previously using the ws_conn global variable to use the appropriate connection manager methods instead
  2. You may want to add methods to the ConnectionManager class for broadcasting messages to all connections if that functionality is needed
  3. Consider adding error handling for connection failures

<a href="https://nonebot.dev/">
<img src="https://img.shields.io/badge/nonebot-v2.1.3-EA5252" alt="nonebot">
</a>
<a href="https://onebot.dev/">
Copy link
Contributor

Choose a reason for hiding this comment

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

问题: QQ群链接不正确

QQ群的链接不正确。应该是https://qm.qq.com/q/mRNtLSl6uc

Original comment in English

issue: Incorrect QQ group link

The link for the QQ group is incorrect. It should be https://qm.qq.com/q/mRNtLSl6uc.

else None,
)
for member in members
]
return []

@classmethod
async def get_user(
Copy link
Contributor

Choose a reason for hiding this comment

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

问题 (代码质量): 我们发现了这些问题:

Original comment in English

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

@@ -411,69 +344,43 @@
return "unknown"

@classmethod
async def get_group_list(cls, bot: Bot) -> tuple[list[GroupConsole], str]:
async def get_group_list(
Copy link
Contributor

Choose a reason for hiding this comment

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

问题 (代码质量): 我们发现了这些问题:

Original comment in English

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

@HibiKier HibiKier merged commit 35014e4 into main Dec 25, 2024
3 checks passed
@HibiKier HibiKier deleted the feature/refactor-base branch December 25, 2024 04:03
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
documentation Improvements or additions to documentation resources
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants