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

*  签到/金币排行限制最大数量
This commit is contained in:
HibiKier 2024-09-09 22:47:23 +08:00 committed by GitHub
parent f11e9c58e4
commit e4a92ea34b
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 16 additions and 4 deletions

View File

@ -55,7 +55,7 @@ _matcher = on_alconna(
Subcommand("my-props", help_text="我的道具"), Subcommand("my-props", help_text="我的道具"),
Subcommand("buy", Args["name", str]["num", int, 1], help_text="购买道具"), Subcommand("buy", Args["name", str]["num", int, 1], help_text="购买道具"),
Subcommand("use", 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, priority=5,
block=True, block=True,
@ -181,8 +181,14 @@ async def _(
async def _( async def _(
session: EventSession, arparma: Arparma, num: Query[int] = AlconnaQuery("num", 10) session: EventSession, arparma: Arparma, num: Query[int] = AlconnaQuery("num", 10)
): ):
if num.result > 50:
await MessageUtils.build_message("排行榜人数不能超过50哦...").finish()
if session.id1: if session.id1:
gid = session.id3 or session.id2 gid = session.id3 or session.id2
if not arparma.find("all") and not gid:
await MessageUtils.build_message(
"私聊中无法查看 '金币排行',请发送 '金币总排行'"
).finish()
if arparma.find("all"): if arparma.find("all"):
gid = None gid = None
result = await gold_rank(session.id1, gid, num.result, session.platform) result = await gold_rank(session.id1, gid, num.result, session.platform)

View File

@ -3,9 +3,11 @@ from nonebot_plugin_session import EventSession
from nonebot_plugin_apscheduler import scheduler from nonebot_plugin_apscheduler import scheduler
from nonebot_plugin_alconna import ( from nonebot_plugin_alconna import (
Args, Args,
Query,
Option, Option,
Alconna, Alconna,
Arparma, Arparma,
AlconnaQuery,
on_alconna, on_alconna,
store_true, store_true,
) )
@ -90,7 +92,7 @@ _sign_matcher = on_alconna(
Option("--my", action=store_true, help_text="我的签到"), Option("--my", action=store_true, help_text="我的签到"),
Option( Option(
"-l|--list", "-l|--list",
Args["num", int, 10], Args["num", int],
help_text="好感度排行", help_text="好感度排行",
), ),
Option("-g|--global", action=store_true, help_text="全局排行"), Option("-g|--global", action=store_true, help_text="全局排行"),
@ -140,7 +142,11 @@ async def _(session: EventSession, arparma: Arparma, nickname: str = UserName())
@_sign_matcher.assign("list") @_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:
await MessageUtils.build_message("排行榜人数不能超过50哦...").finish()
gid = session.id3 or session.id2 gid = session.id3 or session.id2
if not arparma.find("global") and not gid: if not arparma.find("global") and not gid:
await MessageUtils.build_message( await MessageUtils.build_message(
@ -149,7 +155,7 @@ async def _(session: EventSession, arparma: Arparma, num: int):
if session.id1: if session.id1:
if arparma.find("global"): if arparma.find("global"):
gid = None 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) logger.info("查看签到排行", arparma.header_result, session=session)
await MessageUtils.build_message(image).finish() await MessageUtils.build_message(image).finish()
return MessageUtils.build_message("用户id为空...").send() return MessageUtils.build_message("用户id为空...").send()