diff --git a/plugins/genshin/pay_log.py b/plugins/genshin/pay_log.py index b8e8f8c6..fbcc2f3e 100644 --- a/plugins/genshin/pay_log.py +++ b/plugins/genshin/pay_log.py @@ -217,7 +217,7 @@ class PayLogPlugin(Plugin.Conversation): await message.reply_chat_action(ChatAction.TYPING) data = await self.pay_log.get_analysis(user.id, client) await message.reply_chat_action(ChatAction.UPLOAD_PHOTO) - name_card, _, _, _ = await self.player_info.get_player_info(client.uid, user) + name_card = await self.player_info.get_name_card(client.uid, user) data["name_card"] = name_card png_data = await self.template_service.render( "genshin/pay_log/pay_log.jinja2", data, full_page=True, query_selector=".container" diff --git a/plugins/genshin/wish_log.py b/plugins/genshin/wish_log.py index 2ce52331..0861807a 100644 --- a/plugins/genshin/wish_log.py +++ b/plugins/genshin/wish_log.py @@ -321,7 +321,7 @@ class WishLogPlugin(Plugin.Conversation): self.add_delete_message_job(reply_message, delay=300) self.add_delete_message_job(message, delay=300) else: - name_card, _, _, _ = await self.player_info.get_player_info(client.uid, user) + name_card = await self.player_info.get_name_card(client.uid, user) await message.reply_chat_action(ChatAction.UPLOAD_PHOTO) data["name_card"] = name_card png_data = await self.template_service.render( @@ -382,7 +382,7 @@ class WishLogPlugin(Plugin.Conversation): self.add_delete_message_job(reply_message) self.add_delete_message_job(message) else: - name_card, _, _, _ = await self.player_info.get_player_info(client.uid, user) + name_card = await self.player_info.get_name_card(client.uid, user) document = False if data["hasMore"] and not group: document = True diff --git a/plugins/tools/player_info.py b/plugins/tools/player_info.py index 387ee579..de92efb5 100644 --- a/plugins/tools/player_info.py +++ b/plugins/tools/player_info.py @@ -4,6 +4,7 @@ from core.dependence.assets import AssetsService from core.plugin import Plugin from core.services.players.services import PlayerInfoService, PlayersService from metadata.genshin import AVATAR_DATA +from utils.log import logger if TYPE_CHECKING: from telegram import User @@ -27,14 +28,31 @@ class PlayerInfoSystem(Plugin): name_card: Optional[str] = None avatar: Optional[str] = None rarity: int = 5 - 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() - rarity = {k: v["rank"] for k, v in AVATAR_DATA.items()}[str(player_info.hand_image)] + 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() + rarity = {k: v["rank"] for k, v in AVATAR_DATA.items()}[player_info.hand_image] + except Exception as exc: # pylint: disable=W0703 + logger.error("卡片信息请求失败 %s", str(exc)) if name_card is not None: # 默认 name_card = (await self.assets_service.namecard(210001).navbar()).as_uri() return name_card, avatar, nickname, rarity + + async def get_name_card(self, player_id: int, user: "User"): + player = await self.player_service.get(user.id, player_id) + player_info = await self.player_info_service.get(player) + name_card: Optional[str] = None + try: + if player_info is not None: + if player_info.name_card is not None: + name_card = (await self.assets_service.namecard(int(player_info.name_card)).navbar()).as_uri() + except Exception as exc: # pylint: disable=W0703 + logger.error("卡片信息请求失败 %s", str(exc)) + if name_card is not None: # 默认 + name_card = (await self.assets_service.namecard(210001).navbar()).as_uri() + return name_card