mirror of
https://github.com/A-Minos/nonebot-plugin-tetris-stats.git
synced 2026-03-05 05:36:54 +08:00
Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 41bbcdb66c | |||
| 160d81476a | |||
| 1e5b00a280 | |||
| ee53b92559 | |||
| cd9d29b748 | |||
| 214ebc5073 | |||
| 485706267e | |||
| 12cb5193b3 | |||
|
|
461d3450d6 | ||
|
|
64d77dbff2 | ||
|
|
e5b4d3bc08 | ||
|
|
4208018caf | ||
|
|
5032a3eb9a | ||
|
|
bf9a9953dd | ||
|
|
85feb9cb41 | ||
| 5a7c54528c | |||
| afce74afe8 |
@@ -1,6 +1,6 @@
|
||||
from pathlib import Path
|
||||
|
||||
from nonebot_plugin_localstore import get_cache_dir # type: ignore[import-untyped]
|
||||
from nonebot_plugin_localstore import get_cache_dir
|
||||
from pydantic import BaseModel
|
||||
|
||||
CACHE_PATH: Path = get_cache_dir('nonebot_plugin_tetris_stats')
|
||||
|
||||
@@ -8,7 +8,7 @@ from typing import TYPE_CHECKING, Literal, TypeVar, overload
|
||||
from nonebot.exception import FinishedException
|
||||
from nonebot.log import logger
|
||||
from nonebot_plugin_orm import AsyncSession, get_session
|
||||
from nonebot_plugin_user import User # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import User
|
||||
from sqlalchemy import select
|
||||
|
||||
from ..utils.typing import AllCommandType, BaseCommandType, GameType, TETRIOCommandType
|
||||
|
||||
@@ -1,16 +1,10 @@
|
||||
from arclet.alconna import Arg, ArgFlag, Args, Option, Subcommand
|
||||
from nonebot_plugin_alconna import At
|
||||
from nonebot_plugin_alconna import Subcommand
|
||||
|
||||
from ...utils.exception import MessageFormatError
|
||||
from ...utils.typing import Me
|
||||
|
||||
# from .. import add_block_handlers, alc, command
|
||||
from .. import alc, command
|
||||
from .. import alc
|
||||
from .. import command as main_command
|
||||
from .api import Player
|
||||
|
||||
# from .api.typing import ValidRank
|
||||
from .constant import USER_ID, USER_NAME
|
||||
from .typing import Template
|
||||
|
||||
|
||||
def get_player(user_id_or_name: str) -> Player | MessageFormatError:
|
||||
@@ -21,171 +15,22 @@ def get_player(user_id_or_name: str) -> Player | MessageFormatError:
|
||||
return MessageFormatError('用户名/ID不合法')
|
||||
|
||||
|
||||
command.add(
|
||||
Subcommand(
|
||||
'TETR.IO',
|
||||
Subcommand(
|
||||
'bind',
|
||||
Args(
|
||||
Arg(
|
||||
'account',
|
||||
get_player,
|
||||
notice='TETR.IO 用户名 / ID',
|
||||
flags=[ArgFlag.HIDDEN],
|
||||
)
|
||||
),
|
||||
help_text='绑定 TETR.IO 账号',
|
||||
),
|
||||
# Subcommand(
|
||||
# 'query',
|
||||
# Args(
|
||||
# Arg(
|
||||
# 'target',
|
||||
# At | Me,
|
||||
# notice='@想要查询的人 / 自己',
|
||||
# flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL],
|
||||
# ),
|
||||
# Arg(
|
||||
# 'account',
|
||||
# get_player,
|
||||
# notice='TETR.IO 用户名 / ID',
|
||||
# flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL],
|
||||
# ),
|
||||
# ),
|
||||
# Option(
|
||||
# '--template',
|
||||
# Arg('template', Template),
|
||||
# alias=['-T'],
|
||||
# help_text='要使用的查询模板',
|
||||
# ),
|
||||
# help_text='查询 TETR.IO 游戏信息',
|
||||
# ),
|
||||
Subcommand(
|
||||
'record',
|
||||
Option(
|
||||
'--40l',
|
||||
dest='sprint',
|
||||
),
|
||||
Option(
|
||||
'--blitz',
|
||||
dest='blitz',
|
||||
),
|
||||
Args(
|
||||
Arg(
|
||||
'target',
|
||||
At | Me,
|
||||
notice='@想要查询的人 / 自己',
|
||||
flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL],
|
||||
),
|
||||
Arg(
|
||||
'account',
|
||||
get_player,
|
||||
notice='TETR.IO 用户名 / ID',
|
||||
flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL],
|
||||
),
|
||||
),
|
||||
),
|
||||
# Subcommand(
|
||||
# 'list',
|
||||
# Option('--max-tr', Arg('max_tr', float), help_text='TR的上限'),
|
||||
# Option('--min-tr', Arg('min_tr', float), help_text='TR的下限'),
|
||||
# Option('--limit', Arg('limit', int), help_text='查询数量'),
|
||||
# Option('--country', Arg('country', str), help_text='国家代码'),
|
||||
# help_text='查询 TETR.IO 段位排行榜',
|
||||
# ),
|
||||
# Subcommand(
|
||||
# 'rank',
|
||||
# Subcommand(
|
||||
# '--all',
|
||||
# Option(
|
||||
# '--template',
|
||||
# Arg('template', Template),
|
||||
# alias=['-T'],
|
||||
# help_text='要使用的查询模板',
|
||||
# ),
|
||||
# dest='all',
|
||||
# ),
|
||||
# Option(
|
||||
# '--detail',
|
||||
# Arg('rank', ValidRank),
|
||||
# alias=['-D'],
|
||||
# ),
|
||||
# help_text='查询 TETR.IO 段位信息',
|
||||
# ),
|
||||
Subcommand(
|
||||
'config',
|
||||
Option(
|
||||
'--default-template',
|
||||
Arg('template', Template),
|
||||
alias=['-DT', 'DefaultTemplate'],
|
||||
),
|
||||
),
|
||||
alias=['TETRIO', 'tetr.io', 'tetrio', 'io'],
|
||||
dest='TETRIO',
|
||||
help_text='TETR.IO 游戏相关指令',
|
||||
)
|
||||
command = Subcommand(
|
||||
'TETR.IO',
|
||||
alias=['TETRIO', 'tetr.io', 'tetrio', 'io'],
|
||||
dest='TETRIO',
|
||||
help_text='TETR.IO 游戏相关指令',
|
||||
)
|
||||
|
||||
|
||||
# def rank_wrapper(slot: int | str, content: str | None):
|
||||
# if slot == 'rank' and not content:
|
||||
# return '--all'
|
||||
# if content is not None:
|
||||
# return f'--detail {content.lower()}'
|
||||
# return content
|
||||
from . import bind, config, query, record # noqa: E402
|
||||
|
||||
|
||||
alc.shortcut(
|
||||
'(?i:io)(?i:绑定|绑|bind)',
|
||||
command='tstats TETR.IO bind',
|
||||
humanized='io绑定',
|
||||
)
|
||||
# alc.shortcut(
|
||||
# '(?i:io)(?i:查询|查|query|stats)',
|
||||
# command='tstats TETR.IO query',
|
||||
# humanized='io查',
|
||||
# )
|
||||
alc.shortcut(
|
||||
'(?i:io)(?i:记录|record)(?i:40l)',
|
||||
command='tstats TETR.IO record --40l',
|
||||
humanized='io记录40l',
|
||||
)
|
||||
alc.shortcut(
|
||||
'(?i:io)(?i:记录|record)(?i:blitz)',
|
||||
command='tstats TETR.IO record --blitz',
|
||||
humanized='io记录blitz',
|
||||
)
|
||||
# alc.shortcut(
|
||||
# r'(?i:io)(?i:段位|段|rank)\s*(?P<rank>[a-zA-Z+-]{0,2})',
|
||||
# command='tstats TETR.IO rank {rank}',
|
||||
# humanized='iorank',
|
||||
# fuzzy=False,
|
||||
# wrapper=rank_wrapper,
|
||||
# )
|
||||
alc.shortcut(
|
||||
'(?i:io)(?i:配置|配|config)',
|
||||
command='tstats TETR.IO config',
|
||||
humanized='io配置',
|
||||
)
|
||||
|
||||
# alc.shortcut(
|
||||
# 'fkosk',
|
||||
# command='tstats TETR.IO query',
|
||||
# arguments=['我'],
|
||||
# fuzzy=False,
|
||||
# humanized='An Easter egg!',
|
||||
# )
|
||||
|
||||
# add_block_handlers(alc.assign('TETRIO.query'))
|
||||
|
||||
# from . import bind, config, list, query, rank, record
|
||||
from . import bind, config, record # noqa: E402
|
||||
main_command.add(command)
|
||||
|
||||
__all__ = [
|
||||
'alc',
|
||||
'bind',
|
||||
'config',
|
||||
# 'list',
|
||||
# 'query',
|
||||
# 'rank',
|
||||
'query',
|
||||
'record',
|
||||
]
|
||||
|
||||
@@ -39,13 +39,13 @@ class Garbage(BaseModel):
|
||||
|
||||
|
||||
class Stats(BaseModel):
|
||||
seed: int
|
||||
seed: int | None = None # ?: 不知道是之后都没有了还是还会有
|
||||
lines: int
|
||||
level_lines: int
|
||||
level_lines_needed: int
|
||||
inputs: int
|
||||
holds: int
|
||||
time: Time
|
||||
time: Time | None = None # ?: 不知道是之后都没有了还是还会有
|
||||
score: int
|
||||
zenlevel: int
|
||||
zenprogress: int
|
||||
|
||||
@@ -1,13 +1,15 @@
|
||||
from asyncio import gather
|
||||
from hashlib import md5
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from arclet.alconna import Arg, ArgFlag
|
||||
from nepattern import parser # type: ignore[import-untyped]
|
||||
from nonebot_plugin_alconna import Args, Subcommand
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage
|
||||
from nonebot_plugin_orm import get_session
|
||||
from nonebot_plugin_session import EventSession # type: ignore[import-untyped]
|
||||
from nonebot_plugin_session import EventSession
|
||||
from nonebot_plugin_session_orm import get_session_persist_id # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import User # type: ignore[import-untyped]
|
||||
from nonebot_plugin_userinfo import BotUserInfo, UserInfo # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import User
|
||||
from nonebot_plugin_userinfo import BotUserInfo, UserInfo
|
||||
|
||||
from ...db import BindStatus, create_or_update_bind, trigger
|
||||
from ...utils.host import HostPage, get_self_netloc
|
||||
@@ -15,10 +17,31 @@ from ...utils.image import get_avatar
|
||||
from ...utils.render import Bind, render
|
||||
from ...utils.render.schemas.base import Avatar, People
|
||||
from ...utils.screenshot import screenshot
|
||||
from . import alc
|
||||
from . import alc, command, get_player
|
||||
from .api import Player
|
||||
from .constant import GAME_TYPE
|
||||
|
||||
command.add(
|
||||
Subcommand(
|
||||
'bind',
|
||||
Args(
|
||||
Arg(
|
||||
'account',
|
||||
parser(get_player),
|
||||
notice='TETR.IO 用户名 / ID',
|
||||
flags=[ArgFlag.HIDDEN],
|
||||
)
|
||||
),
|
||||
help_text='绑定 TETR.IO 账号',
|
||||
)
|
||||
)
|
||||
|
||||
alc.shortcut(
|
||||
'(?i:io)(?i:绑定|绑|bind)',
|
||||
command='tstats TETR.IO bind',
|
||||
humanized='io绑定',
|
||||
)
|
||||
|
||||
|
||||
@alc.assign('TETRIO.bind')
|
||||
async def _(nb_user: User, account: Player, event_session: EventSession, bot_info: UserInfo = BotUserInfo()): # noqa: B008
|
||||
@@ -28,7 +51,7 @@ async def _(nb_user: User, account: Player, event_session: EventSession, bot_inf
|
||||
command_type='bind',
|
||||
command_args=[],
|
||||
):
|
||||
user, user_info = await gather(account.user, account.get_info())
|
||||
user = await account.user
|
||||
async with get_session() as session:
|
||||
bind_status = await create_or_update_bind(
|
||||
session=session,
|
||||
|
||||
@@ -1,16 +1,38 @@
|
||||
from arclet.alconna import Arg
|
||||
from nepattern import parser # type: ignore[import-untyped]
|
||||
from nonebot_plugin_alconna import Option, Subcommand
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage
|
||||
from nonebot_plugin_orm import async_scoped_session
|
||||
from nonebot_plugin_session import EventSession # type: ignore[import-untyped]
|
||||
from nonebot_plugin_session import EventSession
|
||||
from nonebot_plugin_session_orm import get_session_persist_id # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import User # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import User
|
||||
from sqlalchemy import select
|
||||
|
||||
from ...db import trigger
|
||||
from . import alc
|
||||
from . import alc, command
|
||||
from .constant import GAME_TYPE
|
||||
from .models import TETRIOUserConfig
|
||||
from .typing import Template
|
||||
|
||||
command.add(
|
||||
Subcommand(
|
||||
'config',
|
||||
Option(
|
||||
'--default-template',
|
||||
Arg('template', parser(Template), notice='模板版本'),
|
||||
alias=['-DT', 'DefaultTemplate'],
|
||||
help_text='设置默认查询模板',
|
||||
),
|
||||
help_text='TETR.IO 查询个性化配置',
|
||||
),
|
||||
)
|
||||
|
||||
alc.shortcut(
|
||||
'(?i:io)(?i:配置|配|config)',
|
||||
command='tstats TETR.IO config',
|
||||
humanized='io配置',
|
||||
)
|
||||
|
||||
|
||||
@alc.assign('TETRIO.config')
|
||||
async def _(user: User, session: async_scoped_session, event_session: EventSession, template: Template):
|
||||
|
||||
242
nonebot_plugin_tetris_stats/games/tetrio/query.py
Normal file
242
nonebot_plugin_tetris_stats/games/tetrio/query.py
Normal file
@@ -0,0 +1,242 @@
|
||||
from asyncio import gather
|
||||
from datetime import datetime, timedelta, timezone
|
||||
from hashlib import md5
|
||||
from typing import TYPE_CHECKING, TypeVar
|
||||
from urllib.parse import urlencode
|
||||
|
||||
from arclet.alconna import Arg, ArgFlag
|
||||
from nepattern import parser # type: ignore[import-untyped]
|
||||
from nonebot import get_driver
|
||||
from nonebot.adapters import Event
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot_plugin_alconna import Args, At, Option, Subcommand
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage
|
||||
from nonebot_plugin_orm import get_session
|
||||
from nonebot_plugin_session import EventSession
|
||||
from nonebot_plugin_session_orm import get_session_persist_id # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import User as NBUser
|
||||
from nonebot_plugin_user import get_user
|
||||
from sqlalchemy import select
|
||||
|
||||
from ...db import query_bind_info, trigger
|
||||
from ...utils.host import HostPage, get_self_netloc
|
||||
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 Info as V2TemplateInfo
|
||||
from ...utils.render.schemas.tetrio.user.info_v2 import User as V2TemplateUser
|
||||
from ...utils.screenshot import screenshot
|
||||
from ...utils.typing import Me
|
||||
from .. import add_block_handlers, alc
|
||||
from ..constant import CANT_VERIFY_MESSAGE
|
||||
from . import command, get_player
|
||||
from .api import Player
|
||||
from .constant import GAME_TYPE
|
||||
from .models import TETRIOUserConfig
|
||||
from .typing import Template
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from .api.schemas.summaries import SoloSuccessModel, ZenSuccessModel
|
||||
from .api.schemas.user import User
|
||||
from .api.schemas.user_info import UserInfoSuccess
|
||||
|
||||
UTC = timezone.utc
|
||||
|
||||
driver = get_driver()
|
||||
|
||||
command.add(
|
||||
Subcommand(
|
||||
'query',
|
||||
Args(
|
||||
Arg(
|
||||
'target',
|
||||
parser(At | Me),
|
||||
notice='@想要查询的人 / 自己',
|
||||
flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL],
|
||||
),
|
||||
Arg(
|
||||
'account',
|
||||
parser(get_player),
|
||||
notice='TETR.IO 用户名 / ID',
|
||||
flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL],
|
||||
),
|
||||
),
|
||||
Option(
|
||||
'--template',
|
||||
Arg('template', parser(Template)),
|
||||
alias=['-T'],
|
||||
help_text='要使用的查询模板',
|
||||
),
|
||||
help_text='查询 TETR.IO 游戏信息',
|
||||
),
|
||||
)
|
||||
|
||||
alc.shortcut(
|
||||
'(?i:io)(?i:查询|查|query|stats)',
|
||||
command='tstats TETR.IO query',
|
||||
humanized='io查',
|
||||
)
|
||||
alc.shortcut(
|
||||
'fkosk',
|
||||
command='tstats TETR.IO query',
|
||||
arguments=['我'],
|
||||
fuzzy=False,
|
||||
humanized='An Easter egg!',
|
||||
)
|
||||
|
||||
add_block_handlers(alc.assign('TETRIO.query'))
|
||||
|
||||
|
||||
@alc.assign('TETRIO.query')
|
||||
async def _( # noqa: PLR0913
|
||||
user: NBUser,
|
||||
event: Event,
|
||||
matcher: Matcher,
|
||||
target: At | Me,
|
||||
event_session: EventSession,
|
||||
template: Template | None = None,
|
||||
):
|
||||
async with trigger(
|
||||
session_persist_id=await get_session_persist_id(event_session),
|
||||
game_platform=GAME_TYPE,
|
||||
command_type='query',
|
||||
command_args=[f'--default-template {template}'] if template is not None else [],
|
||||
):
|
||||
async with get_session() as session:
|
||||
bind = await query_bind_info(
|
||||
session=session,
|
||||
user=await get_user(
|
||||
event_session.platform, target.target if isinstance(target, At) else event.get_user_id()
|
||||
),
|
||||
game_platform=GAME_TYPE,
|
||||
)
|
||||
if template is None:
|
||||
template = await session.scalar(
|
||||
select(TETRIOUserConfig.query_template).where(TETRIOUserConfig.id == user.id)
|
||||
)
|
||||
if bind is None:
|
||||
await matcher.finish('未查询到绑定信息')
|
||||
message = UniMessage(CANT_VERIFY_MESSAGE)
|
||||
player = Player(user_id=bind.game_account, trust=True)
|
||||
await (message + UniMessage.image(raw=await make_query_image_v2(player))).finish()
|
||||
|
||||
|
||||
@alc.assign('TETRIO.query')
|
||||
async def _(user: NBUser, account: Player, event_session: EventSession, template: Template | None = None):
|
||||
async with trigger(
|
||||
session_persist_id=await get_session_persist_id(event_session),
|
||||
game_platform=GAME_TYPE,
|
||||
command_type='query',
|
||||
command_args=[f'--default-template {template}'] if template is not None else [],
|
||||
):
|
||||
async with get_session() as session:
|
||||
if template is None:
|
||||
template = await session.scalar(
|
||||
select(TETRIOUserConfig.query_template).where(TETRIOUserConfig.id == user.id)
|
||||
)
|
||||
await (UniMessage.image(raw=await make_query_image_v2(account))).finish()
|
||||
|
||||
|
||||
N = TypeVar('N', int, float)
|
||||
|
||||
|
||||
def handling_special_value(value: N) -> N | None:
|
||||
return value if value != -1 else None
|
||||
|
||||
|
||||
async def make_query_image_v2(player: Player) -> bytes:
|
||||
user: User
|
||||
user_info: UserInfoSuccess
|
||||
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]
|
||||
player.user,
|
||||
player.get_info(),
|
||||
player.sprint,
|
||||
player.blitz,
|
||||
player.zen,
|
||||
player.avatar_revision,
|
||||
player.banner_revision,
|
||||
)
|
||||
|
||||
if sprint.data.record is not None:
|
||||
duration = timedelta(milliseconds=sprint.data.record.results.stats.finaltime).total_seconds()
|
||||
sprint_value = f'{duration:.3f}s' if duration < 60 else f'{duration // 60:.0f}m {duration % 60:.3f}s' # noqa: PLR2004
|
||||
else:
|
||||
sprint_value = 'N/A'
|
||||
|
||||
play_time: str | None
|
||||
if (game_time := handling_special_value(user_info.data.gametime)) is not None:
|
||||
if game_time // 3600 > 0:
|
||||
play_time = f'{game_time//3600:.0f}h {game_time % 3600 // 60:.0f}m {game_time % 60:.0f}s'
|
||||
elif game_time // 60 > 0:
|
||||
play_time = f'{game_time//60:.0f}m {game_time % 60:.0f}s'
|
||||
else:
|
||||
play_time = f'{game_time:.0f}s'
|
||||
else:
|
||||
play_time = game_time
|
||||
netloc = get_self_netloc()
|
||||
async with HostPage(
|
||||
await render(
|
||||
'v2/tetrio/user/info',
|
||||
V2TemplateInfo(
|
||||
user=V2TemplateUser(
|
||||
id=user.ID,
|
||||
name=user.name.upper(),
|
||||
bio=user_info.data.bio,
|
||||
banner=f'http://{netloc}/host/resource/tetrio/banners/{user.ID}?{urlencode({"revision": banner_revision})}'
|
||||
if banner_revision is not None and banner_revision != 0
|
||||
else None,
|
||||
avatar=f'http://{netloc}/host/resource/tetrio/avatars/{user.ID}?{urlencode({"revision": avatar_revision})}'
|
||||
if avatar_revision is not None and avatar_revision != 0
|
||||
else Avatar(
|
||||
type='identicon',
|
||||
hash=md5(user.ID.encode()).hexdigest(), # noqa: S324
|
||||
),
|
||||
badges=[
|
||||
Badge(
|
||||
id=i.id,
|
||||
description=i.label,
|
||||
group=i.group,
|
||||
receive_at=i.ts if isinstance(i.ts, datetime) else None,
|
||||
)
|
||||
for i in user_info.data.badges
|
||||
],
|
||||
country=user_info.data.country,
|
||||
role=user_info.data.role,
|
||||
xp=user_info.data.xp,
|
||||
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,
|
||||
playtime=play_time,
|
||||
join_at=user_info.data.ts,
|
||||
),
|
||||
tetra_league=None,
|
||||
statistic=Statistic(
|
||||
total=handling_special_value(user_info.data.gamesplayed),
|
||||
wins=handling_special_value(user_info.data.gameswon),
|
||||
),
|
||||
sprint=Sprint(
|
||||
time=sprint_value,
|
||||
global_rank=sprint.data.rank,
|
||||
play_at=sprint.data.record.ts,
|
||||
)
|
||||
if sprint.data.record is not None
|
||||
else None,
|
||||
blitz=Blitz(
|
||||
score=blitz.data.record.results.stats.score,
|
||||
global_rank=blitz.data.rank,
|
||||
play_at=blitz.data.record.ts,
|
||||
)
|
||||
if blitz.data.record is not None
|
||||
else None,
|
||||
zen=Zen(level=zen.data.level, score=zen.data.score),
|
||||
),
|
||||
),
|
||||
) as page_hash:
|
||||
return await screenshot(f'http://{netloc}/host/{page_hash}.html')
|
||||
@@ -1,4 +1,31 @@
|
||||
from . import blitz, sprint
|
||||
from arclet.alconna import Arg, ArgFlag
|
||||
from nonebot_plugin_alconna import Args, At, Subcommand
|
||||
|
||||
from ....utils.typing import Me
|
||||
from .. import command as base_command
|
||||
from .. import get_player
|
||||
|
||||
command = Subcommand(
|
||||
'record',
|
||||
Args(
|
||||
Arg(
|
||||
'target',
|
||||
At | Me,
|
||||
notice='@想要查询的人 / 自己',
|
||||
flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL],
|
||||
),
|
||||
Arg(
|
||||
'account',
|
||||
get_player,
|
||||
notice='TETR.IO 用户名 / ID',
|
||||
flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL],
|
||||
),
|
||||
),
|
||||
)
|
||||
|
||||
from . import blitz, sprint # noqa: E402
|
||||
|
||||
base_command.add(command)
|
||||
|
||||
__all__ = [
|
||||
'blitz',
|
||||
|
||||
@@ -5,12 +5,12 @@ from urllib.parse import urlencode
|
||||
|
||||
from nonebot.adapters import Event
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot_plugin_alconna import At
|
||||
from nonebot_plugin_alconna import At, Option
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage
|
||||
from nonebot_plugin_orm import get_session
|
||||
from nonebot_plugin_session import EventSession # type: ignore[import-untyped]
|
||||
from nonebot_plugin_session import EventSession
|
||||
from nonebot_plugin_session_orm import get_session_persist_id # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import get_user # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import get_user
|
||||
|
||||
from ....db import query_bind_info, trigger
|
||||
from ....utils.exception import RecordNotFoundError
|
||||
@@ -18,14 +18,23 @@ 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.tetrio_record_base import Finesse, Max, Mini, Tspins, User
|
||||
from ....utils.render.schemas.tetrio.tetrio_record_blitz import Record, Statistic
|
||||
from ....utils.render.schemas.tetrio.record.base import Finesse, Max, Mini, Tspins, User
|
||||
from ....utils.render.schemas.tetrio.record.blitz import Record, Statistic
|
||||
from ....utils.screenshot import screenshot
|
||||
from ....utils.typing import Me
|
||||
from ...constant import CANT_VERIFY_MESSAGE
|
||||
from .. import alc
|
||||
from ..api.player import Player
|
||||
from ..constant import GAME_TYPE
|
||||
from . import command
|
||||
|
||||
command.add(Option('--blitz', dest='blitz'))
|
||||
|
||||
alc.shortcut(
|
||||
'(?i:io)(?i:记录|record)(?i:blitz)',
|
||||
command='tstats TETR.IO record --blitz',
|
||||
humanized='io记录blitz',
|
||||
)
|
||||
|
||||
|
||||
@alc.assign('TETRIO.record.blitz')
|
||||
@@ -81,7 +90,7 @@ async def make_blitz_image(player: Player) -> bytes:
|
||||
page=await render(
|
||||
'v2/tetrio/record/blitz',
|
||||
Record(
|
||||
type='personal_best',
|
||||
type='best',
|
||||
user=User(
|
||||
id=user.ID,
|
||||
name=user.name.upper(),
|
||||
|
||||
@@ -5,12 +5,12 @@ from urllib.parse import urlencode
|
||||
|
||||
from nonebot.adapters import Event
|
||||
from nonebot.matcher import Matcher
|
||||
from nonebot_plugin_alconna import At
|
||||
from nonebot_plugin_alconna import At, Option
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage
|
||||
from nonebot_plugin_orm import get_session
|
||||
from nonebot_plugin_session import EventSession # type: ignore[import-untyped]
|
||||
from nonebot_plugin_session import EventSession
|
||||
from nonebot_plugin_session_orm import get_session_persist_id # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import get_user # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import get_user
|
||||
|
||||
from ....db import query_bind_info, trigger
|
||||
from ....utils.exception import RecordNotFoundError
|
||||
@@ -18,14 +18,23 @@ 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.tetrio_record_base import Finesse, Max, Mini, Statistic, Tspins, User
|
||||
from ....utils.render.schemas.tetrio.tetrio_record_sprint import Record
|
||||
from ....utils.render.schemas.tetrio.record.base import Finesse, Max, Mini, Statistic, Tspins, User
|
||||
from ....utils.render.schemas.tetrio.record.sprint import Record
|
||||
from ....utils.screenshot import screenshot
|
||||
from ....utils.typing import Me
|
||||
from ...constant import CANT_VERIFY_MESSAGE
|
||||
from .. import alc
|
||||
from ..api.player import Player
|
||||
from ..constant import GAME_TYPE
|
||||
from . import command
|
||||
|
||||
command.add(Option('--40l', dest='sprint'))
|
||||
|
||||
alc.shortcut(
|
||||
'(?i:io)(?i:记录|record)(?i:40l)',
|
||||
command='tstats TETR.IO record --40l',
|
||||
humanized='io记录40l',
|
||||
)
|
||||
|
||||
|
||||
@alc.assign('TETRIO.record.sprint')
|
||||
@@ -82,7 +91,7 @@ async def make_sprint_image(player: Player) -> bytes:
|
||||
page=await render(
|
||||
'v2/tetrio/record/40l',
|
||||
Record(
|
||||
type='personal_best',
|
||||
type='best',
|
||||
user=User(
|
||||
id=user.ID,
|
||||
name=user.name.upper(),
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from arclet.alconna import Arg, ArgFlag, Args, Subcommand
|
||||
from nonebot_plugin_alconna import At
|
||||
from arclet.alconna import Arg, ArgFlag
|
||||
from nepattern import parser # type: ignore[import-untyped]
|
||||
from nonebot_plugin_alconna import Args, At, Subcommand
|
||||
|
||||
from ...utils.exception import MessageFormatError
|
||||
from ...utils.typing import Me
|
||||
@@ -22,7 +23,7 @@ command.add(
|
||||
Args(
|
||||
Arg(
|
||||
'account',
|
||||
get_player,
|
||||
parser(get_player),
|
||||
notice='TOP 用户名 / ID',
|
||||
flags=[ArgFlag.HIDDEN],
|
||||
)
|
||||
@@ -34,13 +35,13 @@ command.add(
|
||||
Args(
|
||||
Arg(
|
||||
'target',
|
||||
At | Me,
|
||||
parser(At | Me),
|
||||
notice='@想要查询的人 / 自己',
|
||||
flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL],
|
||||
),
|
||||
Arg(
|
||||
'account',
|
||||
get_player,
|
||||
parser(get_player),
|
||||
notice='TOP 用户名',
|
||||
flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL],
|
||||
),
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage
|
||||
from nonebot_plugin_orm import get_session
|
||||
from nonebot_plugin_session import EventSession # type: ignore[import-untyped]
|
||||
from nonebot_plugin_session import EventSession
|
||||
from nonebot_plugin_session_orm import get_session_persist_id # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import User # type: ignore[import-untyped]
|
||||
from nonebot_plugin_userinfo import BotUserInfo, EventUserInfo, UserInfo # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import User
|
||||
from nonebot_plugin_userinfo import BotUserInfo, EventUserInfo, UserInfo
|
||||
|
||||
from ...db import BindStatus, create_or_update_bind, trigger
|
||||
from ...utils.host import HostPage, get_self_netloc
|
||||
|
||||
@@ -3,9 +3,9 @@ from nonebot.matcher import Matcher
|
||||
from nonebot_plugin_alconna import At
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage
|
||||
from nonebot_plugin_orm import get_session
|
||||
from nonebot_plugin_session import EventSession # type: ignore[import-untyped]
|
||||
from nonebot_plugin_session import EventSession
|
||||
from nonebot_plugin_session_orm import get_session_persist_id # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import get_user # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import get_user
|
||||
|
||||
from ...db import query_bind_info, trigger
|
||||
from ...utils.metrics import get_metrics
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
from arclet.alconna import Arg, ArgFlag, Args, Subcommand
|
||||
from nonebot_plugin_alconna import At
|
||||
from arclet.alconna import Arg, ArgFlag
|
||||
from nepattern import parser # type: ignore[import-untyped]
|
||||
from nonebot_plugin_alconna import Args, At, Subcommand
|
||||
|
||||
from ...utils.exception import MessageFormatError
|
||||
from ...utils.typing import Me
|
||||
@@ -27,7 +28,7 @@ command.add(
|
||||
Args(
|
||||
Arg(
|
||||
'account',
|
||||
get_player,
|
||||
parser(get_player),
|
||||
notice='茶服 用户名 / ID',
|
||||
flags=[ArgFlag.HIDDEN],
|
||||
)
|
||||
@@ -39,13 +40,13 @@ command.add(
|
||||
Args(
|
||||
Arg(
|
||||
'target',
|
||||
At | Me,
|
||||
parser(At | Me),
|
||||
notice='@想要查询的人 / 自己',
|
||||
flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL],
|
||||
),
|
||||
Arg(
|
||||
'account',
|
||||
get_player,
|
||||
parser(get_player),
|
||||
notice='茶服 用户名 / TeaID',
|
||||
flags=[ArgFlag.HIDDEN, ArgFlag.OPTIONAL],
|
||||
),
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage
|
||||
from nonebot_plugin_orm import get_session
|
||||
from nonebot_plugin_session import EventSession # type: ignore[import-untyped]
|
||||
from nonebot_plugin_session import EventSession
|
||||
from nonebot_plugin_session_orm import get_session_persist_id # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import User # type: ignore[import-untyped]
|
||||
from nonebot_plugin_userinfo import BotUserInfo, EventUserInfo, UserInfo # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import User
|
||||
from nonebot_plugin_userinfo import BotUserInfo, EventUserInfo, UserInfo
|
||||
|
||||
from ...db import BindStatus, create_or_update_bind, trigger
|
||||
from ...utils.host import HostPage, get_self_netloc
|
||||
|
||||
@@ -8,10 +8,10 @@ from nonebot.matcher import Matcher
|
||||
from nonebot_plugin_alconna import At
|
||||
from nonebot_plugin_alconna.uniseg import UniMessage
|
||||
from nonebot_plugin_orm import get_session
|
||||
from nonebot_plugin_session import EventSession # type: ignore[import-untyped]
|
||||
from nonebot_plugin_session import EventSession
|
||||
from nonebot_plugin_session_orm import get_session_persist_id # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import get_user # type: ignore[import-untyped]
|
||||
from nonebot_plugin_userinfo import EventUserInfo, UserInfo # type: ignore[import-untyped]
|
||||
from nonebot_plugin_user import get_user
|
||||
from nonebot_plugin_userinfo import EventUserInfo, UserInfo
|
||||
|
||||
from ...db import query_bind_info, trigger
|
||||
from ...utils.exception import RequestError
|
||||
|
||||
@@ -2,7 +2,7 @@ from base64 import b64encode
|
||||
from io import BytesIO
|
||||
from typing import Literal, overload
|
||||
|
||||
from nonebot_plugin_userinfo import UserInfo # type: ignore[import-untyped]
|
||||
from nonebot_plugin_userinfo import UserInfo
|
||||
from PIL import Image
|
||||
|
||||
|
||||
|
||||
@@ -5,14 +5,14 @@ from nonebot.compat import PYDANTIC_V2
|
||||
|
||||
from ..templates import TEMPLATES_DIR
|
||||
from .schemas.bind import Bind
|
||||
from .schemas.tetrio.tetrio_info import Info as TETRIOInfo
|
||||
from .schemas.tetrio.tetrio_rank_detail import Data as TETRIORankDetailData
|
||||
from .schemas.tetrio.tetrio_rank_v1 import Data as TETRIORankDataV1
|
||||
from .schemas.tetrio.tetrio_rank_v2 import Data as TETRIORankDataV2
|
||||
from .schemas.tetrio.tetrio_record_blitz import Record as TETRIORecordBlitz
|
||||
from .schemas.tetrio.tetrio_record_sprint import Record as TETRIORecordSprint
|
||||
from .schemas.tetrio.tetrio_user_info_v2 import Info as TETRIOUserInfoV2
|
||||
from .schemas.tetrio.tetrio_user_list_v2 import List as TETRIOUserListV2
|
||||
from .schemas.tetrio.rank.detail import Data as TETRIORankDetailData
|
||||
from .schemas.tetrio.rank.v1 import Data as TETRIORankDataV1
|
||||
from .schemas.tetrio.rank.v2 import Data as TETRIORankDataV2
|
||||
from .schemas.tetrio.record.blitz import Record as TETRIORecordBlitz
|
||||
from .schemas.tetrio.record.sprint import Record as TETRIORecordSprint
|
||||
from .schemas.tetrio.user.info_v1 import Info as TETRIOUserInfoV1
|
||||
from .schemas.tetrio.user.info_v2 import Info as TETRIOUserInfoV2
|
||||
from .schemas.tetrio.user.list_v2 import List as TETRIOUserListV2
|
||||
from .schemas.top_info import Info as TOPInfo
|
||||
from .schemas.tos_info import Info as TOSInfo
|
||||
|
||||
@@ -24,7 +24,7 @@ env = Environment(
|
||||
@overload
|
||||
async def render(render_type: Literal['v1/binding'], data: Bind) -> str: ...
|
||||
@overload
|
||||
async def render(render_type: Literal['v1/tetrio/info'], data: TETRIOInfo) -> str: ...
|
||||
async def render(render_type: Literal['v1/tetrio/info'], data: TETRIOUserInfoV1) -> str: ...
|
||||
@overload
|
||||
async def render(render_type: Literal['v1/tetrio/rank'], data: TETRIORankDataV1) -> str: ...
|
||||
@overload
|
||||
@@ -60,7 +60,7 @@ async def render(
|
||||
'v2/tetrio/rank/detail',
|
||||
],
|
||||
data: Bind
|
||||
| TETRIOInfo
|
||||
| TETRIOUserInfoV1
|
||||
| TETRIORankDataV1
|
||||
| TOPInfo
|
||||
| TOSInfo
|
||||
|
||||
@@ -2,7 +2,7 @@ from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .....games.tetrio.api.typing import ValidRank
|
||||
from ......games.tetrio.api.typing import ValidRank
|
||||
|
||||
|
||||
class SpecialData(BaseModel):
|
||||
@@ -2,7 +2,7 @@ from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .....games.tetrio.api.typing import ValidRank
|
||||
from ......games.tetrio.api.typing import ValidRank
|
||||
|
||||
|
||||
class ItemData(BaseModel):
|
||||
@@ -2,7 +2,7 @@ from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .....games.tetrio.api.typing import ValidRank
|
||||
from ......games.tetrio.api.typing import ValidRank
|
||||
|
||||
|
||||
class AverageData(BaseModel):
|
||||
@@ -3,7 +3,7 @@ from typing import Literal
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from ..base import People
|
||||
from ...base import People
|
||||
|
||||
|
||||
class User(People):
|
||||
@@ -1,5 +1,5 @@
|
||||
from .tetrio_record_base import Record as BaseRecord
|
||||
from .tetrio_record_base import Statistic as BaseStatistic
|
||||
from .base import Record as BaseRecord
|
||||
from .base import Statistic as BaseStatistic
|
||||
|
||||
|
||||
class Statistic(BaseStatistic):
|
||||
@@ -0,0 +1,5 @@
|
||||
from .base import Record as BaseRecord
|
||||
|
||||
|
||||
class Record(BaseRecord):
|
||||
time: str
|
||||
@@ -1,5 +0,0 @@
|
||||
from .tetrio_record_base import Record as BaseRecord
|
||||
|
||||
|
||||
class Record(BaseRecord):
|
||||
time: str
|
||||
@@ -2,7 +2,7 @@ from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from ....typing import Number
|
||||
from .....typing import Number
|
||||
|
||||
|
||||
class TetraLeagueHistoryData(BaseModel):
|
||||
@@ -1,8 +1,8 @@
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .....games.tetrio.api.typing import Rank
|
||||
from ....typing import Number
|
||||
from ..base import People, Ranking
|
||||
from ......games.tetrio.api.typing import Rank
|
||||
from .....typing import Number
|
||||
from ...base import People, Ranking
|
||||
from .base import TetraLeagueHistoryData
|
||||
|
||||
|
||||
@@ -3,10 +3,10 @@ from typing import Literal
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .....games.tetrio.api.schemas.user_records import Zen
|
||||
from .....games.tetrio.api.typing import Rank
|
||||
from ....typing import Number
|
||||
from ..base import Avatar
|
||||
from ......games.tetrio.api.schemas.user_records import Zen
|
||||
from ......games.tetrio.api.typing import Rank, ValidRank
|
||||
from .....typing import Number
|
||||
from ...base import Avatar
|
||||
from .base import TetraLeagueHistoryData
|
||||
|
||||
|
||||
@@ -54,20 +54,20 @@ class TetraLeagueStatistic(BaseModel):
|
||||
|
||||
class TetraLeague(BaseModel):
|
||||
rank: Rank
|
||||
highest_rank: Rank
|
||||
highest_rank: ValidRank
|
||||
|
||||
tr: Number
|
||||
|
||||
glicko: Number
|
||||
rd: Number
|
||||
glicko: Number | None
|
||||
rd: Number | None
|
||||
|
||||
global_rank: int | None
|
||||
country_rank: int | None
|
||||
|
||||
pps: Number
|
||||
pps: Number | None
|
||||
|
||||
apm: Number
|
||||
apl: Number
|
||||
apm: Number | None
|
||||
apl: Number | None
|
||||
|
||||
vs: Number | None
|
||||
adpl: Number | None
|
||||
@@ -76,7 +76,7 @@ class TetraLeague(BaseModel):
|
||||
|
||||
decaying: bool
|
||||
|
||||
history: list[TetraLeagueHistoryData]
|
||||
history: list[TetraLeagueHistoryData] | None
|
||||
|
||||
|
||||
class Sprint(BaseModel):
|
||||
@@ -97,4 +97,4 @@ class Info(BaseModel):
|
||||
statistic: Statistic | None
|
||||
sprint: Sprint | None
|
||||
blitz: Blitz | None
|
||||
zen: Zen
|
||||
zen: Zen | None
|
||||
@@ -2,9 +2,9 @@ from datetime import datetime
|
||||
|
||||
from pydantic import BaseModel
|
||||
|
||||
from .....games.tetrio.api.typing import Rank
|
||||
from ....typing import Number
|
||||
from ..base import Avatar
|
||||
from ......games.tetrio.api.typing import Rank
|
||||
from .....typing import Number
|
||||
from ...base import Avatar
|
||||
|
||||
|
||||
class TetraLeague(BaseModel):
|
||||
956
poetry.lock
generated
956
poetry.lock
generated
File diff suppressed because it is too large
Load Diff
@@ -1,6 +1,6 @@
|
||||
[tool.poetry]
|
||||
name = 'nonebot-plugin-tetris-stats'
|
||||
version = '1.4.2'
|
||||
version = '1.4.3'
|
||||
description = '一款基于 NoneBot2 的用于查询 Tetris 相关游戏数据的插件'
|
||||
authors = ['scdhh <wallfjjd@gmail.com>']
|
||||
readme = 'README.md'
|
||||
@@ -21,7 +21,6 @@ nonebot-plugin-user = ">=0.2,<0.4"
|
||||
nonebot-plugin-userinfo = "^0.2.4"
|
||||
aiocache = "^0.12.2"
|
||||
aiofiles = ">=23.2.1,<25.0.0"
|
||||
arclet-alconna = "^1.8.19"
|
||||
async-lru = "^2.0.4"
|
||||
httpx = "^0.27.0"
|
||||
jinja2 = "^3.1.3"
|
||||
@@ -131,3 +130,4 @@ quote-style = 'single'
|
||||
|
||||
[tool.nonebot]
|
||||
plugins = ['nonebot_plugin_tetris_stats']
|
||||
# plugins = ['test_datetime']
|
||||
|
||||
Reference in New Issue
Block a user