From 0ae6a4043375a50a011efd212d54bb6c9feb7b23 Mon Sep 17 00:00:00 2001 From: xtaodada Date: Fri, 12 Jul 2024 21:54:01 +0800 Subject: [PATCH] :sparkles: Support query player when only player_id --- plugin/methods/get_real_uid_or_offset.py | 2 +- services/players/models.py | 4 +++- services/players/repositories.py | 6 ++++-- services/players/services.py | 2 +- 4 files changed, 9 insertions(+), 5 deletions(-) diff --git a/plugin/methods/get_real_uid_or_offset.py b/plugin/methods/get_real_uid_or_offset.py index dc76622..ce67b61 100644 --- a/plugin/methods/get_real_uid_or_offset.py +++ b/plugin/methods/get_real_uid_or_offset.py @@ -4,7 +4,7 @@ from typing import TYPE_CHECKING, Optional, Tuple if TYPE_CHECKING: from telegram import Update -REGEX = r"@(\d{10})|@(\d{9})|@(\d)" +REGEX = r"@(\d{10})|@(\d{9})|@(\d{8})|@(\d)" def get_real_uid_or_offset_by_text(text: str) -> Tuple[Optional[int], Optional[int]]: diff --git a/services/players/models.py b/services/players/models.py index a480568..dfedfd4 100644 --- a/services/players/models.py +++ b/services/players/models.py @@ -12,7 +12,7 @@ try: except ImportError: import json as jsonlib -__all__ = ("Player", "PlayersDataBase", "PlayerInfo", "PlayerInfoSQLModel") +__all__ = ("Player", "PlayersDataBase", "PlayerInfo", "PlayerInfoSQLModel", "ExtraPlayerInfo") class Player(SQLModel): @@ -34,10 +34,12 @@ class PlayersDataBase(Player, table=True): class ExtraPlayerInfo(BaseModel): class Config(BaseSettings.Config): + frozen = False json_loads = jsonlib.loads json_dumps = jsonlib.dumps waifu_id: Optional[int] = None + level: Optional[int] = None class ExtraPlayerType(TypeDecorator): # pylint: disable=W0223 diff --git a/services/players/repositories.py b/services/players/repositories.py index c11ca4e..f962f21 100644 --- a/services/players/repositories.py +++ b/services/players/repositories.py @@ -18,7 +18,7 @@ class PlayersRepository(BaseService.Component): async def get( self, - user_id: int, + user_id: Optional[int] = None, player_id: Optional[int] = None, account_id: Optional[int] = None, region: Optional[RegionEnum] = None, @@ -26,7 +26,9 @@ class PlayersRepository(BaseService.Component): offset: int = 0, ) -> Optional[Player]: async with AsyncSession(self.engine) as session: - statement = select(Player).where(Player.user_id == user_id) + statement = select(Player) + if user_id is not None: + statement = statement.where(Player.user_id == user_id) if player_id is not None: statement = statement.where(Player.player_id == player_id) if account_id is not None: diff --git a/services/players/services.py b/services/players/services.py index 93711b2..ebf0626 100644 --- a/services/players/services.py +++ b/services/players/services.py @@ -14,7 +14,7 @@ class PlayersService(BaseService): async def get( self, - user_id: int, + user_id: Optional[int] = None, player_id: Optional[int] = None, account_id: Optional[int] = None, region: Optional[RegionEnum] = None,