diff --git a/pyproject.toml b/pyproject.toml index d256a3e..f6293b0 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -4,7 +4,7 @@ build-backend = "hatchling.build" [project] name = "yggdrasil-mc" -version = "0.1b7" +version = "0.1b8" authors = [ { name="Xiao_Jin", email="i@xiaojin233.cn" }, ] diff --git a/src/yggdrasil_mc/model.py b/src/yggdrasil_mc/model.py index 1c16a24..36a0e46 100644 --- a/src/yggdrasil_mc/model.py +++ b/src/yggdrasil_mc/model.py @@ -1,10 +1,10 @@ import json from base64 import b64decode -from datetime import date +from datetime import datetime from typing import Literal from urllib.parse import urlparse -from pydantic import BaseModel, Field, root_validator +from pydantic import model_validator, BaseModel, Field, root_validator class YggdrasilPlayerUuidApiModel(BaseModel): @@ -30,13 +30,13 @@ class _Skin(BaseModel): url: str | None = None hash: str | None = None metadata: _SkinMetaData | None = _SkinMetaData(model="default") - _get_hash = root_validator(allow_reuse=True)(get_hash) + _get_hash = model_validator(mode="before")(get_hash) class _Cape(BaseModel): url: str | None = None hash: str | None = None - _get_hash = root_validator(allow_reuse=True)(get_hash) + _get_hash = model_validator(mode="before")(get_hash) class YggdrasilTexturesModel(BaseModel): @@ -45,7 +45,7 @@ class YggdrasilTexturesModel(BaseModel): class YggdrasilPropertiesTexturesModel(BaseModel): - timestamp: date + timestamp: datetime profileId: str profileName: str textures: YggdrasilTexturesModel @@ -59,7 +59,8 @@ class Properties(BaseModel): name: str properties: Properties # a bit difference between API - @root_validator(pre=True) + @model_validator(mode="before") + @classmethod def pre_processer(cls, values): # Doc: https://wiki.vg/Mojang_API#UUID_-.3E_Profile_.2B_Skin.2FCape # base64 decode and a little change diff --git a/src/yggdrasil_mc/ygg.py b/src/yggdrasil_mc/ygg.py index 65dafcb..7a94792 100644 --- a/src/yggdrasil_mc/ygg.py +++ b/src/yggdrasil_mc/ygg.py @@ -9,7 +9,7 @@ def get(cls, api_root: str, player_name: str): resp = httpx.get(f"{api_root}/users/profiles/minecraft/{player_name}") if resp.status_code in [204, 404]: # No Content & Not Found return cls(existed=False) - return cls.parse_raw(resp.text) + return cls.model_validate_json(resp.text) @classmethod def getYggdrasilServer(cls, api_root: str, player_name: str): @@ -24,7 +24,7 @@ class YggdrasilGameProfileApi(model.YggdrasilGameProfileApiModel): @classmethod def get(cls, api_root: str, player_uuid: str): resp = httpx.get(f"{api_root}/session/minecraft/profile/{player_uuid}") - return cls.parse_raw(resp.text) + return cls.model_validate_json(resp.text) @classmethod def getYggdrasilServer(cls, api_root: str, player_uuid: str): diff --git a/src/yggdrasil_mc/ygg_async.py b/src/yggdrasil_mc/ygg_async.py index 849a9da..37b0949 100644 --- a/src/yggdrasil_mc/ygg_async.py +++ b/src/yggdrasil_mc/ygg_async.py @@ -12,7 +12,7 @@ async def get(cls, api_root: str, player_name: str): ) if resp.status_code in [204, 404]: # No Content & Not Found return cls(existed=False) - return cls.parse_raw(resp.text) + return cls.model_validate_json(resp.text) @classmethod async def getYggdrasilServer(cls, api_root: str, player_name: str): @@ -30,7 +30,7 @@ async def get(cls, api_root: str, player_uuid: str): resp = await client.get( f"{api_root}/session/minecraft/profile/{player_uuid}" ) - return cls.parse_raw(resp.text) + return cls.model_validate_json(resp.text) @classmethod async def getYggdrasilServer(cls, api_root: str, player_uuid: str):