Skip to content

⬆️ auto update by pre-commit hooks #529

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Feb 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ ci:
autoupdate_commit_msg: ':arrow_up: auto update by pre-commit hooks'
repos:
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.8.3
rev: v0.9.6
hooks:
- id: ruff
args: [--fix, --exit-non-zero-on-fix]
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tetris_stats/db/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from nonebot_plugin_user import User
from sqlalchemy import select

from ..utils.typing import AllCommandType, BaseCommandType, GameType, TETRIOCommandType
from ..utils.typedefs import AllCommandType, BaseCommandType, GameType, TETRIOCommandType
from .models import Bind, TriggerHistoricalData

UTC = timezone.utc
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tetris_stats/db/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
from sqlalchemy.orm import Mapped, MappedAsDataclass, mapped_column
from typing_extensions import override

from ..utils.typing import AllCommandType, GameType
from ..utils.typedefs import AllCommandType, GameType


class PydanticType(TypeDecorator):
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tetris_stats/games/schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pydantic import BaseModel

from ..utils.typing import GameType
from ..utils.typedefs import GameType

T = TypeVar('T', bound=GameType)

Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tetris_stats/games/tetrio/api/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

from ....db.models import PydanticType
from .schemas.base import SuccessModel
from .typing import Records, Summaries
from .typedefs import Records, Summaries


class TETRIOHistoricalData(MappedAsDataclass, Model):
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tetris_stats/games/tetrio/api/player.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from .schemas.summaries.league import LeagueSuccessModel
from .schemas.user import User
from .schemas.user_info import UserInfo, UserInfoSuccess
from .typing import Records, Summaries
from .typedefs import Records, Summaries


class RecordModeType(str, Enum):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pydantic import BaseModel, Field

from ...typing import Prisecter
from ...typedefs import Prisecter


