-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
34c8573
commit aacf518
Showing
9 changed files
with
166 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
from nonebot_plugin_alconna.uniseg import UniMessage | ||
from nonebot_plugin_session import EventSession # type: ignore[import-untyped] | ||
from nonebot_plugin_session_orm import get_session_persist_id # type: ignore[import-untyped] | ||
|
||
from ...db import trigger | ||
from ...utils.host import HostPage, get_self_netloc | ||
from ...utils.metrics import get_metrics | ||
from ...utils.render import render | ||
from ...utils.render.schemas.tetrio.tetrio_user_list_v2 import List, TetraLeague, User | ||
from ...utils.screenshot import screenshot | ||
from .. import alc | ||
from .api.schemas.tetra_league import ValidLeague | ||
from .api.tetra_league import Parameter, leaderboard | ||
from .constant import GAME_TYPE | ||
|
||
|
||
@alc.assign('TETRIO.list') | ||
async def _( | ||
event_session: EventSession, | ||
max_tr: float | None = None, | ||
min_tr: float | None = None, | ||
limit: int | None = None, | ||
country: str | None = None, | ||
): | ||
async with trigger( | ||
session_persist_id=await get_session_persist_id(event_session), | ||
game_platform=GAME_TYPE, | ||
command_type='list', | ||
command_args=[], | ||
): | ||
parameter: Parameter = {} | ||
if max_tr is not None: | ||
parameter['after'] = max_tr | ||
if min_tr is not None: | ||
parameter['before'] = min_tr | ||
if limit is not None: | ||
parameter['limit'] = limit | ||
if country is not None: | ||
parameter['country'] = country | ||
league = await leaderboard(parameter) | ||
async with HostPage( | ||
await render( | ||
'v2/tetrio/user/list', | ||
List( | ||
show_index=True, | ||
users=[ | ||
User( | ||
id=i.id, | ||
name=i.username.upper(), | ||
avatar=f'https://tetr.io/user-content/avatars/{i.id}.jpg', | ||
country=i.country, | ||
verified=i.verified, | ||
tetra_league=TetraLeague( | ||
rank=i.league.rank, | ||
tr=round(i.league.rating, 2), | ||
glicko=round(i.league.glicko, 2), | ||
rd=round(i.league.rd, 2), | ||
decaying=i.league.decaying, | ||
pps=(metrics := get_metrics(pps=i.league.pps, apm=i.league.apm, vs=i.league.vs)).pps, | ||
apm=metrics.apm, | ||
apl=metrics.apl, | ||
vs=metrics.vs, | ||
adpl=metrics.adpl, | ||
), | ||
xp=i.xp, | ||
join_at=None, | ||
) | ||
for i in league.data.users | ||
if isinstance(i.league, ValidLeague) | ||
], | ||
), | ||
) | ||
) as page_hash: | ||
await UniMessage.image(raw=await screenshot(f'http://{get_self_netloc()}/host/{page_hash}.html')).finish() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
nonebot_plugin_tetris_stats/utils/render/schemas/tetrio/tetrio_user_list_v2.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
from datetime import datetime | ||
|
||
from pydantic import BaseModel | ||
|
||
from .....games.tetrio.api.typing import Rank | ||
from ....typing import Number | ||
from ..base import Avatar | ||
|
||
|
||
class TetraLeague(BaseModel): | ||
rank: Rank | ||
tr: Number | ||
|
||
glicko: Number | None | ||
rd: Number | None | ||
decaying: bool | ||
pps: Number | ||
apm: Number | ||
apl: Number | ||
vs: Number | None | ||
adpl: Number | None | ||
|
||
|
||
class User(BaseModel): | ||
id: str | ||
name: str | ||
avatar: str | Avatar | ||
country: str | None | ||
verified: bool | ||
tetra_league: TetraLeague | ||
xp: Number | ||
join_at: datetime | None | ||
|
||
|
||
class List(BaseModel): | ||
show_index: bool | ||
users: list[User] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters