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

✨ 签到/金币排行限制最大数量 #1616

Merged
merged 2 commits into from
Sep 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion zhenxun/builtin_plugins/shop/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
Subcommand("my-props", help_text="我的道具"),
Subcommand("buy", Args["name", str]["num", int, 1], help_text="购买道具"),
Subcommand("use", Args["name", str]["num?", int, 1], help_text="使用道具"),
Subcommand("gold-list", Args["num?", int], help_text="使用道具"),
Subcommand("gold-list", Args["num", int], help_text="金币排行"),
),
priority=5,
block=True,
Expand Down Expand Up @@ -181,8 +181,14 @@ async def _(
async def _(
session: EventSession, arparma: Arparma, num: Query[int] = AlconnaQuery("num", 10)
):
if num.result > 50:
await MessageUtils.build_message("排行榜人数不能超过50哦...").finish()
if session.id1:
gid = session.id3 or session.id2
if not arparma.find("all") and not gid:
await MessageUtils.build_message(
"私聊中无法查看 '金币排行',请发送 '金币总排行'"
).finish()
Comment on lines +188 to +191
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: 考虑将私信检查通用化

此私信检查对其他命令也可能有用。考虑创建一个装饰器或实用函数来处理此检查,可以在不同的命令处理程序中重用。

async def check_private_message(gid: Optional[int], action: str):
    if not gid:
        await MessageUtils.build_message(
            f"私聊中无法查看 '{action}',请发送 '{action}总排行'"
        ).finish()

if not arparma.find("all"):
    await check_private_message(gid, "金币排行")
Original comment in English

suggestion: Consider generalizing the private message check

This check for private messages could be useful for other commands as well. Consider creating a decorator or utility function to handle this check, which could be reused across different command handlers.

async def check_private_message(gid: Optional[int], action: str):
    if not gid:
        await MessageUtils.build_message(
            f"私聊中无法查看 '{action}',请发送 '{action}总排行'"
        ).finish()

if not arparma.find("all"):
    await check_private_message(gid, "金币排行")

if arparma.find("all"):
gid = None
result = await gold_rank(session.id1, gid, num.result, session.platform)
Expand Down
12 changes: 9 additions & 3 deletions zhenxun/builtin_plugins/sign_in/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@
from nonebot_plugin_apscheduler import scheduler
from nonebot_plugin_alconna import (
Args,
Query,
Option,
Alconna,
Arparma,
AlconnaQuery,
on_alconna,
store_true,
)
Expand Down Expand Up @@ -90,7 +92,7 @@
Option("--my", action=store_true, help_text="我的签到"),
Option(
"-l|--list",
Args["num", int, 10],
Args["num", int],
help_text="好感度排行",
),
Option("-g|--global", action=store_true, help_text="全局排行"),
Expand Down Expand Up @@ -140,7 +142,11 @@ async def _(session: EventSession, arparma: Arparma, nickname: str = UserName())


@_sign_matcher.assign("list")
async def _(session: EventSession, arparma: Arparma, num: int):
async def _(
session: EventSession, arparma: Arparma, num: Query[int] = AlconnaQuery("num", 10)
):
if num.result > 50:
Copy link
Contributor

Choose a reason for hiding this comment

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

suggestion: 考虑为最大排名限制定义一个常量

为了提高可维护性和一致性,考虑在模块级别定义一个常量,如 MAX_RANK_LIMIT = 50,并在此处和其他类似检查中使用它。

MAX_RANK_LIMIT = 50

# ... (earlier in the file)

    if num.result > MAX_RANK_LIMIT:
Original comment in English

suggestion: Consider defining a constant for the maximum rank limit

To improve maintainability and consistency, consider defining a constant like MAX_RANK_LIMIT = 50 at the module level and using it here and in other similar checks.

MAX_RANK_LIMIT = 50

# ... (earlier in the file)

    if num.result > MAX_RANK_LIMIT:

await MessageUtils.build_message("排行榜人数不能超过50哦...").finish()
gid = session.id3 or session.id2
if not arparma.find("global") and not gid:
await MessageUtils.build_message(
Expand All @@ -149,7 +155,7 @@ async def _(session: EventSession, arparma: Arparma, num: int):
if session.id1:
if arparma.find("global"):
gid = None
if image := await SignManage.rank(session.id1, num, gid):
if image := await SignManage.rank(session.id1, num.result, gid):
logger.info("查看签到排行", arparma.header_result, session=session)
await MessageUtils.build_message(image).finish()
return MessageUtils.build_message("用户id为空...").send()
Expand Down
Loading