mirror of
https://github.com/PaiGramTeam/GramCore.git
synced 2024-12-03 10:26:10 +00:00
✨ Support query player when only player_id
This commit is contained in:
parent
549a40e8af
commit
0ae6a40433
@ -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]]:
|
||||
|
@ -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
|
||||
|
@ -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:
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user