Skip to content

Commit

Permalink
💩 迅速的适配第二赛季
Browse files Browse the repository at this point in the history
  • Loading branch information
shoucandanghehe committed Aug 16, 2024
1 parent 25e281a commit ed6eb9a
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 15 deletions.
11 changes: 8 additions & 3 deletions nonebot_plugin_tetris_stats/games/tetrio/api/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
SoloSuccessModel as SummariesSoloSuccessModel,
)
from .schemas.summaries.base import User as SummariesUser
from .schemas.summaries.league import LeagueSuccessModel
from .schemas.user import User
from .schemas.user_info import UserInfo, UserInfoSuccess
from .typing import Records, Summaries
Expand Down Expand Up @@ -55,6 +56,7 @@ class Player:
'blitz': SummariesSoloSuccessModel,
'zenith': ZenithSuccessModel,
'zenithex': ZenithSuccessModel,
'league': LeagueSuccessModel,
'zen': ZenSuccessModel,
'achievements': AchievementsSuccessModel,
}
Expand Down Expand Up @@ -138,6 +140,8 @@ async def get_summaries(self, summaries_type: Literal['zenith', 'zenithex']) ->
@overload
async def get_summaries(self, summaries_type: Literal['zen']) -> ZenSuccessModel: ...
@overload
async def get_summaries(self, summaries_type: Literal['league']) -> LeagueSuccessModel: ...
@overload
async def get_summaries(self, summaries_type: Literal['achievements']) -> AchievementsSuccessModel: ...

async def get_summaries(self, summaries_type: Summaries) -> SummariesModel:
Expand All @@ -164,20 +168,21 @@ async def get_summaries(self, summaries_type: Summaries) -> SummariesModel:
return self._summaries[summaries_type]

@property
@alru_cache
async def sprint(self) -> SummariesSoloSuccessModel:
return await self.get_summaries('40l')

@property
@alru_cache
async def blitz(self) -> SummariesSoloSuccessModel:
return await self.get_summaries('blitz')

@property
@alru_cache
async def zen(self) -> ZenSuccessModel:
return await self.get_summaries('zen')

@property
async def league(self) -> LeagueSuccessModel:
return await self.get_summaries('league')

