From 2e9ea3e87b22feaacf6e885e15136e1b019d6f13 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 10 Jan 2025 22:48:14 +0800 Subject: [PATCH] :bug: Ensure cookie uid IntStr is int --- modules/apihelper/models/genshin/cookies.py | 13 ++++++++++--- plugins/account/cookies.py | 2 ++ 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/modules/apihelper/models/genshin/cookies.py b/modules/apihelper/models/genshin/cookies.py index 9389dbb..461acc4 100644 --- a/modules/apihelper/models/genshin/cookies.py +++ b/modules/apihelper/models/genshin/cookies.py @@ -1,8 +1,15 @@ -from typing import Optional, TypeVar +from typing import Optional, Annotated, Union -from pydantic import BaseModel +from pydantic import BaseModel, BeforeValidator -IntStr = TypeVar("IntStr", int, str) + +def int_str_check(value: Union[int, str]) -> Union[int, str]: + if value is not None: + int(value) + return value + + +IntStr = Annotated[Union[int, str], BeforeValidator(int_str_check)] __all__ = ("CookiesModel",) diff --git a/plugins/account/cookies.py b/plugins/account/cookies.py index cff8625..cfadaf0 100644 --- a/plugins/account/cookies.py +++ b/plugins/account/cookies.py @@ -205,6 +205,8 @@ class AccountCookiesPlugin(Plugin.Conversation): ) cookie = {x[0]: x[1] for x in wrapped} cookies = self.parse_cookie(cookie) + if cookies: + CookiesModel.model_validate(cookies) except (AttributeError, ValueError, IndexError) as exc: logger.info("用户 %s[%s] Cookies解析出现错误\ntext:%s", user.full_name, user.id, message.text) logger.debug("解析Cookies出现错误", exc_info=exc)