⬆️ auto update by pre-commit hooks (#529)
Some checks failed
Code Coverage / Test (macos-latest, 3.10) (push) Waiting to run
Code Coverage / Test (macos-latest, 3.11) (push) Waiting to run
Code Coverage / Test (macos-latest, 3.12) (push) Waiting to run
Code Coverage / Test (ubuntu-latest, 3.10) (push) Waiting to run
Code Coverage / Test (ubuntu-latest, 3.11) (push) Waiting to run
Code Coverage / Test (ubuntu-latest, 3.12) (push) Waiting to run
Code Coverage / Test (windows-latest, 3.10) (push) Waiting to run
Code Coverage / Test (windows-latest, 3.11) (push) Waiting to run
Code Coverage / Test (windows-latest, 3.12) (push) Waiting to run
Code Coverage / check (push) Blocked by required conditions
TypeCheck / TypeCheck (push) Waiting to run
CodeQL / Analyze (python) (push) Has been cancelled

* ⬆️ auto update by pre-commit hooks

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.8.3 → v0.9.6](https://github.com/astral-sh/ruff-pre-commit/compare/v0.8.3...v0.9.6)

* 🚨 auto fix by pre-commit hooks

* ♻️ 重命名 typing 为 typedefs

* ♻️ 使用 Annotated 代替默认值

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: shoucandanghehe <wallfjjd@gmail.com>
This commit is contained in:
pre-commit-ci[bot]
2025-02-13 04:18:36 +08:00
committed by GitHub
parent 5e45db8cf5
commit bb8943d4c3
41 changed files with 49 additions and 47 deletions

View File

@@ -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]

View File

@@ -11,7 +11,7 @@ from nonebot_plugin_orm import AsyncSession, get_session
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

View File

@@ -9,7 +9,7 @@ from sqlalchemy import JSON, DateTime, Dialect, String, TypeDecorator
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):

View File

@@ -3,7 +3,7 @@ from typing import Generic, TypeVar
from pydantic import BaseModel
from ..utils.typing import GameType
from ..utils.typedefs import GameType
T = TypeVar('T', bound=GameType)

View File

@@ -7,7 +7,7 @@ from sqlalchemy.orm import Mapped, MappedAsDataclass, mapped_column
from ....db.models import PydanticType
from .schemas.base import SuccessModel
from .typing import Records, Summaries
from .typedefs import Records, Summaries
class TETRIOHistoricalData(MappedAsDataclass, Model):

View File

@@ -27,7 +27,7 @@ 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
from .typedefs import Records, Summaries
class RecordModeType(str, Enum):

View File

@@ -3,7 +3,7 @@ from typing import Literal
from pydantic import BaseModel, Field
from ...typing import Prisecter
from ...typedefs import Prisecter
class AggregateStats(BaseModel):

View File

@@ -3,7 +3,7 @@ from typing import Any
from nonebot.compat import PYDANTIC_V2
from pydantic import BaseModel, Field
from ...typing import Prisecter
from ...typedefs import Prisecter
class Parameter(BaseModel):

View File

@@ -3,7 +3,7 @@ from typing import Literal
from pydantic import BaseModel, Field
from ...typing import Rank, ValidRank
from ...typedefs import Rank, ValidRank
from ..base import ArCounts, FailedModel, P, SuccessModel

View File

@@ -3,7 +3,7 @@ from typing import Literal
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:

View File

