diff --git a/nonebot_plugin_tetris_stats/games/tetrio/bind.py b/nonebot_plugin_tetris_stats/games/tetrio/bind.py index c7329f2..435c60e 100644 --- a/nonebot_plugin_tetris_stats/games/tetrio/bind.py +++ b/nonebot_plugin_tetris_stats/games/tetrio/bind.py @@ -41,7 +41,7 @@ async def _(bot: Bot, event: Event, account: Player, event_session: EventSession if bind_status in (BindStatus.SUCCESS, BindStatus.UPDATE): async with HostPage( await render( - 'binding', + 'v1/binding', Bind( platform='TETR.IO', status='unknown', diff --git a/nonebot_plugin_tetris_stats/games/tetrio/query.py b/nonebot_plugin_tetris_stats/games/tetrio/query.py index 894df33..9f32226 100644 --- a/nonebot_plugin_tetris_stats/games/tetrio/query.py +++ b/nonebot_plugin_tetris_stats/games/tetrio/query.py @@ -229,7 +229,7 @@ async def make_query_image( blitz_value = f'{blitz.endcontext.score:,}' if blitz is not None else 'N/A' async with HostPage( await render( - 'tetrio/info', + 'v1/tetrio/info', Info( user=TemplateUser( avatar=f'https://tetr.io/user-content/avatars/{user_info.data.user.id}.jpg?rv={user_info.data.user.avatar_revision}' diff --git a/nonebot_plugin_tetris_stats/games/top/bind.py b/nonebot_plugin_tetris_stats/games/top/bind.py index c86a723..c0c1f28 100644 --- a/nonebot_plugin_tetris_stats/games/top/bind.py +++ b/nonebot_plugin_tetris_stats/games/top/bind.py @@ -45,7 +45,7 @@ async def _( if bind_status in (BindStatus.SUCCESS, BindStatus.UPDATE): async with HostPage( await render( - 'binding', + 'v1/binding', Bind( platform=GAME_TYPE, status='unknown', diff --git a/nonebot_plugin_tetris_stats/games/tos/bind.py b/nonebot_plugin_tetris_stats/games/tos/bind.py index 472cf45..7820c8e 100644 --- a/nonebot_plugin_tetris_stats/games/tos/bind.py +++ b/nonebot_plugin_tetris_stats/games/tos/bind.py @@ -46,7 +46,7 @@ async def _( if bind_status in (BindStatus.SUCCESS, BindStatus.UPDATE): async with HostPage( await render( - 'binding', + 'v1/binding', Bind( platform=GAME_TYPE, status='unknown', diff --git a/nonebot_plugin_tetris_stats/games/tos/query.py b/nonebot_plugin_tetris_stats/games/tos/query.py index a8be90f..9aa925d 100644 --- a/nonebot_plugin_tetris_stats/games/tos/query.py +++ b/nonebot_plugin_tetris_stats/games/tos/query.py @@ -204,7 +204,7 @@ async def make_query_image(user_info: UserInfoSuccess, game_data: GameData, even sprint_value = f'{duration:.3f}s' if duration < 60 else f'{duration // 60:.0f}m {duration % 60:.3f}s' # noqa: PLR2004 async with HostPage( await render( - 'tos/info', + 'v1/tos/info', Info( user=People(avatar=await get_avatar(event_user_info, 'Data URI', None), name=user_info.data.name), ranking=Ranking(rating=float(user_info.data.ranking), rd=round(float(user_info.data.rd_now), 2)), diff --git a/nonebot_plugin_tetris_stats/utils/render/__init__.py b/nonebot_plugin_tetris_stats/utils/render/__init__.py index d4caef6..189e5d9 100644 --- a/nonebot_plugin_tetris_stats/utils/render/__init__.py +++ b/nonebot_plugin_tetris_stats/utils/render/__init__.py @@ -6,6 +6,7 @@ from nonebot.compat import PYDANTIC_V2 from ..templates import templates_dir from .schemas.bind import Bind from .schemas.tetrio_info import Info as TETRIOInfo +from .schemas.tetrio_info_v2 import Info as TETRIOInfoV2 from .schemas.top_info import Info as TOPInfo from .schemas.tos_info import Info as TOSInfo @@ -15,23 +16,28 @@ env = Environment( @overload -async def render(render_type: Literal['binding'], data: Bind) -> str: ... +async def render(render_type: Literal['v1/binding'], data: Bind) -> str: ... @overload -async def render(render_type: Literal['tetrio/info'], data: TETRIOInfo) -> str: ... +async def render(render_type: Literal['v1/tetrio/info'], data: TETRIOInfo) -> str: ... @overload -async def render(render_type: Literal['top/info'], data: TOPInfo) -> str: ... +async def render(render_type: Literal['v2/tetrio/info'], data: TETRIOInfoV2) -> str: ... @overload -async def render(render_type: Literal['tos/info'], data: TOSInfo) -> str: ... +async def render(render_type: Literal['v1/top/info'], data: TOPInfo) -> str: ... + + +@overload +async def render(render_type: Literal['v1/tos/info'], data: TOSInfo) -> str: ... async def render( - render_type: Literal['binding', 'tetrio/info', 'top/info', 'tos/info'], data: Bind | TETRIOInfo | TOPInfo | TOSInfo + render_type: Literal['v1/binding', 'v1/tetrio/info', 'v2/tetrio/info', 'v1/top/info', 'v1/tos/info'], + data: Bind | TETRIOInfo | TETRIOInfoV2 | TOPInfo | TOSInfo, ) -> str: if PYDANTIC_V2: return await env.get_template('index.html').render_async( diff --git a/nonebot_plugin_tetris_stats/utils/render/schemas/tetrio_info_v2.py b/nonebot_plugin_tetris_stats/utils/render/schemas/tetrio_info_v2.py new file mode 100644 index 0000000..4f7adc6 --- /dev/null +++ b/nonebot_plugin_tetris_stats/utils/render/schemas/tetrio_info_v2.py @@ -0,0 +1,84 @@ +from datetime import datetime + +from pydantic import BaseModel + +from ....games.tetrio.api.typing import Rank +from ...typing import Number +from .base import Avatar + + +class User(BaseModel): + id: str + name: str + country: str | None + + avatar: str | Avatar + banner: str | None + + bio: str | None + + friend_count: int + supporter_tier: int + + verified: bool + bad_standing: bool + + badges: list[str] + xp: Number + + playtime: str + join_at: datetime | None + + +class Statistic(BaseModel): + total: int + wins: int + + +class TetraLeague(BaseModel): + rank: Rank + highest_rank: Rank + + tr: Number + + glicko: Number + rd: Number + + global_rank: int + country_rank: int + + pps: Number + + apm: Number + adpm: Number + + vs: Number + adpl: Number + + statistic: Statistic + + +class Sprint(BaseModel): + time: str + global_rank: int | None + play_at: datetime + + +class Blitz(BaseModel): + score: int + global_rank: int | None + play_at: datetime + + +class Zen(BaseModel): + score: int + level: int + + +class Info(BaseModel): + user: User + tetra_league: TetraLeague | None + statistic: Statistic | None + sprint: Sprint | None + blitz: Blitz | None + zen: Zen