mirror of
https://github.com/PaiGramTeam/MibooGram.git
synced 2024-11-21 22:58:20 +00:00
🐛 Fix new uid length when mask number
This commit is contained in:
parent
7864859377
commit
2b24da0dde
@ -243,6 +243,9 @@ class _AvatarAssets(_AssetsService):
|
|||||||
gacha_card: ICON_TYPE
|
gacha_card: ICON_TYPE
|
||||||
"""抽卡卡片"""
|
"""抽卡卡片"""
|
||||||
|
|
||||||
|
AVATAR_DEFAULT: int = 10000005
|
||||||
|
"""默认角色ID"""
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def game_name(self) -> str:
|
def game_name(self) -> str:
|
||||||
icon = "UI_AvatarIcon_"
|
icon = "UI_AvatarIcon_"
|
||||||
@ -269,6 +272,8 @@ class _AvatarAssets(_AssetsService):
|
|||||||
self._enka_api = enka or DEFAULT_EnkaAssets
|
self._enka_api = enka or DEFAULT_EnkaAssets
|
||||||
|
|
||||||
def __call__(self, target: StrOrInt) -> "_AvatarAssets":
|
def __call__(self, target: StrOrInt) -> "_AvatarAssets":
|
||||||
|
if target == 0:
|
||||||
|
target = self.AVATAR_DEFAULT
|
||||||
temp = target
|
temp = target
|
||||||
result = _AvatarAssets(self.client)
|
result = _AvatarAssets(self.client)
|
||||||
if isinstance(target, str):
|
if isinstance(target, str):
|
||||||
|
@ -15,9 +15,9 @@ from core.services.players import PlayersService
|
|||||||
from core.services.players.services import PlayerInfoService
|
from core.services.players.services import PlayerInfoService
|
||||||
from core.services.template.models import FileType
|
from core.services.template.models import FileType
|
||||||
from core.services.template.services import TemplateService
|
from core.services.template.services import TemplateService
|
||||||
from metadata.genshin import AVATAR_DATA
|
|
||||||
from modules.wiki.base import Model
|
from modules.wiki.base import Model
|
||||||
from plugins.tools.genshin import CharacterDetails, GenshinHelper
|
from plugins.tools.genshin import CharacterDetails, GenshinHelper
|
||||||
|
from plugins.tools.player_info import PlayerInfoSystem
|
||||||
from utils.log import logger
|
from utils.log import logger
|
||||||
from utils.uid import mask_number
|
from utils.uid import mask_number
|
||||||
|
|
||||||
@ -62,6 +62,7 @@ class AvatarListPlugin(Plugin):
|
|||||||
helper: GenshinHelper = None,
|
helper: GenshinHelper = None,
|
||||||
character_details: CharacterDetails = None,
|
character_details: CharacterDetails = None,
|
||||||
player_info_service: PlayerInfoService = None,
|
player_info_service: PlayerInfoService = None,
|
||||||
|
player_info_system: PlayerInfoSystem = None,
|
||||||
) -> None:
|
) -> None:
|
||||||
self.cookies_service = cookies_service
|
self.cookies_service = cookies_service
|
||||||
self.assets_service = assets_service
|
self.assets_service = assets_service
|
||||||
@ -70,6 +71,7 @@ class AvatarListPlugin(Plugin):
|
|||||||
self.character_details = character_details
|
self.character_details = character_details
|
||||||
self.player_service = player_service
|
self.player_service = player_service
|
||||||
self.player_info_service = player_info_service
|
self.player_info_service = player_info_service
|
||||||
|
self.player_info_system = player_info_system
|
||||||
|
|
||||||
async def get_avatar_data(self, character: Character, client: "GenshinClient") -> Optional["AvatarData"]:
|
async def get_avatar_data(self, character: Character, client: "GenshinClient") -> Optional["AvatarData"]:
|
||||||
detail = await self.character_details.get_character_details(client, character)
|
detail = await self.character_details.get_character_details(client, character)
|
||||||
@ -131,31 +133,6 @@ class AvatarListPlugin(Plugin):
|
|||||||
reverse=True,
|
reverse=True,
|
||||||
)[:max_length]
|
)[:max_length]
|
||||||
|
|
||||||
async def get_final_data(self, player_id: int, user_id: int, user_name: str):
|
|
||||||
player = await self.player_service.get(user_id, player_id)
|
|
||||||
player_info = await self.player_info_service.get(player)
|
|
||||||
nickname = user_name
|
|
||||||
name_card: Optional[str] = None
|
|
||||||
avatar: Optional[str] = None
|
|
||||||
rarity: int = 5
|
|
||||||
try:
|
|
||||||
if player_info is not None:
|
|
||||||
if player_info.nickname is not None:
|
|
||||||
nickname = player_info.nickname
|
|
||||||
if player_info.name_card is not None:
|
|
||||||
name_card = (await self.assets_service.namecard(int(player_info.name_card)).navbar()).as_uri()
|
|
||||||
if player_info.hand_image is not None:
|
|
||||||
avatar = (await self.assets_service.avatar(player_info.hand_image).icon()).as_uri()
|
|
||||||
try:
|
|
||||||
rarity = {k: v["rank"] for k, v in AVATAR_DATA.items()}[str(player_info.hand_image)]
|
|
||||||
except KeyError:
|
|
||||||
logger.warning("未找到角色 %s 的星级", player_info.hand_image)
|
|
||||||
except Exception as exc: # pylint: disable=W0703
|
|
||||||
logger.error("卡片信息请求失败 %s", str(exc))
|
|
||||||
if name_card is None: # 默认
|
|
||||||
name_card = (await self.assets_service.namecard(0).navbar()).as_uri()
|
|
||||||
return name_card, avatar, nickname, rarity
|
|
||||||
|
|
||||||
@handler.command("avatars", cookie=True, block=False)
|
@handler.command("avatars", cookie=True, block=False)
|
||||||
@handler.message(filters.Regex(r"^(全部)?练度统计$"), cookie=True, block=False)
|
@handler.message(filters.Regex(r"^(全部)?练度统计$"), cookie=True, block=False)
|
||||||
async def avatar_list(self, update: "Update", _: "ContextTypes.DEFAULT_TYPE"):
|
async def avatar_list(self, update: "Update", _: "ContextTypes.DEFAULT_TYPE"):
|
||||||
@ -183,7 +160,9 @@ class AvatarListPlugin(Plugin):
|
|||||||
return
|
return
|
||||||
raise e
|
raise e
|
||||||
|
|
||||||
name_card, avatar, nickname, rarity = await self.get_final_data(client.player_id, user_id, user_name)
|
name_card, avatar, nickname, rarity = await self.player_info_system.get_player_info(
|
||||||
|
client.player_id, user_id, user_name
|
||||||
|
)
|
||||||
|
|
||||||
render_data = {
|
render_data = {
|
||||||
"uid": mask_number(client.player_id), # 玩家uid
|
"uid": mask_number(client.player_id), # 玩家uid
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from typing import TYPE_CHECKING, Optional
|
from typing import Optional
|
||||||
|
|
||||||
from core.dependence.assets import AssetsService
|
from core.dependence.assets import AssetsService
|
||||||
from core.plugin import Plugin
|
from core.plugin import Plugin
|
||||||
@ -6,9 +6,6 @@ from core.services.players.services import PlayerInfoService, PlayersService
|
|||||||
from metadata.genshin import AVATAR_DATA
|
from metadata.genshin import AVATAR_DATA
|
||||||
from utils.log import logger
|
from utils.log import logger
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
|
||||||
from telegram import User
|
|
||||||
|
|
||||||
|
|
||||||
class PlayerInfoSystem(Plugin):
|
class PlayerInfoSystem(Plugin):
|
||||||
def __init__(
|
def __init__(
|
||||||
@ -21,10 +18,10 @@ class PlayerInfoSystem(Plugin):
|
|||||||
self.player_info_service = player_info_service
|
self.player_info_service = player_info_service
|
||||||
self.player_service = player_service
|
self.player_service = player_service
|
||||||
|
|
||||||
async def get_player_info(self, player_id: int, user: "User"):
|
async def get_player_info(self, player_id: int, user_id: int, user_name: str):
|
||||||
player = await self.player_service.get(user.id, player_id)
|
player = await self.player_service.get(user_id, player_id)
|
||||||
player_info = await self.player_info_service.get(player)
|
player_info = await self.player_info_service.get(player)
|
||||||
nickname = user.full_name
|
nickname = user_name
|
||||||
name_card: Optional[str] = None
|
name_card: Optional[str] = None
|
||||||
avatar: Optional[str] = None
|
avatar: Optional[str] = None
|
||||||
rarity: int = 5
|
rarity: int = 5
|
||||||
@ -39,11 +36,13 @@ class PlayerInfoSystem(Plugin):
|
|||||||
try:
|
try:
|
||||||
rarity = {k: v["rank"] for k, v in AVATAR_DATA.items()}[str(player_info.hand_image)]
|
rarity = {k: v["rank"] for k, v in AVATAR_DATA.items()}[str(player_info.hand_image)]
|
||||||
except KeyError:
|
except KeyError:
|
||||||
logger.warning("未找到角色 %s 的等级", player_info.hand_image)
|
logger.warning("未找到角色 %s 的星级", player_info.hand_image)
|
||||||
except Exception as exc: # pylint: disable=W0703
|
except Exception as exc: # pylint: disable=W0703
|
||||||
logger.error("卡片信息请求失败 %s", str(exc))
|
logger.error("卡片信息请求失败 %s", str(exc))
|
||||||
if name_card is None: # 默认
|
if name_card is None: # 默认
|
||||||
name_card = (await self.assets_service.namecard(0).navbar()).as_uri()
|
name_card = (await self.assets_service.namecard(0).navbar()).as_uri()
|
||||||
|
if avatar is None: # 默认
|
||||||
|
avatar = (await self.assets_service.avatar(0).icon()).as_uri()
|
||||||
return name_card, avatar, nickname, rarity
|
return name_card, avatar, nickname, rarity
|
||||||
|
|
||||||
async def get_name_card(self, player_id: int, user_id: int):
|
async def get_name_card(self, player_id: int, user_id: int):
|
||||||
|
@ -3,7 +3,11 @@ import re
|
|||||||
|
|
||||||
def mask_number(number):
|
def mask_number(number):
|
||||||
number_str = str(number)
|
number_str = str(number)
|
||||||
|
masked_number = None
|
||||||
if len(number_str) == 9:
|
if len(number_str) == 9:
|
||||||
masked_number = re.sub(r"(\d{2})(\d{4})(\d{3})", r"\1****\3", number_str)
|
masked_number = re.sub(r"(\d{2})(\d{4})(\d{3})", r"\1****\3", number_str)
|
||||||
|
if len(number_str) == 10:
|
||||||
|
masked_number = re.sub(r"(\d{3})(\d{4})(\d{3})", r"\1****\3", number_str)
|
||||||
|
if masked_number:
|
||||||
return masked_number
|
return masked_number
|
||||||
return "Invalid input"
|
return "Invalid input"
|
||||||
|
Loading…
Reference in New Issue
Block a user