diff --git a/plugins/genshin/pay_log.py b/plugins/genshin/pay_log.py index 603ee9ca..b8e8f8c6 100644 --- a/plugins/genshin/pay_log.py +++ b/plugins/genshin/pay_log.py @@ -13,6 +13,7 @@ from modules.gacha_log.helpers import from_url_get_authkey from modules.pay_log.error import PayLogNotFound, PayLogAccountNotFound, PayLogInvalidAuthkey, PayLogAuthkeyTimeout from modules.pay_log.log import PayLog from plugins.tools.genshin import GenshinHelper, PlayerNotFoundError +from plugins.tools.player_info import PlayerInfoSystem from utils.genshin import get_authkey_by_stoken from utils.log import logger @@ -28,12 +29,14 @@ class PayLogPlugin(Plugin.Conversation): players_service: PlayersService, cookie_service: CookiesService, helper: GenshinHelper, + player_info: PlayerInfoSystem, ): self.template_service = template_service self.players_service = players_service self.cookie_service = cookie_service self.pay_log = PayLog() self.helper = helper + self.player_info = player_info async def _refresh_user_data(self, user: User, authkey: str = None) -> str: """刷新用户数据 @@ -214,8 +217,10 @@ 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) + data["name_card"] = name_card png_data = await self.template_service.render( - "genshin/pay_log/pay_log.html", data, full_page=True, query_selector=".container" + "genshin/pay_log/pay_log.jinja2", data, full_page=True, query_selector=".container" ) await png_data.reply_photo(message) except PayLogNotFound: diff --git a/plugins/genshin/wish_log.py b/plugins/genshin/wish_log.py index a5458b94..2ce52331 100644 --- a/plugins/genshin/wish_log.py +++ b/plugins/genshin/wish_log.py @@ -28,6 +28,7 @@ from modules.gacha_log.error import ( from modules.gacha_log.helpers import from_url_get_authkey from modules.gacha_log.log import GachaLog from plugins.tools.genshin import PlayerNotFoundError, GenshinHelper +from plugins.tools.player_info import PlayerInfoSystem from utils.genshin import get_authkey_by_stoken from utils.log import logger @@ -50,6 +51,7 @@ class WishLogPlugin(Plugin.Conversation): assets: AssetsService, cookie_service: CookiesService, helper: GenshinHelper, + player_info: PlayerInfoSystem, ): self.template_service = template_service self.players_service = players_service @@ -58,6 +60,7 @@ class WishLogPlugin(Plugin.Conversation): self.zh_dict = None self.gacha_log = GachaLog() self.helper = helper + self.player_info = player_info async def initialize(self) -> None: await update_paimon_moe_zh(False) @@ -318,9 +321,11 @@ 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) await message.reply_chat_action(ChatAction.UPLOAD_PHOTO) + data["name_card"] = name_card png_data = await self.template_service.render( - "genshin/gacha_log/gacha_log.html", + "genshin/wish_log/wish_log.jinja2", data, full_page=True, file_type=FileType.DOCUMENT if len(data.get("fiveLog")) > 36 else FileType.PHOTO, @@ -377,13 +382,15 @@ 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) document = False if data["hasMore"] and not group: document = True data["hasMore"] = False + data["name_card"] = name_card await message.reply_chat_action(ChatAction.UPLOAD_DOCUMENT if document else ChatAction.UPLOAD_PHOTO) png_data = await self.template_service.render( - "genshin/gacha_count/gacha_count.html", + "genshin/wish_count/wish_count.jinja2", data, full_page=True, query_selector=".body_box", diff --git a/plugins/tools/player_info.py b/plugins/tools/player_info.py new file mode 100644 index 00000000..387ee579 --- /dev/null +++ b/plugins/tools/player_info.py @@ -0,0 +1,40 @@ +from typing import TYPE_CHECKING, Optional + +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 + +if TYPE_CHECKING: + from telegram import User + + +class PlayerInfoSystem(Plugin): + def __init__( + self, + player_service: PlayersService = None, + assets_service: AssetsService = None, + player_info_service: PlayerInfoService = None, + ) -> None: + self.assets_service = assets_service + self.player_info_service = player_info_service + self.player_service = player_service + + async def get_player_info(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) + nickname = user.full_name + 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)] + if name_card is not None: # 默认 + name_card = (await self.assets_service.namecard(210001).navbar()).as_uri() + return name_card, avatar, nickname, rarity diff --git a/resources/genshin/pay_log/pay_log.html b/resources/genshin/pay_log/pay_log.jinja2 similarity index 96% rename from resources/genshin/pay_log/pay_log.html rename to resources/genshin/pay_log/pay_log.jinja2 index 59c38d92..fcfdbac8 100644 --- a/resources/genshin/pay_log/pay_log.html +++ b/resources/genshin/pay_log/pay_log.jinja2 @@ -5,10 +5,9 @@ - diff --git a/resources/genshin/gacha_count/example.html b/resources/genshin/wish_count/example.html similarity index 91% rename from resources/genshin/gacha_count/example.html rename to resources/genshin/wish_count/example.html index 9fddf2cb..eae2f55b 100644 --- a/resources/genshin/gacha_count/example.html +++ b/resources/genshin/wish_count/example.html @@ -3,7 +3,7 @@
- + @@ -11,7 +11,7 @@ diff --git a/resources/genshin/gacha_count/gacha_count.css b/resources/genshin/wish_count/wish_count.css similarity index 100% rename from resources/genshin/gacha_count/gacha_count.css rename to resources/genshin/wish_count/wish_count.css diff --git a/resources/genshin/gacha_count/gacha_count.html b/resources/genshin/wish_count/wish_count.jinja2 similarity index 93% rename from resources/genshin/gacha_count/gacha_count.html rename to resources/genshin/wish_count/wish_count.jinja2 index 02e28da0..431513c8 100644 --- a/resources/genshin/gacha_count/gacha_count.html +++ b/resources/genshin/wish_count/wish_count.jinja2 @@ -3,7 +3,7 @@ - + @@ -11,7 +11,7 @@ diff --git a/resources/genshin/gacha_log/example.html b/resources/genshin/wish_log/example.html similarity index 97% rename from resources/genshin/gacha_log/example.html rename to resources/genshin/wish_log/example.html index a3532781..d3523f78 100644 --- a/resources/genshin/gacha_log/example.html +++ b/resources/genshin/wish_log/example.html @@ -3,7 +3,7 @@ - + diff --git a/resources/genshin/gacha_log/img/提纳里.png b/resources/genshin/wish_log/img/提纳里.png similarity index 100% rename from resources/genshin/gacha_log/img/提纳里.png rename to resources/genshin/wish_log/img/提纳里.png diff --git a/resources/genshin/gacha_log/gacha_log.css b/resources/genshin/wish_log/wish_log.css similarity index 100% rename from resources/genshin/gacha_log/gacha_log.css rename to resources/genshin/wish_log/wish_log.css diff --git a/resources/genshin/gacha_log/gacha_log.html b/resources/genshin/wish_log/wish_log.jinja2 similarity index 56% rename from resources/genshin/gacha_log/gacha_log.html rename to resources/genshin/wish_log/wish_log.jinja2 index 36601c8a..58e5c115 100644 --- a/resources/genshin/gacha_log/gacha_log.html +++ b/resources/genshin/wish_log/wish_log.jinja2 @@ -3,15 +3,14 @@ - + @@ -27,7 +26,7 @@