From d64b763a29ae0ce8441efa94ff9f39299606d1b7 Mon Sep 17 00:00:00 2001 From: omg-xtao <100690902+omg-xtao@users.noreply.github.com> Date: Wed, 6 Dec 2023 14:16:23 +0800 Subject: [PATCH] :bug: Fix load old player card info TypeError --- modules/playercards/file.py | 10 ++++++---- plugins/genshin/gcsim/plugin.py | 2 -- plugins/genshin/player_cards.py | 2 -- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/modules/playercards/file.py b/modules/playercards/file.py index 9be156ac..e2c292d4 100644 --- a/modules/playercards/file.py +++ b/modules/playercards/file.py @@ -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) diff --git a/plugins/genshin/gcsim/plugin.py b/plugins/genshin/gcsim/plugin.py index 9bb3e73f..e26be7d8 100644 --- a/plugins/genshin/gcsim/plugin.py +++ b/plugins/genshin/gcsim/plugin.py @@ -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( diff --git a/plugins/genshin/player_cards.py b/plugins/genshin/player_cards.py index 067e633e..ab376ebb 100644 --- a/plugins/genshin/player_cards.py +++ b/plugins/genshin/player_cards.py @@ -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