async def _get_local_summaries_user(self) -> SummariesUser | None:
allow_summaries: set[Literal['40l', 'blitz', 'zenith', 'zenithex']] = {
'40l',
Expand Down
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
from .achievements import Achievements, AchievementsSuccessModel
from .league import LeagueSuccessModel
from .solo import Solo, SoloSuccessModel
from .zen import Zen, ZenSuccessModel
from .zenith import Zenith, ZenithEx, ZenithSuccessModel

SummariesModel = AchievementsSuccessModel | SoloSuccessModel | ZenSuccessModel | ZenithSuccessModel
SummariesModel = AchievementsSuccessModel | SoloSuccessModel | ZenSuccessModel | LeagueSuccessModel | ZenithSuccessModel

__all__ = [
'Achievements',
'AchievementsSuccessModel',
'LeagueSuccessModel',
'Solo',
'SoloSuccessModel',
'SummariesModel',
'Zen',
'ZenSuccessModel',
'Zenith',
'ZenithEx',
'ZenithSuccessModel',
'SummariesModel',
'ZenSuccessModel',
]
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ class User(BaseModel):
avatar_revision: int | None
banner_revision: int | None
country: str | None
verified: int
verified: int | None = None
supporter: int
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class Data(BaseModel):
badstanding: bool | None = None
supporter: bool | None = None # osk说是必有, 但实际上不是 fkosk
supporter_tier: int
verified: bool
verified: bool | None = None
avatar_revision: int | None = None
"""This user's avatar ID. Get their avatar at
Expand Down
7 changes: 5 additions & 2 deletions nonebot_plugin_tetris_stats/games/tetrio/api/typing.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from typing import Literal

ValidRank = Literal[
S1ValidRank = Literal[
'x+',
'x',
'u',
'ss',
Expand All @@ -19,15 +20,17 @@
'd+',
'd',
]
S1Rank = S1ValidRank | Literal['z']

ValidRank = Literal['x+'] | S1ValidRank
Rank = ValidRank | Literal['z'] # 未定级

Summaries = Literal[
'40l',
'blitz',
'zenith',
'zenithex',
# 'league', # 等待正式赛季开始
'league',
'zen',
'achievements',
]
Expand Down
36 changes: 32 additions & 4 deletions nonebot_plugin_tetris_stats/games/tetrio/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,18 @@

from ...db import query_bind_info, trigger
from ...utils.host import HostPage, get_self_netloc
from ...utils.metrics import get_metrics
from ...utils.render import render
from ...utils.render.schemas.base import Avatar
from ...utils.render.schemas.tetrio.user.info_v2 import Badge, Blitz, Sprint, Statistic, Zen
from ...utils.render.schemas.tetrio.user.info_v2 import (
Badge,
Blitz,
Sprint,
Statistic,
TetraLeague,
TetraLeagueStatistic,
Zen,
)
from ...utils.render.schemas.tetrio.user.info_v2 import Info as V2TemplateInfo
from ...utils.render.schemas.tetrio.user.info_v2 import User as V2TemplateUser
from ...utils.screenshot import screenshot
Expand All @@ -36,6 +45,7 @@

if TYPE_CHECKING:
from .api.schemas.summaries import SoloSuccessModel, ZenSuccessModel
from .api.schemas.summaries.league import LeagueSuccessModel
from .api.schemas.user import User
from .api.schemas.user_info import UserInfoSuccess

Expand Down Expand Up @@ -146,15 +156,17 @@ def handling_special_value(value: N) -> N | None:
async def make_query_image_v2(player: Player) -> bytes:
user: User
user_info: UserInfoSuccess
league: LeagueSuccessModel
sprint: SoloSuccessModel
blitz: SoloSuccessModel
zen: ZenSuccessModel
avatar_revision: int | None
banner_revision: int | None
# TODO)) 有没有什么办法能让这类型推导成功)
user, user_info, sprint, blitz, zen, avatar_revision, banner_revision = await gather( # type: ignore[assignment]
user, user_info, league, sprint, blitz, zen, avatar_revision, banner_revision = await gather( # type: ignore[assignment]
player.user,
player.get_info(),
player.league,
player.sprint,
player.blitz,
player.zen,
Expand Down Expand Up @@ -211,11 +223,27 @@ async def make_query_image_v2(player: Player) -> bytes:
friend_count=user_info.data.friend_count,
supporter_tier=user_info.data.supporter_tier,
bad_standing=user_info.data.badstanding or False,
verified=user_info.data.verified,
verified=user_info.data.verified or False,
playtime=play_time,
join_at=user_info.data.ts,
),
tetra_league=None,
tetra_league=TetraLeague(
rank=league.data.rank,
highest_rank=league.data.bestrank,
tr=round(league.data.tr, 2),
glicko=round(league.data.glicko, 2),
rd=round(league.data.rd, 2),
global_rank=league.data.standing,
country_rank=league.data.standing_local,
pps=(metrics := get_metrics(pps=league.data.pps, apm=league.data.apm, vs=league.data.vs)).pps,
apm=metrics.apm,
apl=metrics.apl,
vs=metrics.vs,
adpl=metrics.adpl,
statistic=TetraLeagueStatistic(total=league.data.gamesplayed, wins=league.data.gameswon),
decaying=league.data.decaying,
history=None,
),
statistic=Statistic(
total=handling_special_value(user_info.data.gamesplayed),
wins=handling_special_value(user_info.data.gameswon),
Expand Down
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = 'nonebot-plugin-tetris-stats'
version = '1.4.8'
version = '1.4.9'
description = '一款基于 NoneBot2 的用于查询 Tetris 相关游戏数据的插件'
authors = ['scdhh <[email protected]>']
readme = 'README.md'
Expand Down

0 comments on commit ed6eb9a

Please sign in to comment.