class AggregateStats(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from nonebot.compat import PYDANTIC_V2
from pydantic import BaseModel, Field

from ...typing import Prisecter
from ...typedefs import Prisecter


class Parameter(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from pydantic import BaseModel, Field

from ...typing import Rank, ValidRank
from ...typedefs import Rank, ValidRank
from ..base import ArCounts, FailedModel, P, SuccessModel


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
from nonebot.compat import PYDANTIC_V2
from pydantic import BaseModel, Field

from ...typing import Rank, S1Rank, S1ValidRank
from ...typedefs import Rank, S1Rank, S1ValidRank
from ..base import SuccessModel

if PYDANTIC_V2:
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tetris_stats/games/tetrio/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
from . import alc, command
from .constant import GAME_TYPE
from .models import TETRIOUserConfig
from .typing import Template
from .typedefs import Template

command.add(
Subcommand(
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tetris_stats/games/tetrio/constant.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from yarl import URL

from .api.typing import ValidRank
from .api.typedefs import ValidRank

GAME_TYPE: Literal['IO'] = 'IO'

Expand Down
4 changes: 2 additions & 2 deletions nonebot_plugin_tetris_stats/games/tetrio/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

from ...db.models import PydanticType
from .api.schemas.leaderboards.by import BySuccessModel, Entry
from .api.typing import ValidRank
from .typing import Template
from .api.typedefs import ValidRank
from .typedefs import Template


class TETRIOUserConfig(MappedAsDataclass, Model):
Expand Down
4 changes: 2 additions & 2 deletions nonebot_plugin_tetris_stats/games/tetrio/query/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
from ....db import query_bind_info, trigger
from ....i18n import Lang
from ....utils.exception import FallbackError
from ....utils.typing import Me
from ....utils.typedefs import Me
from ... import add_block_handlers, alc
from .. import command, get_player
from ..api import Player
from ..constant import GAME_TYPE
from ..models import TETRIOUserConfig
from ..typing import Template
from ..typedefs import Template
from .v1 import make_query_image_v1
from .v2 import make_query_image_v2

Expand Down
4 changes: 2 additions & 2 deletions nonebot_plugin_tetris_stats/games/tetrio/query/v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,9 @@
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'
play_time = f'{game_time // 3600:.0f}h {game_time % 3600 // 60:.0f}m {game_time % 60:.0f}s'

Check warning on line 46 in nonebot_plugin_tetris_stats/games/tetrio/query/v2.py

View check run for this annotation

Codecov / codecov/patch

nonebot_plugin_tetris_stats/games/tetrio/query/v2.py#L46

Added line #L46 was not covered by tests
elif game_time // 60 > 0:
play_time = f'{game_time//60:.0f}m {game_time % 60:.0f}s'
play_time = f'{game_time // 60:.0f}m {game_time % 60:.0f}s'

Check warning on line 48 in nonebot_plugin_tetris_stats/games/tetrio/query/v2.py

View check run for this annotation

Codecov / codecov/patch

nonebot_plugin_tetris_stats/games/tetrio/query/v2.py#L48

Added line #L48 was not covered by tests
else:
play_time = f'{game_time:.0f}s'
else:
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tetris_stats/games/tetrio/rank/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

if TYPE_CHECKING:
from ..api.schemas.leaderboards.by import BySuccessModel
from ..api.typing import Rank
from ..api.typedefs import Rank

Check warning on line 28 in nonebot_plugin_tetris_stats/games/tetrio/rank/__init__.py

View check run for this annotation

Codecov / codecov/patch

nonebot_plugin_tetris_stats/games/tetrio/rank/__init__.py#L28

Added line #L28 was not covered by tests

UTC = timezone.utc

Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tetris_stats/games/tetrio/rank/all.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
from .. import alc
from ..constant import GAME_TYPE
from ..models import TETRIOLeagueStats
from ..typing import Template
from ..typedefs import Template
from . import command

command.add(
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tetris_stats/games/tetrio/rank/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
from ....utils.render.schemas.tetrio.rank.detail import Data, SpecialData
from ....utils.screenshot import screenshot
from .. import alc
from ..api.typing import ValidRank
from ..api.typedefs import ValidRank
from ..constant import GAME_TYPE
from ..models import TETRIOLeagueStats
from . import command
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from arclet.alconna import Arg, ArgFlag
from nonebot_plugin_alconna import Args, At, Subcommand

from ....utils.typing import Me
from ....utils.typedefs import Me
from .. import command as base_command
from .. import get_player

Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tetris_stats/games/tetrio/record/blitz.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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 ....utils.typedefs import Me
from .. import alc
from ..api.player import Player
from ..constant import GAME_TYPE
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tetris_stats/games/tetrio/record/sprint.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
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 ....utils.typedefs import Me
from .. import alc
from ..api.player import Player
from ..constant import GAME_TYPE
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tetris_stats/games/top/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from nonebot_plugin_alconna import Args, At, Subcommand

from ...utils.exception import MessageFormatError
from ...utils.typing import Me
from ...utils.typedefs import Me
from .. import add_block_handlers, alc, command
from .api import Player
from .constant import USER_NAME
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tetris_stats/games/top/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
from ...utils.render.schemas.top_info import Data as InfoData
from ...utils.render.schemas.top_info import Info
from ...utils.screenshot import screenshot
from ...utils.typing import Me
from ...utils.typedefs import Me
from . import alc
from .api import Player
from .api.schemas.user_profile import Data, UserProfile
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tetris_stats/games/tos/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from nonebot_plugin_alconna import Args, At, Subcommand

from ...utils.exception import MessageFormatError
from ...utils.typing import Me
from ...utils.typedefs import Me
from .. import add_block_handlers, alc, command
from .api import Player
from .constant import USER_NAME
Expand Down
6 changes: 3 additions & 3 deletions nonebot_plugin_tetris_stats/games/tos/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
from ...utils.render.schemas.base import People, Ranking
from ...utils.render.schemas.tos_info import Info, Multiplayer, Radar
from ...utils.screenshot import screenshot
from ...utils.typing import Me, Number
from ...utils.typedefs import Me, Number
from . import alc
from .api import Player
from .api.schemas.user_info import UserInfoSuccess
Expand Down Expand Up @@ -258,15 +258,15 @@
if user_data.ranked_games == '0':
message += '暂无段位统计数据'
else:
message += f', 段位分 {round(float(user_data.rating_now),2)}±{round(float(user_data.rd_now),2)} ({round(float(user_data.vol_now),2)}) '
message += f', 段位分 {round(float(user_data.rating_now), 2)}±{round(float(user_data.rd_now), 2)} ({round(float(user_data.vol_now), 2)}) '

Check warning on line 261 in nonebot_plugin_tetris_stats/games/tos/query.py

View check run for this annotation

Codecov / codecov/patch

nonebot_plugin_tetris_stats/games/tos/query.py#L261

Added line #L261 was not covered by tests
if game_data is None:
message += ', 暂无游戏数据'
else:
message += f', 最近 {game_data.game_num} 局数据'
message += f"\nL'PM: {game_data.metrics.lpm} ( {game_data.metrics.pps} pps )"
message += f'\nAPM: {game_data.metrics.apm} ( x{game_data.metrics.apl} )'
message += f'\nADPM: {game_data.metrics.adpm} ( x{game_data.metrics.adpl} ) ( {game_data.metrics.vs}vs )'
message += f'\n40L: {float(user_data.pb_sprint)/1000:.2f}s' if user_data.pb_sprint != '2147483647' else ''
message += f'\n40L: {float(user_data.pb_sprint) / 1000:.2f}s' if user_data.pb_sprint != '2147483647' else ''

Check warning on line 269 in nonebot_plugin_tetris_stats/games/tos/query.py

View check run for this annotation

Codecov / codecov/patch

nonebot_plugin_tetris_stats/games/tos/query.py#L269

Added line #L269 was not covered by tests
message += f'\nMarathon: {user_data.pb_marathon}' if user_data.pb_marathon != '0' else ''
message += f'\nChallenge: {user_data.pb_challenge}' if user_data.pb_challenge != '0' else ''
return UniMessage(message)
4 changes: 2 additions & 2 deletions nonebot_plugin_tetris_stats/utils/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from hashlib import sha256
from ipaddress import IPv4Address, IPv6Address
from pathlib import Path as FilePath
from typing import TYPE_CHECKING, ClassVar, Literal
from typing import TYPE_CHECKING, Annotated, ClassVar, Literal

from aiofiles import open as aopen
from fastapi import BackgroundTasks, FastAPI, Path, status
Expand Down Expand Up @@ -69,9 +69,9 @@ def _(page_hash: str) -> HTMLResponse:
@app.get('/host/resource/tetrio/{resource_type}/{user_id}', status_code=status.HTTP_200_OK)
async def _(
resource_type: Literal['avatars', 'banners'],
user_id: Annotated[str, Path(regex=r'^[a-f0-9]{24}$')],
revision: int,
background_tasks: BackgroundTasks,
user_id: str = Path(regex=r'^[a-f0-9]{24}$'),
) -> Response:
if not (path := CACHE_PATH / 'tetrio' / resource_type / f'{user_id}_{revision}.png').exists():
image = img_to_png(
Expand Down
4 changes: 3 additions & 1 deletion nonebot_plugin_tetris_stats/utils/limit.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@
nonlocal last_call
async with lock:
if (diff := (time() - last_call)) < limit_seconds:
logger.debug(f'func: {func.__name__} trigger limit, wait {(limit_time:=limit_seconds-diff):.3f}s')
logger.debug(

Check warning on line 26 in nonebot_plugin_tetris_stats/utils/limit.py

View check run for this annotation

Codecov / codecov/patch

nonebot_plugin_tetris_stats/utils/limit.py#L26

Added line #L26 was not covered by tests
f'func: {func.__name__} trigger limit, wait {(limit_time := limit_seconds - diff):.3f}s'
)
await sleep(limit_time)
last_call = time()
return await func(*args, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tetris_stats/utils/metrics.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import overload

from .typing import Number
from .typedefs import Number


class TetrisMetricsBaseWithPPS:
Expand Down
2 changes: 1 addition & 1 deletion nonebot_plugin_tetris_stats/utils/render/schemas/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pydantic import BaseModel

from ...typing import Number
from ...typedefs import Number


class Avatar(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pydantic import BaseModel

from ......games.tetrio.api.typing import ValidRank
from ......games.tetrio.api.typedefs import ValidRank


class SpecialData(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pydantic import BaseModel

from ......games.tetrio.api.typing import ValidRank
from ......games.tetrio.api.typedefs import ValidRank


class ItemData(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pydantic import BaseModel

from ......games.tetrio.api.typing import ValidRank
from ......games.tetrio.api.typedefs import ValidRank


class AverageData(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from pydantic import BaseModel

from .....typing import Number
from .....typedefs import Number


class TetraLeagueHistoryData(BaseModel):
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from pydantic import BaseModel

from ......games.tetrio.api.typing import Rank
from .....typing import Number
from ......games.tetrio.api.typedefs import Rank
from .....typedefs import Number
from ...base import People, Ranking
from .base import TetraLeagueHistoryData

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@

from pydantic import BaseModel

from ......games.tetrio.api.typing import Rank
from .....typing import Number
from ......games.tetrio.api.typedefs import Rank
from .....typedefs import Number
from ...base import Avatar
from .base import TetraLeagueHistoryData

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

from pydantic import BaseModel

from ......games.tetrio.api.typing import Rank
from .....typing import Number
from ......games.tetrio.api.typedefs import Rank
from .....typedefs import Number
from ...base import Avatar


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic import BaseModel

from ...typing import Number
from ...typedefs import Number
from .base import People


Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from pydantic import BaseModel, Field

from ...typing import Number
from ...typedefs import Number
from .base import People, Ranking


Expand Down