-
Notifications
You must be signed in to change notification settings - Fork 605
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
✨ unban支持使用id #1681
✨ unban支持使用id #1681
Conversation
审核指南由 Sourcery 提供此拉取请求通过添加使用用户 ID 解禁的支持来增强禁用功能。它还重构并改进了现有的禁用和解禁逻辑,使代码更高效且更易于维护。 使用 ID 的解禁过程序列图sequenceDiagram
actor Admin
participant System
participant BanManage
participant BanConsole
Admin->>System: Initiate unban with --id [idx]
System->>BanManage: Call unban(user_id, group_id, session, idx, is_superuser)
BanManage->>BanConsole: Get ban data by id
alt Ban data exists
BanConsole-->>BanManage: Return ban data
BanManage->>BanConsole: Delete ban data
BanManage-->>System: Return success
System-->>Admin: Notify unban success
else Ban data does not exist
BanManage-->>System: Return failure
System-->>Admin: Notify unban failure
end
更新后的 BanConsole 模型类图classDiagram
class BanConsole {
IntField id
CharField user_id
CharField group_id
IntField ban_time
IntField duration
CharField ban_level
CharField operator
+_get_data(user_id: str | None, group_id: str | None) Self | None
+check_ban_level(user_id: str | None, group_id: str | None, user_level: int) bool
+check_ban_time(user_id: str | None, group_id: str | None) int
+is_ban(user_id: str | None, group_id: str | None) bool
+ban(user_id: str, group_id: str, ban_level: str, duration: int)
+unban(user_id: str | None, group_id: str | None)
}
文件级更改
提示和命令与 Sourcery 互动
自定义您的体验访问您的仪表板以:
获取帮助Original review guide in EnglishReviewer's Guide by SourceryThis pull request enhances the ban functionality by adding support for unbanning users using their ID. It also refactors and improves the existing ban and unban logic, making the code more efficient and easier to maintain. Sequence diagram for unban process using IDsequenceDiagram
actor Admin
participant System
participant BanManage
participant BanConsole
Admin->>System: Initiate unban with --id [idx]
System->>BanManage: Call unban(user_id, group_id, session, idx, is_superuser)
BanManage->>BanConsole: Get ban data by id
alt Ban data exists
BanConsole-->>BanManage: Return ban data
BanManage->>BanConsole: Delete ban data
BanManage-->>System: Return success
System-->>Admin: Notify unban success
else Ban data does not exist
BanManage-->>System: Return failure
System-->>Admin: Notify unban failure
end
Updated class diagram for BanConsole modelclassDiagram
class BanConsole {
IntField id
CharField user_id
CharField group_id
IntField ban_time
IntField duration
CharField ban_level
CharField operator
+_get_data(user_id: str | None, group_id: str | None) Self | None
+check_ban_level(user_id: str | None, group_id: str | None, user_level: int) bool
+check_ban_time(user_id: str | None, group_id: str | None) int
+is_ban(user_id: str | None, group_id: str | None) bool
+ban(user_id: str, group_id: str, ban_level: str, duration: int)
+unban(user_id: str | None, group_id: str | None)
}
File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
嘿 @HibiKier - 我已经审查了你的更改,看起来很棒!
这是我在审查期间查看的内容
- 🟡 一般问题: 发现1个问题
- 🟢 安全性: 一切看起来都很好
- 🟢 测试: 一切看起来都很好
- 🟡 复杂性: 发现1个问题
- 🟢 文档: 一切看起来都很好
帮助我变得更有用!请点击👍或👎在每个评论上,我将使用反馈来改进你的审查。
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: 1 issue found
- 🟢 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.
is_superuser: bool = False, | ||
) -> bool: | ||
) -> tuple[bool, str]: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
建议: 考虑简化unban函数中的嵌套if-else结构
当前嵌套if-else语句的结构可以简化以提高可读性和可维护性。考虑使用提前返回或更线性的逻辑流。
) -> tuple[bool, str]: | |
) -> tuple[bool, str]: | |
if not user_id: | |
return False, "请输入正确的用户id..." | |
if not await BanUser.check_ban_level(user_id): | |
return False, f"解禁失败,{user_id}不在封禁列表中!" | |
await BanUser.unban(user_id) | |
return True, f"已将{user_id}解除封禁!" |
Original comment in English
suggestion: Consider simplifying the nested if-else structure in the unban function
The current structure of nested if-else statements could be simplified to improve readability and maintainability. Consider using early returns or a more linear flow of logic.
) -> tuple[bool, str]: | |
) -> tuple[bool, str]: | |
if not user_id: | |
return False, "请输入正确的用户id..." | |
if not await BanUser.check_ban_level(user_id): | |
return False, f"解禁失败,{user_id}不在封禁列表中!" | |
await BanUser.unban(user_id) | |
return True, f"已将{user_id}解除封禁!" |
@@ -238,8 +240,10 @@ async def _( | |||
arparma: Arparma, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
问题 (复杂性): 考虑重构unban函数以改善其结构和可读性。
随着新功能的添加,unban函数变得更加复杂。虽然增加的功能很有价值,但我们可以改进其结构以提高可读性和可维护性。以下是一些建议:
- 使用提前返回以减少嵌套:
async def unban_handler(bot: Bot, session: EventSession, arparma: Arparma, user: Match[str | At], group_id: Match[str], idx: Match[int]):
user_id = ""
_idx = idx.result if idx.available else None
if not user.available and session.id1 not in bot.config.superusers:
await MessageUtils.build_message("权限不足捏...").finish(reply_to=True)
return
user_id = get_user_id(user)
gid = session.id3 or session.id2
_group_id = group_id.result if group_id.available else None
is_superuser = session.id1 in bot.config.superusers
unban_target = gid if gid else _group_id
is_unban, result = await BanManage.unban(user_id, unban_target, session, _idx, is_superuser)
if not is_unban:
await MessageUtils.build_message(result).finish(reply_to=True)
return
log_unban(is_superuser, arparma, session, unban_target, result)
await send_unban_message(user, result, unban_target)
- 提取辅助函数以提高可读性:
def get_user_id(user: Match[str | At]) -> str:
if isinstance(user.result, At):
return user.result.target
return user.result
def log_unban(is_superuser: bool, arparma: Arparma, session: EventSession, target: str, result: str):
logger.info(
"超级用户UnBan" if is_superuser else "管理员UnBan",
arparma.header_result,
session=session,
target=f"{target}:{result}",
)
async def send_unban_message(user: Match[str | At], result: str, target: str):
at_msg = At(flag="user", target=result) if isinstance(user.result, At) else result
message = f"对 {at_msg} 从黑屋中拉了出来并急救了一下!" if target else [
"将 ", at_msg, " 从黑屋中拉了出来并急救了一下!"
]
await MessageUtils.build_message(message).finish(reply_to=True)
这些更改将使结构扁平化,减少重复,并使代码更易于理解和维护,同时保留所有新功能。
Original comment in English
issue (complexity): Consider refactoring the unban function to improve its structure and readability.
The unban function has become more complex with the addition of new features. While the added functionality is valuable, we can improve its structure for better readability and maintainability. Here are some suggestions:
- Use early returns to reduce nesting:
async def unban_handler(bot: Bot, session: EventSession, arparma: Arparma, user: Match[str | At], group_id: Match[str], idx: Match[int]):
user_id = ""
_idx = idx.result if idx.available else None
if not user.available and session.id1 not in bot.config.superusers:
await MessageUtils.build_message("权限不足捏...").finish(reply_to=True)
return
user_id = get_user_id(user)
gid = session.id3 or session.id2
_group_id = group_id.result if group_id.available else None
is_superuser = session.id1 in bot.config.superusers
unban_target = gid if gid else _group_id
is_unban, result = await BanManage.unban(user_id, unban_target, session, _idx, is_superuser)
if not is_unban:
await MessageUtils.build_message(result).finish(reply_to=True)
return
log_unban(is_superuser, arparma, session, unban_target, result)
await send_unban_message(user, result, unban_target)
- Extract helper functions to improve readability:
def get_user_id(user: Match[str | At]) -> str:
if isinstance(user.result, At):
return user.result.target
return user.result
def log_unban(is_superuser: bool, arparma: Arparma, session: EventSession, target: str, result: str):
logger.info(
"超级用户UnBan" if is_superuser else "管理员UnBan",
arparma.header_result,
session=session,
target=f"{target}:{result}",
)
async def send_unban_message(user: Match[str | At], result: str, target: str):
at_msg = At(flag="user", target=result) if isinstance(user.result, At) else result
message = f"对 {at_msg} 从黑屋中拉了出来并急救了一下!" if target else [
"将 ", at_msg, " 从黑屋中拉了出来并急救了一下!"
]
await MessageUtils.build_message(message).finish(reply_to=True)
These changes will flatten the structure, reduce duplication, and make the code easier to understand and maintain while preserving all the new functionality.
Summary by Sourcery
通过添加使用用户ID解除封禁的功能并改进解除封禁操作的反馈机制,增强封禁管理系统。重构数据检索方法以提高效率和清晰度。
新功能:
unban --id [idx]
使用用户ID解除封禁的支持。增强:
unban
函数以返回一个表示成功与消息的元组,增强操作的反馈。BanConsole
中的_get_data
方法以简化用户或组数据的检索。Original summary in English
Summary by Sourcery
Enhance the ban management system by adding the ability to unban users using their ID and improve the feedback mechanism for unban operations. Refactor data retrieval methods for better efficiency and clarity.
New Features:
unban --id [idx]
.Enhancements:
unban
function to return a tuple indicating success and a message, enhancing feedback for the operation._get_data
method inBanConsole
to streamline the retrieval of user or group data.