Skip to content

Commit

Permalink
兼容pydantic v2
Browse files Browse the repository at this point in the history
  • Loading branch information
ssttkkl committed Jan 22, 2025
1 parent 471196f commit 010cd44
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "nonebot-plugin-majsoul"
version = "0.2.8"
version = "0.2.9"
description = "NoneBot2 雀魂信息查询插件"
authors = ["ssttkkl <[email protected]>"]
license = "AGPL-3.0"
Expand All @@ -13,7 +13,7 @@ packages = [
python = "^3.9"
nonebot2 = {extras = ["httpx"], version = ">=2.0.0"}
nonebot-plugin-send-anything-anywhere = ">=0.2.1"
ssttkkl-nonebot-utils = ">=0.1.22"
ssttkkl-nonebot-utils = ">=0.1.23"
tzlocal = ">=4.2"
monthdelta = ">=0.9.1"
icmplib = ">=3.0.3"
Expand Down
7 changes: 4 additions & 3 deletions src/nonebot_plugin_majsoul/paifuya/data/models/game_record.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
from datetime import datetime, timezone
from typing import List

from pydantic import BaseModel, Field, validator
from pydantic import BaseModel, Field

from ssttkkl_nonebot_utils.pyc import field_validator
from .player_rank import PlayerRank
from .room_rank import RoomRank

Expand All @@ -14,7 +15,7 @@ class GamePlayer(BaseModel):
score: int
pt: int = Field(alias="gradingScore")

@validator("rank", pre=True, allow_reuse=True)
@field_validator("rank", mode="before")
def parse_rank(cls, v):
if isinstance(v, PlayerRank):
return v
Expand All @@ -31,7 +32,7 @@ class GameRecord(BaseModel):
end_time: datetime = Field(alias="endTime")
players: List[GamePlayer]

@validator("start_time", "end_time", pre=True, allow_reuse=True)
@field_validator("start_time", "end_time", mode="before")
def parse_timestamp(cls, v):
if isinstance(v, int) or isinstance(v, float):
return datetime.fromtimestamp(v, timezone.utc)
Expand Down

0 comments on commit 010cd44

Please sign in to comment.