mirror of
https://github.com/A-Minos/nonebot-plugin-tetris-stats.git
synced 2026-03-05 05:36:54 +08:00
Some checks are pending
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) Waiting to run
* ➕ 添加依赖 strenum * 🐛 优化等待逻辑,修复截图爆炸 * ✨ 使用新模板 * ⚡️ 关闭自动转译 * ✨ 同步新模板 schemas * 🌐 添加模板语言的映射 * ✨ 适配 bind * ✨ 更新模板 * ✨ 全部适配 * 🚨 make mypy happy * Update nonebot_plugin_tetris_stats/games/tos/query.py Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> * ✨ 使用用户设置语言 * 🚨 auto fix by pre-commit hooks --------- Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
57 lines
1.8 KiB
Python
57 lines
1.8 KiB
Python
from collections.abc import Callable
|
|
from datetime import timedelta
|
|
from typing import TypeVar, overload
|
|
from zoneinfo import ZoneInfo
|
|
|
|
from ....utils.exception import FallbackError
|
|
from ....utils.render.schemas.base import HistoryData
|
|
from ..api.schemas.labs.leagueflow import Empty, LeagueFlowSuccess
|
|
from ..api.schemas.summaries.league import InvalidData, LeagueSuccessModel, NeverPlayedData, NeverRatedData, RatedData
|
|
|
|
|
|
def flow_to_history(
|
|
leagueflow: LeagueFlowSuccess,
|
|
handle: Callable[[list[HistoryData]], list[HistoryData]] | None = None,
|
|
) -> list[HistoryData]:
|
|
if isinstance(leagueflow.data, Empty):
|
|
raise FallbackError
|
|
start_time = leagueflow.data.start_time.astimezone(ZoneInfo('Asia/Shanghai'))
|
|
ret = [
|
|
HistoryData(
|
|
record_at=start_time + timedelta(milliseconds=i.timestamp_offset),
|
|
score=i.post_match_tr,
|
|
)
|
|
for i in leagueflow.data.points
|
|
if start_time + timedelta(milliseconds=i.timestamp_offset)
|
|
]
|
|
return ret if handle is None else handle(ret)
|
|
|
|
|
|
N = TypeVar('N', int, float)
|
|
|
|
|
|
def handling_special_value(value: N) -> N | None:
|
|
return value if value != -1 else None
|
|
|
|
|
|
L = TypeVar('L', NeverPlayedData, NeverRatedData, RatedData)
|
|
|
|
|
|
@overload
|
|
def get_league_data(user_info: LeagueSuccessModel, league_type: type[L]) -> L: ...
|
|
@overload
|
|
def get_league_data(
|
|
user_info: LeagueSuccessModel, league_type: None = None
|
|
) -> NeverPlayedData | NeverRatedData | RatedData: ...
|
|
def get_league_data(
|
|
user_info: LeagueSuccessModel, league_type: type[L] | None = None
|
|
) -> L | NeverPlayedData | NeverRatedData | RatedData:
|
|
league = user_info.data
|
|
if isinstance(league, InvalidData):
|
|
raise FallbackError
|
|
if league_type is None:
|
|
return league
|
|
if isinstance(league, league_type):
|
|
return league
|
|
raise FallbackError
|