From afce74afe8856b0dcd84db089836bfc443c0356b Mon Sep 17 00:00:00 2001 From: shoucandanghehe Date: Mon, 5 Aug 2024 11:56:48 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20=E4=BF=AE=E6=94=B9=E5=91=BD?= =?UTF-8?q?=E4=BB=A4=E6=B3=A8=E5=86=8C=E9=80=BB=E8=BE=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../games/tetrio/__init__.py | 178 ++---------------- .../games/tetrio/bind.py | 25 ++- .../games/tetrio/config.py | 23 ++- .../games/tetrio/record/__init__.py | 29 ++- .../games/tetrio/record/blitz.py | 11 +- .../games/tetrio/record/sprint.py | 11 +- 6 files changed, 105 insertions(+), 172 deletions(-) diff --git a/nonebot_plugin_tetris_stats/games/tetrio/__init__.py b/nonebot_plugin_tetris_stats/games/tetrio/__init__.py index 697ee5c..ba55712 100644 --- a/nonebot_plugin_tetris_stats/games/tetrio/__init__.py +++ b/nonebot_plugin_tetris_stats/games/tetrio/__init__.py @@ -1,16 +1,10 @@ -from arclet.alconna import Arg, ArgFlag, Args, Option, Subcommand -from nonebot_plugin_alconna import At +from nonebot_plugin_alconna import Subcommand from ...utils.exception import MessageFormatError -from ...utils.typing import Me - -# from .. import add_block_handlers, alc, command -from .. import alc, command +from .. import alc +from .. import command as main_command from .api import Player - -# from .api.typing import ValidRank from .constant import USER_ID, USER_NAME -from .typing import Template def get_player(user_id_or_name: str) -> Player | MessageFormatError: @@ -21,171 +15,21 @@ def get_player(user_id_or_name: str) -> Player | MessageFormatError: return MessageFormatError('用户名/ID不合法') -command.add( - Subcommand( - 'TETR.IO', - Subcommand( - 'bind', - Args( - Arg( - 'account', - get_player, - notice='TETR.IO 用户名 / ID', - flags=[ArgFlag.HIDDEN], - ) - ), - help_text='绑定 TETR.IO 账号', - ), - # Subcommand( - # 'query', - # Args( - # Arg( - # 'target', - # At | Me, - # notice='@想要查询的人 / 自己', - # flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL], - # ), - # Arg( - # 'account', - # get_player, - # notice='TETR.IO 用户名 / ID', - # flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL], - # ), - # ), - # Option( - # '--template', - # Arg('template', Template), - # alias=['-T'], - # help_text='要使用的查询模板', - # ), - # help_text='查询 TETR.IO 游戏信息', - # ), - Subcommand( - 'record', - Option( - '--40l', - dest='sprint', - ), - Option( - '--blitz', - dest='blitz', - ), - Args( - Arg( - 'target', - At | Me, - notice='@想要查询的人 / 自己', - flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL], - ), - Arg( - 'account', - get_player, - notice='TETR.IO 用户名 / ID', - flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL], - ), - ), - ), - # Subcommand( - # 'list', - # Option('--max-tr', Arg('max_tr', float), help_text='TR的上限'), - # Option('--min-tr', Arg('min_tr', float), help_text='TR的下限'), - # Option('--limit', Arg('limit', int), help_text='查询数量'), - # Option('--country', Arg('country', str), help_text='国家代码'), - # help_text='查询 TETR.IO 段位排行榜', - # ), - # Subcommand( - # 'rank', - # Subcommand( - # '--all', - # Option( - # '--template', - # Arg('template', Template), - # alias=['-T'], - # help_text='要使用的查询模板', - # ), - # dest='all', - # ), - # Option( - # '--detail', - # Arg('rank', ValidRank), - # alias=['-D'], - # ), - # help_text='查询 TETR.IO 段位信息', - # ), - Subcommand( - 'config', - Option( - '--default-template', - Arg('template', Template), - alias=['-DT', 'DefaultTemplate'], - ), - ), - alias=['TETRIO', 'tetr.io', 'tetrio', 'io'], - dest='TETRIO', - help_text='TETR.IO 游戏相关指令', - ) +command = Subcommand( + 'TETR.IO', + alias=['TETRIO', 'tetr.io', 'tetrio', 'io'], + dest='TETRIO', + help_text='TETR.IO 游戏相关指令', ) -# def rank_wrapper(slot: int | str, content: str | None): -# if slot == 'rank' and not content: -# return '--all' -# if content is not None: -# return f'--detail {content.lower()}' -# return content - - -alc.shortcut( - '(?i:io)(?i:绑定|绑|bind)', - command='tstats TETR.IO bind', - humanized='io绑定', -) -# alc.shortcut( -# '(?i:io)(?i:查询|查|query|stats)', -# command='tstats TETR.IO query', -# humanized='io查', -# ) -alc.shortcut( - '(?i:io)(?i:记录|record)(?i:40l)', - command='tstats TETR.IO record --40l', - humanized='io记录40l', -) -alc.shortcut( - '(?i:io)(?i:记录|record)(?i:blitz)', - command='tstats TETR.IO record --blitz', - humanized='io记录blitz', -) -# alc.shortcut( -# r'(?i:io)(?i:段位|段|rank)\s*(?P[a-zA-Z+-]{0,2})', -# command='tstats TETR.IO rank {rank}', -# humanized='iorank', -# fuzzy=False, -# wrapper=rank_wrapper, -# ) -alc.shortcut( - '(?i:io)(?i:配置|配|config)', - command='tstats TETR.IO config', - humanized='io配置', -) - -# alc.shortcut( -# 'fkosk', -# command='tstats TETR.IO query', -# arguments=['我'], -# fuzzy=False, -# humanized='An Easter egg!', -# ) - -# add_block_handlers(alc.assign('TETRIO.query')) - -# from . import bind, config, list, query, rank, record from . import bind, config, record # noqa: E402 +main_command.add(command) + __all__ = [ + 'alc', 'bind', 'config', - # 'list', - # 'query', - # 'rank', 'record', ] diff --git a/nonebot_plugin_tetris_stats/games/tetrio/bind.py b/nonebot_plugin_tetris_stats/games/tetrio/bind.py index c5d1be8..19edb13 100644 --- a/nonebot_plugin_tetris_stats/games/tetrio/bind.py +++ b/nonebot_plugin_tetris_stats/games/tetrio/bind.py @@ -2,6 +2,8 @@ from asyncio import gather from hashlib import md5 from urllib.parse import urlencode +from arclet.alconna import Arg, ArgFlag +from nonebot_plugin_alconna import Args, Subcommand from nonebot_plugin_alconna.uniseg import UniMessage from nonebot_plugin_orm import get_session from nonebot_plugin_session import EventSession # type: ignore[import-untyped] @@ -15,10 +17,31 @@ from ...utils.image import get_avatar from ...utils.render import Bind, render from ...utils.render.schemas.base import Avatar, People from ...utils.screenshot import screenshot -from . import alc +from . import alc, command, get_player from .api import Player from .constant import GAME_TYPE +command.add( + Subcommand( + 'bind', + Args( + Arg( + 'account', + get_player, + notice='TETR.IO 用户名 / ID', + flags=[ArgFlag.HIDDEN], + ) + ), + help_text='绑定 TETR.IO 账号', + ) +) + +alc.shortcut( + '(?i:io)(?i:绑定|绑|bind)', + command='tstats TETR.IO bind', + humanized='io绑定', +) + @alc.assign('TETRIO.bind') async def _(nb_user: User, account: Player, event_session: EventSession, bot_info: UserInfo = BotUserInfo()): # noqa: B008 diff --git a/nonebot_plugin_tetris_stats/games/tetrio/config.py b/nonebot_plugin_tetris_stats/games/tetrio/config.py index 9ec44e1..215ca01 100644 --- a/nonebot_plugin_tetris_stats/games/tetrio/config.py +++ b/nonebot_plugin_tetris_stats/games/tetrio/config.py @@ -1,3 +1,5 @@ +from arclet.alconna import Arg +from nonebot_plugin_alconna import Option, Subcommand from nonebot_plugin_alconna.uniseg import UniMessage from nonebot_plugin_orm import async_scoped_session from nonebot_plugin_session import EventSession # type: ignore[import-untyped] @@ -6,11 +8,30 @@ from nonebot_plugin_user import User # type: ignore[import-untyped] from sqlalchemy import select from ...db import trigger -from . import alc +from . import alc, command from .constant import GAME_TYPE from .models import TETRIOUserConfig from .typing import Template +command.add( + Subcommand( + 'config', + Option( + '--default-template', + Arg('template', Template, notice='模板版本'), + alias=['-DT', 'DefaultTemplate'], + help_text='设置默认查询模板', + ), + help_text='TETR.IO 查询个性化配置', + ), +) + +alc.shortcut( + '(?i:io)(?i:配置|配|config)', + command='tstats TETR.IO config', + humanized='io配置', +) + @alc.assign('TETRIO.config') async def _(user: User, session: async_scoped_session, event_session: EventSession, template: Template): diff --git a/nonebot_plugin_tetris_stats/games/tetrio/record/__init__.py b/nonebot_plugin_tetris_stats/games/tetrio/record/__init__.py index 87f9941..d9c81de 100644 --- a/nonebot_plugin_tetris_stats/games/tetrio/record/__init__.py +++ b/nonebot_plugin_tetris_stats/games/tetrio/record/__init__.py @@ -1,4 +1,31 @@ -from . import blitz, sprint +from arclet.alconna import Arg, ArgFlag +from nonebot_plugin_alconna import Args, At, Subcommand + +from ....utils.typing import Me +from .. import command as base_command +from .. import get_player + +command = Subcommand( + 'record', + Args( + Arg( + 'target', + At | Me, + notice='@想要查询的人 / 自己', + flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL], + ), + Arg( + 'account', + get_player, + notice='TETR.IO 用户名 / ID', + flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL], + ), + ), +) + +from . import blitz, sprint # noqa: E402 + +base_command.add(command) __all__ = [ 'blitz', diff --git a/nonebot_plugin_tetris_stats/games/tetrio/record/blitz.py b/nonebot_plugin_tetris_stats/games/tetrio/record/blitz.py index 69583d5..b1966dc 100644 --- a/nonebot_plugin_tetris_stats/games/tetrio/record/blitz.py +++ b/nonebot_plugin_tetris_stats/games/tetrio/record/blitz.py @@ -5,7 +5,7 @@ from urllib.parse import urlencode from nonebot.adapters import Event from nonebot.matcher import Matcher -from nonebot_plugin_alconna import At +from nonebot_plugin_alconna import At, Option from nonebot_plugin_alconna.uniseg import UniMessage from nonebot_plugin_orm import get_session from nonebot_plugin_session import EventSession # type: ignore[import-untyped] @@ -26,6 +26,15 @@ from ...constant import CANT_VERIFY_MESSAGE from .. import alc from ..api.player import Player from ..constant import GAME_TYPE +from . import command + +command.add(Option('--blitz', dest='blitz')) + +alc.shortcut( + '(?i:io)(?i:记录|record)(?i:blitz)', + command='tstats TETR.IO record --blitz', + humanized='io记录blitz', +) @alc.assign('TETRIO.record.blitz') diff --git a/nonebot_plugin_tetris_stats/games/tetrio/record/sprint.py b/nonebot_plugin_tetris_stats/games/tetrio/record/sprint.py index 5a9dff8..de05e5b 100644 --- a/nonebot_plugin_tetris_stats/games/tetrio/record/sprint.py +++ b/nonebot_plugin_tetris_stats/games/tetrio/record/sprint.py @@ -5,7 +5,7 @@ from urllib.parse import urlencode from nonebot.adapters import Event from nonebot.matcher import Matcher -from nonebot_plugin_alconna import At +from nonebot_plugin_alconna import At, Option from nonebot_plugin_alconna.uniseg import UniMessage from nonebot_plugin_orm import get_session from nonebot_plugin_session import EventSession # type: ignore[import-untyped] @@ -26,6 +26,15 @@ from ...constant import CANT_VERIFY_MESSAGE from .. import alc from ..api.player import Player from ..constant import GAME_TYPE +from . import command + +command.add(Option('--40l', dest='sprint')) + +alc.shortcut( + '(?i:io)(?i:记录|record)(?i:40l)', + command='tstats TETR.IO record --40l', + humanized='io记录40l', +) @alc.assign('TETRIO.record.sprint')