mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-22 07:07:46 +00:00
✨ Add get_name_card
function
This commit is contained in:
parent
85178d34ae
commit
ca37f6948a
@ -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"
|
||||
|
@ -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
|
||||
|
@ -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,6 +28,7 @@ class PlayerInfoSystem(Plugin):
|
||||
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
|
||||
@ -34,7 +36,23 @@ class PlayerInfoSystem(Plugin):
|
||||
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)]
|
||||
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
|
||||
|
Loading…
Reference in New Issue
Block a user