🐛 Ensure cookie uid IntStr is int

This commit is contained in:
xtaodada 2025-01-10 22:48:14 +08:00
parent 409f0648fd
commit 2e9ea3e87b
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
2 changed files with 12 additions and 3 deletions

View File

@ -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",)

View File

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