🐛 Fix load old player card info TypeError

This commit is contained in:
omg-xtao 2023-12-06 14:16:23 +08:00 committed by GitHub
parent bc0f6c86d5
commit d64b763a29
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 8 deletions

View File

@ -51,7 +51,10 @@ class PlayerCardsFile:
if not file_path.exists():
return None
try:
return await self.load_json(file_path)
data = await self.load_json(file_path)
if data:
data["avatarInfoList"] = data.get("avatarInfoList") or []
return data
except jsonlib.JSONDecodeError:
return None
@ -65,10 +68,9 @@ class PlayerCardsFile:
if old_data is None:
await self.save_json(self.get_file_path(uid), data)
return data
if data.get("avatarInfoList") is None:
data["avatarInfoList"] = []
data["avatarInfoList"] = data.get("avatars") or []
characters = [i.get("avatarId", 0) for i in data["avatarInfoList"]]
for i in old_data.get("avatarInfoList", []):
for i in old_data["avatarInfoList"]:
if i.get("avatarId", 0) not in characters:
data["avatarInfoList"].append(i)
await self.save_json(self.get_file_path(uid), data)

View File

@ -152,8 +152,6 @@ class GCSimPlugin(Plugin):
original_data = await self.player_cards_file.load_history_info(uid)
if original_data is None:
return []
if original_data.get("avatarInfoList") is None:
original_data["avatarInfoList"] = []
if len(original_data["avatarInfoList"]) == 0:
return []
enka_response: EnkaNetworkResponse = EnkaNetworkResponse.parse_obj(

View File

@ -188,8 +188,6 @@ class PlayerCards(Plugin):
await message.reply_text("未查询到您所绑定的账号信息,请先绑定账号", reply_markup=InlineKeyboardMarkup(buttons))
return
original_data = await self._load_history(uid)
if original_data and not original_data.get("avatarInfoList"):
original_data["avatarInfoList"] = []
if original_data is None or len(original_data["avatarInfoList"]) == 0:
if isinstance(self.kitsune, str):
photo = self.kitsune