🐛 Fix the KeyError exception caused by the character rarity not found

This commit is contained in:
洛水居室 2023-04-28 14:34:54 +08:00
parent ca37f6948a
commit 9e23c1d20d
No known key found for this signature in database
GPG Key ID: C9DE87DA724B88FC
2 changed files with 18 additions and 9 deletions

View File

@ -167,6 +167,7 @@ class AvatarListPlugin(Plugin):
name_card: Optional[str] = None
avatar: Optional[str] = None
rarity: int = 5
try:
if player_info is not None:
if player_info.nickname is not None:
nickname = player_info.nickname
@ -174,7 +175,12 @@ class AvatarListPlugin(Plugin):
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)]
try:
rarity = {k: v["rank"] for k, v in AVATAR_DATA.items()}[player_info.hand_image]
except KeyError:
logger.warning("未找到角色 %s 的星级", player_info.hand_image)
except Exception as exc: # pylint: disable=W0703
logger.error("卡片信息请求失败 %s", str(exc))
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

@ -36,7 +36,10 @@ class PlayerInfoSystem(Plugin):
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()
try:
rarity = {k: v["rank"] for k, v in AVATAR_DATA.items()}[player_info.hand_image]
except KeyError:
logger.warning("未找到角色 %s 的等级", player_info.hand_image)
except Exception as exc: # pylint: disable=W0703
logger.error("卡片信息请求失败 %s", str(exc))
if name_card is not None: # 默认