From 6e8f29786ef2018a660ae5ec0a1b35b8c4bc7911 Mon Sep 17 00:00:00 2001 From: SiHuaN Date: Fri, 28 Oct 2022 15:58:07 +0800 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20talent=20levels=20to=20daily?= =?UTF-8?q?=20materials?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: kotoriのねこ --- plugins/genshin/daily/material.py | 32 ++++++++++++++++++- .../genshin/daily_material/character.html | 5 +++ resources/genshin/daily_material/example.html | 24 ++++++++++++++ resources/genshin/daily_material/style.css | 17 ++++++++++ 4 files changed, 77 insertions(+), 1 deletion(-) diff --git a/plugins/genshin/daily/material.py b/plugins/genshin/daily/material.py index e2bb1b29..889b8a8a 100644 --- a/plugins/genshin/daily/material.py +++ b/plugins/genshin/daily/material.py @@ -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 # 武器使用者图标 diff --git a/resources/genshin/daily_material/character.html b/resources/genshin/daily_material/character.html index 2df4295c..baf1f4fe 100644 --- a/resources/genshin/daily_material/character.html +++ b/resources/genshin/daily_material/character.html @@ -67,6 +67,11 @@ {% endif %} {% endif %} {{ item.name }} + {% if item.level != none and item.skills != none %} +
+ {{ item.skills[0] }}/{{ item.skills[1] }}/{{ item.skills[2] }} +
+ {% endif %}
{{ item.name }}
diff --git a/resources/genshin/daily_material/example.html b/resources/genshin/daily_material/example.html index 9a36269e..c90499db 100644 --- a/resources/genshin/daily_material/example.html +++ b/resources/genshin/daily_material/example.html @@ -76,6 +76,9 @@
Lv.90
6命
八重神子 +
+ 10/10/10 +
八重神子
@@ -86,6 +89,9 @@
Lv.90
6命
神里绫华 +
+ 10/10/10 +
神里绫华
@@ -96,6 +102,9 @@
Lv.90
6命
神里绫华 +
+ 10/10/10 +
神里绫华
@@ -105,6 +114,9 @@
Lv.90
神里绫华 +
+ 10/10/10 +
神里绫华
@@ -188,6 +200,9 @@
Lv.90
6命
神里绫华 +
+ 10/10/10 +
神里绫华
@@ -198,6 +213,9 @@
Lv.90
6命
神里绫华 +
+ 10/10/10 +
神里绫华
@@ -208,6 +226,9 @@
Lv.90
6命
神里绫华 +
+ 10/10/10 +
神里绫华
@@ -217,6 +238,9 @@
Lv.90
神里绫华 +
+ 10/10/10 +
神里绫华
diff --git a/resources/genshin/daily_material/style.css b/resources/genshin/daily_material/style.css index 91a64047..0b80b0c8 100644 --- a/resources/genshin/daily_material/style.css +++ b/resources/genshin/daily_material/style.css @@ -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;