Add talent levels to daily materials

Co-authored-by: kotoriのねこ <minamiktr@outlook.com>
This commit is contained in:
SiHuaN 2022-10-28 15:58:07 +08:00 committed by 洛水居室
parent fe9c1261a0
commit 6e8f29786e
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC
4 changed files with 77 additions and 1 deletions

View File

@ -15,7 +15,7 @@ import ujson as json
from aiofiles import open as async_open
from arkowrapper import ArkoWrapper
from bs4 import BeautifulSoup
from genshin import Client, InvalidCookies
from genshin import Client, InvalidCookies, GenshinException
from httpx import AsyncClient, HTTPError
from pydantic import BaseModel
from telegram import Message, Update, User
@ -127,6 +127,30 @@ class DailyMaterial(Plugin, BasePlugin):
data = json.loads(await file.read())
self.data = data
@staticmethod
async def _get_skills_data(client: Client, character_id: int) -> Optional[List[int]]:
detail = None
for _ in range(5):
try:
detail = await client.get_character_details(character_id)
except Exception as e: # pylint: disable=W0703
logger.warning(f"daily_material 解析角色 id 为 [bold]{character_id}[/]的数据时遇到了错误:{e}", extra={"markup": True})
if isinstance(e, GenshinException) and "Too Many Requests" in e.msg:
await asyncio.sleep(0.2)
continue
# 输入数据不可能是旅行者
# if character.name != "旅行者":
# raise e
# logger.debug(f"解析旅行者数据时遇到了错误:{e}")
else:
break
if not detail:
return None
# 不用针对旅行者、草主进行特殊处理,因为输入数据不会有旅行者。
# 不用计算命座加成因为这个是展示天赋升级情况10 级为最高。计算命座会引起混淆。
talents = [t for t in detail.talents if t.type in ["attack", "skill", "burst"]]
return [t.level for t in talents]
async def _get_data_from_user(self, user: User) -> Tuple[Optional[Client], Dict[str, List[Any]]]:
"""获取已经绑定的账号的角色、武器信息"""
client = None
@ -148,6 +172,7 @@ class DailyMaterial(Plugin, BasePlugin):
rarity=character.rarity,
level=character.level,
constellation=character.constellation,
gid=character.id,
icon=(await self.assets_service.avatar(cid).icon()).as_uri(),
)
)
@ -237,6 +262,9 @@ class DailyMaterial(Plugin, BasePlugin):
for i in user_data[type_]: # 从已经获取的角色数据中查找对应角色、武器
if id_ == str(i.id):
if i.rarity > 3: # 跳过 3 星及以下的武器
if type_ == "avatar": # 给角色添加天赋信息
skills = await self._get_skills_data(client, i.gid)
i.skills = skills
items.append(i)
added = True
if added:
@ -445,6 +473,8 @@ class ItemData(BaseModel):
icon: str # 图标
level: Optional[int] = None # 等级
constellation: Optional[int] = None # 命座
skills: Optional[List[int]] = None # 天赋等级
gid: Optional[int] = None # 角色在 genshin.py 里的 ID
refinement: Optional[int] = None # 精炼度
c_path: Optional[str] = None # 武器使用者图标

View File

@ -67,6 +67,11 @@
{% endif %}
{% endif %}
<img src="{{ item.icon }}" alt="{{ item.name }}"/>
{% if item.level != none and item.skills != none %}
<div class="item-icon-character-talent">
<span>{{ item.skills[0] }}/{{ item.skills[1] }}/{{ item.skills[2] }}</span>
</div>
{% endif %}
</div>
<div class="item-name">
<div>{{ item.name }}</div>

View File

@ -76,6 +76,9 @@
<div>Lv.90</div>
<div style="background-color: rgba(255, 20, 147, 0.8); backdrop-filter: blur(3px);">6命</div>
<img src="../../assets/avatar/10000058/icon.png" alt="八重神子"/>
<div class="item-icon-character-talent">
<span>10/10/10</span>
</div>
</div>
<div class="item-name">
<div>八重神子</div>
@ -86,6 +89,9 @@
<div>Lv.90</div>
<div style="background-color: rgba(255, 20, 147, 0.8); backdrop-filter: blur(3px);">6命</div>
<img src="../../assets/avatar/10000002/icon.png" alt="神里绫华"/>
<div class="item-icon-character-talent">
<span>10/10/10</span>
</div>
</div>
<div class="item-name">
<div>神里绫华</div>
@ -96,6 +102,9 @@
<div>Lv.90</div>
<div style="background-color: rgba(255, 20, 147, 0.8); backdrop-filter: blur(3px);">6命</div>
<img src="../../assets/avatar/10000002/icon.png" alt="神里绫华"/>
<div class="item-icon-character-talent">
<span>10/10/10</span>
</div>
</div>
<div class="item-name">
<div>神里绫华</div>
@ -105,6 +114,9 @@
<div class="item-icon" style="background-image: url(../../background/rarity/full/5.png)">
<div>Lv.90</div>
<img src="../../assets/avatar/10000002/icon.png" alt="神里绫华"/>
<div class="item-icon-character-talent">
<span>10/10/10</span>
</div>
</div>
<div class="item-name">
<div>神里绫华</div>
@ -188,6 +200,9 @@
<div>Lv.90</div>
<div style="background-color: rgba(255, 20, 147, 0.8); backdrop-filter: blur(3px);">6命</div>
<img src="../../assets/avatar/10000058/icon.png" alt="神里绫华"/>
<div class="item-icon-character-talent">
<span>10/10/10</span>
</div>
</div>
<div class="item-name">
<div>神里绫华</div>
@ -198,6 +213,9 @@
<div>Lv.90</div>
<div style="background-color: rgba(255, 20, 147, 0.8); backdrop-filter: blur(3px);">6命</div>
<img src="../../assets/avatar/10000002/icon.png" alt="神里绫华"/>
<div class="item-icon-character-talent">
<span>10/10/10</span>
</div>
</div>
<div class="item-name">
<div>神里绫华</div>
@ -208,6 +226,9 @@
<div>Lv.90</div>
<div style="background-color: rgba(255, 20, 147, 0.8); backdrop-filter: blur(3px);">6命</div>
<img src="../../assets/avatar/10000002/icon.png" alt="神里绫华"/>
<div class="item-icon-character-talent">
<span>10/10/10</span>
</div>
</div>
<div class="item-name">
<div>神里绫华</div>
@ -217,6 +238,9 @@
<div class="item-icon" style="background-image: url(../../background/rarity/full/5.png)">
<div>Lv.90</div>
<img src="../../assets/avatar/10000002/icon.png" alt="神里绫华"/>
<div class="item-icon-character-talent">
<span>10/10/10</span>
</div>
</div>
<div class="item-name">
<div>神里绫华</div>

View File

@ -244,6 +244,23 @@ body {
transform: translateX(-50%) translateY(-50%);
}
.item-icon-character-talent {
position: absolute;
padding: 4px;
bottom: 0;
left: 0;
background-color: rgba(100, 149, 237, 0.7);
backdrop-filter: blur(3px);
border-radius: 0 5px 0 0;
box-shadow: 1px 1px 5px var(--shadow);
}
.item-icon-character-talent > span {
color: white;
font-size: 14px;
letter-spacing: 0.05em;
}
.item-name {
text-align: center;
display: flex;