@@ -11,7 +11,7 @@ from ...db import trigger
from . import alc, command
from .constant import GAME_TYPE
from .models import TETRIOUserConfig
from .typing import Template
from .typedefs import Template
command.add(
Subcommand(

View File

@@ -3,7 +3,7 @@ from typing import Literal
from yarl import URL
from .api.typing import ValidRank
from .api.typedefs import ValidRank
GAME_TYPE: Literal['IO'] = 'IO'

View File

@@ -7,8 +7,8 @@ from sqlalchemy.orm import Mapped, MappedAsDataclass, mapped_column, relationshi
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):

View File

@@ -16,13 +16,13 @@ from sqlalchemy import select
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

View File

@@ -43,9 +43,9 @@ async def make_query_image_v2(player: Player) -> bytes:
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'
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'
else:
play_time = f'{game_time:.0f}s'
else:

View File

@@ -25,7 +25,7 @@ from ..models import TETRIOLeagueHistorical, TETRIOLeagueStats, TETRIOLeagueStat
if TYPE_CHECKING:
from ..api.schemas.leaderboards.by import BySuccessModel
from ..api.typing import Rank
from ..api.typedefs import Rank
UTC = timezone.utc

View File

@@ -21,7 +21,7 @@ from ....utils.screenshot import screenshot
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(

View File

@@ -17,7 +17,7 @@ from ....utils.render import render
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

View File

@@ -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

View File

@@ -22,7 +22,7 @@ from ....utils.render.schemas.base import Avatar
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

View File

@@ -22,7 +22,7 @@ from ....utils.render.schemas.base import Avatar
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

View File

@@ -2,7 +2,7 @@ from arclet.alconna import Arg, ArgFlag
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

View File

@@ -18,7 +18,7 @@ from ...utils.render.schemas.base import People
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

View File

@@ -2,7 +2,7 @@ from arclet.alconna import Arg, ArgFlag
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

View File

@@ -24,7 +24,7 @@ from ...utils.render.avatar import get_avatar as get_random_avatar
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
@@ -258,7 +258,7 @@ def make_query_text(user_info: UserInfoSuccess, game_data: GameData | None) -> U
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)}) '
if game_data is None:
message += ', 暂无游戏数据'
else:
@@ -266,7 +266,7 @@ def make_query_text(user_info: UserInfoSuccess, game_data: GameData | None) -> U
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 ''
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)

View File

@@ -2,7 +2,7 @@ from functools import cache
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
@@ -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(

View File

@@ -23,7 +23,9 @@ def limit(limit: timedelta) -> Callable[[Callable[P, Coroutine[Any, Any, T]]], C
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(
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)

View File

@@ -1,6 +1,6 @@
from typing import overload
from .typing import Number
from .typedefs import Number
class TetrisMetricsBaseWithPPS:

View File

@@ -2,7 +2,7 @@ from typing import Literal
from pydantic import BaseModel
from ...typing import Number
from ...typedefs import Number
class Avatar(BaseModel):

View File

@@ -2,7 +2,7 @@ from datetime import datetime
from pydantic import BaseModel
from ......games.tetrio.api.typing import ValidRank
from ......games.tetrio.api.typedefs import ValidRank
class SpecialData(BaseModel):

View File

@@ -2,7 +2,7 @@ from datetime import datetime
from pydantic import BaseModel
from ......games.tetrio.api.typing import ValidRank
from ......games.tetrio.api.typedefs import ValidRank
class ItemData(BaseModel):

View File

@@ -2,7 +2,7 @@ from datetime import datetime
from pydantic import BaseModel
from ......games.tetrio.api.typing import ValidRank
from ......games.tetrio.api.typedefs import ValidRank
class AverageData(BaseModel):

View File

@@ -2,7 +2,7 @@ from datetime import datetime
from pydantic import BaseModel
from .....typing import Number
from .....typedefs import Number
class TetraLeagueHistoryData(BaseModel):

View File

@@ -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

View File

@@ -3,8 +3,8 @@ from typing import Literal
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

View File

@@ -2,8 +2,8 @@ from datetime import datetime
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

View File

@@ -1,6 +1,6 @@
from pydantic import BaseModel
from ...typing import Number
from ...typedefs import Number
from .base import People

View File

@@ -1,6 +1,6 @@
from pydantic import BaseModel, Field
from ...typing import Number
from ...typedefs import Number
from .base import People, Ranking