Support query player when only player_id

This commit is contained in:
xtaodada 2024-07-12 21:54:01 +08:00
parent 549a40e8af
commit 0ae6a40433
Signed by: xtaodada
GPG Key ID: 4CBB3F4FA8C85659
4 changed files with 9 additions and 5 deletions

View File

@ -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]]:

View File

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

View File

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

View File

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