mirror of
https://github.com/A-Minos/nonebot-plugin-tetris-stats.git
synced 2026-03-05 05:36:54 +08:00
✨ 适配 v2 模板
This commit is contained in:
@@ -41,7 +41,7 @@ async def _(bot: Bot, event: Event, account: Player, event_session: EventSession
|
|||||||
if bind_status in (BindStatus.SUCCESS, BindStatus.UPDATE):
|
if bind_status in (BindStatus.SUCCESS, BindStatus.UPDATE):
|
||||||
async with HostPage(
|
async with HostPage(
|
||||||
await render(
|
await render(
|
||||||
'binding',
|
'v1/binding',
|
||||||
Bind(
|
Bind(
|
||||||
platform='TETR.IO',
|
platform='TETR.IO',
|
||||||
status='unknown',
|
status='unknown',
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ async def make_query_image(
|
|||||||
blitz_value = f'{blitz.endcontext.score:,}' if blitz is not None else 'N/A'
|
blitz_value = f'{blitz.endcontext.score:,}' if blitz is not None else 'N/A'
|
||||||
async with HostPage(
|
async with HostPage(
|
||||||
await render(
|
await render(
|
||||||
'tetrio/info',
|
'v1/tetrio/info',
|
||||||
Info(
|
Info(
|
||||||
user=TemplateUser(
|
user=TemplateUser(
|
||||||
avatar=f'https://tetr.io/user-content/avatars/{user_info.data.user.id}.jpg?rv={user_info.data.user.avatar_revision}'
|
avatar=f'https://tetr.io/user-content/avatars/{user_info.data.user.id}.jpg?rv={user_info.data.user.avatar_revision}'
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ async def _(
|
|||||||
if bind_status in (BindStatus.SUCCESS, BindStatus.UPDATE):
|
if bind_status in (BindStatus.SUCCESS, BindStatus.UPDATE):
|
||||||
async with HostPage(
|
async with HostPage(
|
||||||
await render(
|
await render(
|
||||||
'binding',
|
'v1/binding',
|
||||||
Bind(
|
Bind(
|
||||||
platform=GAME_TYPE,
|
platform=GAME_TYPE,
|
||||||
status='unknown',
|
status='unknown',
|
||||||
|
|||||||
@@ -46,7 +46,7 @@ async def _(
|
|||||||
if bind_status in (BindStatus.SUCCESS, BindStatus.UPDATE):
|
if bind_status in (BindStatus.SUCCESS, BindStatus.UPDATE):
|
||||||
async with HostPage(
|
async with HostPage(
|
||||||
await render(
|
await render(
|
||||||
'binding',
|
'v1/binding',
|
||||||
Bind(
|
Bind(
|
||||||
platform=GAME_TYPE,
|
platform=GAME_TYPE,
|
||||||
status='unknown',
|
status='unknown',
|
||||||
|
|||||||
@@ -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
|
sprint_value = f'{duration:.3f}s' if duration < 60 else f'{duration // 60:.0f}m {duration % 60:.3f}s' # noqa: PLR2004
|
||||||
async with HostPage(
|
async with HostPage(
|
||||||
await render(
|
await render(
|
||||||
'tos/info',
|
'v1/tos/info',
|
||||||
Info(
|
Info(
|
||||||
user=People(avatar=await get_avatar(event_user_info, 'Data URI', None), name=user_info.data.name),
|
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)),
|
ranking=Ranking(rating=float(user_info.data.ranking), rd=round(float(user_info.data.rd_now), 2)),
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ from nonebot.compat import PYDANTIC_V2
|
|||||||
from ..templates import templates_dir
|
from ..templates import templates_dir
|
||||||
from .schemas.bind import Bind
|
from .schemas.bind import Bind
|
||||||
from .schemas.tetrio_info import Info as TETRIOInfo
|
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.top_info import Info as TOPInfo
|
||||||
from .schemas.tos_info import Info as TOSInfo
|
from .schemas.tos_info import Info as TOSInfo
|
||||||
|
|
||||||
@@ -15,23 +16,28 @@ env = Environment(
|
|||||||
|
|
||||||
|
|
||||||
@overload
|
@overload
|
||||||
async def render(render_type: Literal['binding'], data: Bind) -> str: ...
|
async def render(render_type: Literal['v1/binding'], data: Bind) -> str: ...
|
||||||
|
|
||||||
|
|
||||||
@overload
|
@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
|
@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
|
@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(
|
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:
|
) -> str:
|
||||||
if PYDANTIC_V2:
|
if PYDANTIC_V2:
|
||||||
return await env.get_template('index.html').render_async(
|
return await env.get_template('index.html').render_async(
|
||||||
|
|||||||
@@ -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
|
||||||
Reference in New Issue
Block a user