From d3d7c2733dbcfd2e21d34f055da520600c23d635 Mon Sep 17 00:00:00 2001 From: CMHopeSunshine <277073121@qq.com> Date: Sat, 27 Aug 2022 16:33:58 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D`ys`=E3=80=81`ysa`?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E5=87=BA=E7=8E=B0=E7=9A=84None=E9=97=AE?= =?UTF-8?q?=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- LittlePaimon/utils/genshin.py | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/LittlePaimon/utils/genshin.py b/LittlePaimon/utils/genshin.py index e1cdeb4..bbc733a 100644 --- a/LittlePaimon/utils/genshin.py +++ b/LittlePaimon/utils/genshin.py @@ -189,14 +189,15 @@ class GenshinInfoManager: :return: 原神玩家信息和角色列表 """ await self.set_last_query() - player_info, state = await PlayerInfo.get_or_create(user_id=self.user_id, uid=self.uid) - if state or player_info.update_time is None or player_info.update_time < ( + player_info = await PlayerInfo.get_or_none(user_id=self.user_id, uid=self.uid) + if player_info is None or player_info.update_time is None or player_info.update_time < ( datetime.datetime.now() - datetime.timedelta(days=1)).replace( tzinfo=pytz.timezone('Asia/Shanghai')): result = await self.update_from_mihoyo() if result != '更新成功': return result, [] - player_info = await PlayerInfo.get_or_none(user_id=self.user_id, uid=self.uid) + if (player_info := await PlayerInfo.get_or_none(user_id=self.user_id, uid=self.uid)) is None: + return '获取原神信息失败', [] character_list = [] for character_name in CHARACTERS: if character := await self.get_character(name=character_name): @@ -205,15 +206,16 @@ class GenshinInfoManager: async def get_player_info(self) -> Tuple[Union[PlayerInfo, str], Optional[List[Character]]]: await self.set_last_query() - player_info, state = await PlayerInfo.get_or_create(user_id=self.user_id, uid=self.uid) - if state or player_info.update_time is None or player_info.update_time < ( + player_info = await PlayerInfo.get_or_none(user_id=self.user_id, uid=self.uid) + if player_info is None or player_info.update_time is None or player_info.update_time < ( datetime.datetime.now() - datetime.timedelta(days=1)).replace( tzinfo=pytz.timezone('Asia/Shanghai')): result = await self.update_from_mihoyo() if result != '更新成功': return result, None await self.update_from_enka() - player_info, _ = await PlayerInfo.get_or_create(user_id=self.user_id, uid=self.uid) + if (player_info := await PlayerInfo.get_or_none(user_id=self.user_id, uid=self.uid)) is None: + return '获取原神信息失败', None characters_list = [] for chara in player_info.avatars: if c := await self.get_character(character_id=chara):