diff --git a/nonebot_plugin_tetris_stats/games/tetrio/api/player.py b/nonebot_plugin_tetris_stats/games/tetrio/api/player.py index 892e0c42..49476f20 100644 --- a/nonebot_plugin_tetris_stats/games/tetrio/api/player.py +++ b/nonebot_plugin_tetris_stats/games/tetrio/api/player.py @@ -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 @@ -55,6 +56,7 @@ class Player: 'blitz': SummariesSoloSuccessModel, 'zenith': ZenithSuccessModel, 'zenithex': ZenithSuccessModel, + 'league': LeagueSuccessModel, 'zen': ZenSuccessModel, 'achievements': AchievementsSuccessModel, } @@ -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: @@ -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', diff --git a/nonebot_plugin_tetris_stats/games/tetrio/api/schemas/summaries/__init__.py b/nonebot_plugin_tetris_stats/games/tetrio/api/schemas/summaries/__init__.py index 1f05cec7..8a8f1002 100644 --- a/nonebot_plugin_tetris_stats/games/tetrio/api/schemas/summaries/__init__.py +++ b/nonebot_plugin_tetris_stats/games/tetrio/api/schemas/summaries/__init__.py @@ -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', ] diff --git a/nonebot_plugin_tetris_stats/games/tetrio/api/schemas/summaries/base.py b/nonebot_plugin_tetris_stats/games/tetrio/api/schemas/summaries/base.py index 5aed764a..1548cfe7 100644 --- a/nonebot_plugin_tetris_stats/games/tetrio/api/schemas/summaries/base.py +++ b/nonebot_plugin_tetris_stats/games/tetrio/api/schemas/summaries/base.py @@ -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 diff --git a/nonebot_plugin_tetris_stats/games/tetrio/api/schemas/user_info.py b/nonebot_plugin_tetris_stats/games/tetrio/api/schemas/user_info.py index 2b0563e7..d6b7764f 100644 --- a/nonebot_plugin_tetris_stats/games/tetrio/api/schemas/user_info.py +++ b/nonebot_plugin_tetris_stats/games/tetrio/api/schemas/user_info.py @@ -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 diff --git a/nonebot_plugin_tetris_stats/games/tetrio/api/typing.py b/nonebot_plugin_tetris_stats/games/tetrio/api/typing.py index 23cdc3b9..bb53b4ef 100644 --- a/nonebot_plugin_tetris_stats/games/tetrio/api/typing.py +++ b/nonebot_plugin_tetris_stats/games/tetrio/api/typing.py @@ -1,6 +1,7 @@ from typing import Literal -ValidRank = Literal[ +S1ValidRank = Literal[ + 'x+', 'x', 'u', 'ss', @@ -19,7 +20,9 @@ 'd+', 'd', ] +S1Rank = S1ValidRank | Literal['z'] +ValidRank = Literal['x+'] | S1ValidRank Rank = ValidRank | Literal['z'] # 未定级 Summaries = Literal[ @@ -27,7 +30,7 @@ 'blitz', 'zenith', 'zenithex', - # 'league', # 等待正式赛季开始 + 'league', 'zen', 'achievements', ] diff --git a/nonebot_plugin_tetris_stats/games/tetrio/query.py b/nonebot_plugin_tetris_stats/games/tetrio/query.py index be87796c..b25f2e2c 100644 --- a/nonebot_plugin_tetris_stats/games/tetrio/query.py +++ b/nonebot_plugin_tetris_stats/games/tetrio/query.py @@ -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 @@ -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 @@ -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, @@ -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), diff --git a/pyproject.toml b/pyproject.toml index 0622862d..1d09542e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = 'nonebot-plugin-tetris-stats' -version = '1.4.8' +version = '1.4.9' description = '一款基于 NoneBot2 的用于查询 Tetris 相关游戏数据的插件' authors = ['scdhh '] readme = 'README.md'