mirror of
https://github.com/PaiGramTeam/PaiGram.git
synced 2024-11-25 18:04:10 +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)
|
await message.reply_chat_action(ChatAction.TYPING)
|
||||||
data = await self.pay_log.get_analysis(user.id, client)
|
data = await self.pay_log.get_analysis(user.id, client)
|
||||||
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
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
|
data["name_card"] = name_card
|
||||||
png_data = await self.template_service.render(
|
png_data = await self.template_service.render(
|
||||||
"genshin/pay_log/pay_log.jinja2", data, full_page=True, query_selector=".container"
|
"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(reply_message, delay=300)
|
||||||
self.add_delete_message_job(message, delay=300)
|
self.add_delete_message_job(message, delay=300)
|
||||||
else:
|
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)
|
await message.reply_chat_action(ChatAction.UPLOAD_PHOTO)
|
||||||
data["name_card"] = name_card
|
data["name_card"] = name_card
|
||||||
png_data = await self.template_service.render(
|
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(reply_message)
|
||||||
self.add_delete_message_job(message)
|
self.add_delete_message_job(message)
|
||||||
else:
|
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
|
document = False
|
||||||
if data["hasMore"] and not group:
|
if data["hasMore"] and not group:
|
||||||
document = True
|
document = True
|
||||||
|
@ -4,6 +4,7 @@ from core.dependence.assets import AssetsService
|
|||||||
from core.plugin import Plugin
|
from core.plugin import Plugin
|
||||||
from core.services.players.services import PlayerInfoService, PlayersService
|
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
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from telegram import User
|
from telegram import User
|
||||||
@ -27,6 +28,7 @@ class PlayerInfoSystem(Plugin):
|
|||||||
name_card: Optional[str] = None
|
name_card: Optional[str] = None
|
||||||
avatar: Optional[str] = None
|
avatar: Optional[str] = None
|
||||||
rarity: int = 5
|
rarity: int = 5
|
||||||
|
try:
|
||||||
if player_info is not None:
|
if player_info is not None:
|
||||||
if player_info.nickname is not None:
|
if player_info.nickname is not None:
|
||||||
nickname = player_info.nickname
|
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()
|
name_card = (await self.assets_service.namecard(int(player_info.name_card)).navbar()).as_uri()
|
||||||
if player_info.hand_image is not None:
|
if player_info.hand_image is not None:
|
||||||
avatar = (await self.assets_service.avatar(player_info.hand_image).icon()).as_uri()
|
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: # 默认
|
if name_card is not None: # 默认
|
||||||
name_card = (await self.assets_service.namecard(210001).navbar()).as_uri()
|
name_card = (await self.assets_service.namecard(210001).navbar()).as_uri()
|
||||||
return name_card, avatar, nickname, rarity
|
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