Support name card

This commit is contained in:
洛水居室 2023-04-28 09:19:20 +08:00 committed by GitHub
parent dfe58215ae
commit fa1e84bea9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
11 changed files with 85 additions and 35 deletions

View File

@ -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:

View File

@ -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",

View File

@ -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

View File

@ -5,10 +5,9 @@
<link rel="shortcut icon" href="#" />
<link rel="stylesheet" type="text/css" href="pay_log.css" />
<link rel="preload" href="../../fonts/tttgbnumber.ttf" as="font">
<link rel="preload" href="../gacha_log/img/提纳里.png" as="image">
<style>
.head_box {
background: #fff url(../gacha_log/img/提纳里.png) no-repeat right center;
background: #fff url('{{ name_card }}') no-repeat right center;
background-size: cover;
}
</style>

View File

@ -3,7 +3,7 @@
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<link rel="shortcut icon" href="#"/>
<link rel="stylesheet" type="text/css" href="gacha_count.css"/>
<link rel="stylesheet" type="text/css" href="wish_count.css"/>
<link rel="preload" href="../../fonts/HYWenHei-85W.ttf" as="font">
<link rel="preload" href="./../../fonts/tttgbnumber.ttf" as="font">
<link rel="preload" href="./../abyss/background/roleStarBg5.png" as="image">
@ -11,7 +11,7 @@
<style>
.head_box {
background-position-x: 42px;
background: #fff url(../gacha_log/img/提纳里.png) no-repeat;
background: #fff url(../wish_log/img/提纳里.png) no-repeat;
background-size: auto 101%;
}
</style>

View File

@ -3,7 +3,7 @@
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<link rel="shortcut icon" href="#"/>
<link rel="stylesheet" type="text/css" href="gacha_count.css"/>
<link rel="stylesheet" type="text/css" href="wish_count.css"/>
<link rel="preload" href="../../fonts/HYWenHei-85W.ttf" as="font">
<link rel="preload" href="./../../fonts/tttgbnumber.ttf" as="font">
<link rel="preload" href="./../abyss/background/roleStarBg5.png" as="image">
@ -11,7 +11,7 @@
<style>
.head_box {
background-position-x: 42px;
background: #fff url(../gacha_log/img/提纳里.png) no-repeat;
background: #fff url('{{ name_card }}') no-repeat right center;
background-size: auto 101%;
}
</style>

View File

@ -3,7 +3,7 @@
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<link rel="shortcut icon" href="#"/>
<link rel="stylesheet" type="text/css" href="gacha_log.css"/>
<link rel="stylesheet" type="text/css" href="wish_log.css"/>
<link rel="preload" href="./../../fonts/tttgbnumber.ttf" as="font">
<link rel="preload" href="./img/提纳里.png" as="image">
<link rel="preload" href="./../abyss/background/roleStarBg5.png" as="image">

View File

Before

Width:  |  Height:  |  Size: 47 KiB

After

Width:  |  Height:  |  Size: 47 KiB

View File

@ -3,15 +3,14 @@
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8"/>
<link rel="shortcut icon" href="#"/>
<link rel="stylesheet" type="text/css" href="gacha_log.css"/>
<link rel="stylesheet" type="text/css" href="wish_log.css"/>
<link rel="preload" href="./../../fonts/tttgbnumber.ttf" as="font">
<link rel="preload" href="./img/提纳里.png" as="image">
<link rel="preload" href="./../abyss/background/roleStarBg5.png" as="image">
<link rel="preload" href="./../abyss/background/roleStarBg4.png" as="image">
<style>
.head_box {
background-position: right center;
background: #fff url(./img/提纳里.png) no-repeat;
background: #fff url('{{ name_card }}') no-repeat right center;
background-size: cover;
}
</style>
@ -27,7 +26,7 @@
</div>
<h2 class="day_text">
{{ allNum }}抽
<span class="label label_{{type}}">{{ typeName }}</span>
<span class="label label_{{ type }}">{{ typeName }}</span>
</h2>
<img class="genshin_logo" src="./../../bot/help/background/genshin.png" alt=""/>
</div>
@ -38,8 +37,8 @@
<div class="data_line">
{% for item in val %}
<div class="data_line_item">
<div class="num">{{item.num}}<span class="unit">{{item.unit}}</span></div>
<div class="lable">{{item.lable}}</div>
<div class="num">{{ item.num }}<span class="unit">{{ item.unit }}</span></div>
<div class="lable">{{ item.lable }}</div>
</div>
{% endfor %}
</div>
@ -47,7 +46,7 @@
<div class="line_box">
<span class="line"></span>
<span class="text">五星历史 {{firstTime}} ~ {{lastTime}}</span>
<span class="text">五星历史 {{ firstTime }} ~ {{ lastTime }}</span>
<span class="line"></span>
</div>