mirror of
https://github.com/PaiGramTeam/MibooGram.git
synced 2024-11-16 04:45:27 +00:00
🐛 avatar 修复错误
This commit is contained in:
parent
5b09ccdf76
commit
adec83108a
@ -69,11 +69,10 @@ class AvatarListPlugin(Plugin, BasePlugin):
|
||||
try:
|
||||
detail = await client.get_character_details(character)
|
||||
except Exception as e: # pylint: disable=W0703
|
||||
if character.name == "旅行者":
|
||||
logger.debug(f"解析旅行者数据时遇到了错误:{e}")
|
||||
continue
|
||||
else:
|
||||
if character.name != "旅行者":
|
||||
raise e
|
||||
logger.debug(f"解析旅行者数据时遇到了错误:{e}")
|
||||
continue
|
||||
if character.id == 10000005: # 针对男草主
|
||||
talents = []
|
||||
for talent in detail.talents:
|
||||
@ -139,6 +138,17 @@ class AvatarListPlugin(Plugin, BasePlugin):
|
||||
rarity = {k: v["rank"] for k, v in AVATAR_DATA.items()}[str(cid)]
|
||||
return namecard, avatar, nickname, rarity
|
||||
|
||||
async def get_default_final_data(self, characters: Sequence[Character], update: Update):
|
||||
nickname = update.effective_user.full_name
|
||||
rarity = 5
|
||||
# 须弥·正明
|
||||
namecard = (await self.assets_service.namecard(210132).navbar()).as_uri()
|
||||
if traveller := next(filter(lambda x: x.id in [10000005, 10000007], characters), None):
|
||||
avatar = (await self.assets_service.avatar(traveller.id).icon()).as_uri()
|
||||
else:
|
||||
avatar = (await self.assets_service.avatar(10000005).icon()).as_uri()
|
||||
return namecard, avatar, nickname, rarity
|
||||
|
||||
@handler.command("avatars", filters.Regex(r"^/avatars\s*(?:(\d+)|(all))?$"))
|
||||
@handler.message(filters.Regex(r"^(全部)?练度统计$"))
|
||||
@restricts(30)
|
||||
@ -147,9 +157,9 @@ class AvatarListPlugin(Plugin, BasePlugin):
|
||||
user = update.effective_user
|
||||
message = update.effective_message
|
||||
|
||||
args = context.match
|
||||
args = [i.lower() for i in context.match.groups() if i]
|
||||
|
||||
all_avatars = any(["all" in args.groups(), "全部" in args.groups()]) # 是否发送全部角色
|
||||
all_avatars = any(["all" in args, "全部" in args]) # 是否发送全部角色
|
||||
|
||||
logger.info(f"用户 {user.full_name}[{user.id}] [bold]练度统计[/bold]: all={all_avatars}", extra={"markup": True})
|
||||
|
||||
@ -174,7 +184,11 @@ class AvatarListPlugin(Plugin, BasePlugin):
|
||||
return
|
||||
raise e
|
||||
|
||||
namecard, avatar, nickname, rarity = await self.get_final_data(client, characters, update)
|
||||
try:
|
||||
namecard, avatar, nickname, rarity = await self.get_final_data(client, characters, update)
|
||||
except Exception as e:
|
||||
logger.debug(f"卡片信息请求失败: {e}")
|
||||
namecard, avatar, nickname, rarity = await self.get_default_final_data(characters, update)
|
||||
|
||||
render_data = {
|
||||
"uid": client.uid, # 玩家uid
|
||||
|
@ -1,3 +1,3 @@
|
||||
from utils.patch import aiohttp
|
||||
from utils.patch import aiohttp, genshin
|
||||
|
||||
__all__ = ["aiohttp"]
|
||||
__all__ = ["aiohttp", "genshin"]
|
||||
|
41
utils/patch/genshin.py
Normal file
41
utils/patch/genshin.py
Normal file
@ -0,0 +1,41 @@
|
||||
import typing
|
||||
|
||||
import genshin # pylint: disable=W0406
|
||||
|
||||
from utils.patch.methods import patch, patchable
|
||||
|
||||
|
||||
@patch(genshin.client.components.calculator.CalculatorClient) # noqa
|
||||
class CalculatorClient:
|
||||
@patchable
|
||||
async def get_character_details(
|
||||
self,
|
||||
character: genshin.types.IDOr[genshin.models.genshin.Character],
|
||||
*,
|
||||
uid: typing.Optional[int] = None,
|
||||
lang: typing.Optional[str] = None,
|
||||
):
|
||||
uid = uid or await self._get_uid(genshin.types.Game.GENSHIN)
|
||||
|
||||
data = await self.request_calculator(
|
||||
"sync/avatar/detail",
|
||||
method="GET",
|
||||
lang=lang,
|
||||
params=dict(
|
||||
avatar_id=int(character),
|
||||
uid=uid,
|
||||
region=genshin.utility.recognize_genshin_server(uid),
|
||||
),
|
||||
)
|
||||
if data.get("weapon") is None:
|
||||
weapon = {
|
||||
"id": character.weapon.id,
|
||||
"name": character.weapon.name,
|
||||
"icon": character.weapon.icon,
|
||||
"weapon_cat_id": character.weapon.type,
|
||||
"weapon_level": character.weapon.rarity,
|
||||
"max_level": 90,
|
||||
"level_current": character.weapon.level,
|
||||
}
|
||||
data["weapon"] = weapon
|
||||
return genshin.models.genshin.CalculatorCharacterDetails(**data)
|
Loading…
Reference in New Issue
Block a user