Open
Conversation
- 新增 AdminCommandHandler 和 UserCommandHandler 类,分离管理员和用户命令处理逻辑 - 创建 command_router.py 文件,统一管理命令路由 - 移除 commands.py 中冗余的命令处理逻辑
文件级别变更
提示和命令与 Sourcery 互动
自定义您的体验访问您的 仪表板 以:
获得帮助Original review guide in EnglishReviewer's Guide by SourceryThis PR refactors the bot command processing by separating user and admin commands into distinct handlers, centralizing command routing, and modularizing utility functions. Additionally, it removes redundant code and updates how certain properties are accessed in user services. Class diagram for AdminCommandHandler & UserCommandHandlerclassDiagram
class UserCommandHandler {
- bot_client: BotClient
- user_service: UserService
- code_to_message_id: Dict
+ count(message: Message)
+ info(message: Message)
+ use_code(message: Message)
+ select_line(message: Message)
+ create_user(message: Message)
+ reset_emby_password(message: Message)
+ help_command(message: Message)
+ handle_callback_query(client, CallbackQuery)
}
class AdminCommandHandler {
- bot_client: BotClient
- user_service: UserService
- code_to_message_id: Dict
+ new_code(message: Message)
+ new_whitelist_code(message: Message)
+ ban_emby(message: Message)
+ unban_emby(message: Message)
+ register_until(message: Message)
+ register_amount(message: Message)
+ send_code(code_list, message: Message, whitelist: bool)
+ group_member_change_handler(client, message: Message)
}
UserCommandHandler <|-- AdminCommandHandler : similar structure
note for UserCommandHandler "Handles all user-initiated commands"
note for AdminCommandHandler "Handles all admin-related commands"
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey @linhemin - I've reviewed your changes and found some issues that need to be addressed.
Blocking issues:
- Recursive call to group_member_change_handler causes unintentional recursion. (link)
Overall Comments:
- Consider adding a base class or interface for
AdminCommandHandlerandUserCommandHandlerto enforce a contract for command handlers. - The
code_to_message_iddictionary is used in bothAdminCommandHandlerandUserCommandHandler; consider moving it to a shared base class or a separate utility.
Here's what I looked at during the review
- 🔴 General issues: 1 blocking issue, 1 other issue
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
- 新增 EventHandler 类统一处理回调查询和群组成员变更事件 - 从 AdminCommandHandler 和 UserCommandHandler 中移除相关事件处理代码 - 更新命令路由注册逻辑,使用新的 EventHandler 实例 - 优化日志记录配置,支持文件和控制台输出
- 将 admin_command、event_command 和 user_command 模块的导入路径修改为 bot.command包下的路径 - 这个改动统一了命令模块的导入路径格式,提高了代码的可维护性和可读性
- 将命令路由定义从单独的函数封装为统一的列表结构 - 通过循环动态注册消息处理器,简化了代码结构- 新增命令支持:new_code, new_whitelist_code, ban_emby, unban_emby, register_until, register_amount - 保留了现有的回调查询和群组成员变动处理器
Frankoul
reviewed
Feb 13, 2025
Frankoul
reviewed
Feb 13, 2025
- 更新多个命令处理函数,使用新的参数解析装饰器- 优化代码结构,提高可读性和可维护性
- 移除了原有的 ensure_args 函数 - 新增了 with_ensure_args 装饰器,用于参数数量检查 - 在 admin_command.py 和 user_command.py 中使用新装饰器替换原有的参数检查逻辑- 更新了 with_parsed_args装饰器的注释说明
- 将 CommandHandler 类从 commands.py 移动到 command/__init__.py - 创建新的 utils/__init__.py 文件,集中通用工具函数 - 更新模块导入路径,使用相对路径导入 - 优化代码格式和结构,提高可读性
- 调整代码缩进和换行,提高可读性 - 统一使用 f-string 格式化字符串 - 优化部分变量和函数命名 - 移除冗余的空行和导入 - 消除警告
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
好的,这是翻译成中文的 pull request 总结:
Sourcery 总结
重构命令处理逻辑,将管理命令和用户命令分离到专用类中,并引入集中式命令路由器。
新特性:
增强功能:
Original summary in English
Summary by Sourcery
Refactor command handling logic by separating admin and user commands into dedicated classes and introducing a centralized command router.
New Features:
Enhancements: