From a9beb14cc46df40b08a0629d4729e3bb3077e78b Mon Sep 17 00:00:00 2001 From: seria Date: Wed, 13 Mar 2024 22:21:52 +0800 Subject: [PATCH] fix: Fix not updating player info --- hoyo_buddy/hoyo/clients/enka_client.py | 17 +---------------- hoyo_buddy/hoyo/clients/mihomo_client.py | 12 ++++++++++++ 2 files changed, 13 insertions(+), 16 deletions(-) diff --git a/hoyo_buddy/hoyo/clients/enka_client.py b/hoyo_buddy/hoyo/clients/enka_client.py index 350abe40..0efb9454 100644 --- a/hoyo_buddy/hoyo/clients/enka_client.py +++ b/hoyo_buddy/hoyo/clients/enka_client.py @@ -23,13 +23,6 @@ async def __aenter__(self) -> "EnkaAPI": return self def _update_cache_with_live_data(self, cache: EnkaCache, live_data: "ShowcaseResponse") -> None: - """ - Updates the cache with live data. - - Args: - cache (EnkaCache): The cache object to update. - live_data (ShowcaseResponse): The live data to update the cache with. - """ live_chara_data = {"live": True, "lang": self._lang.value} if cache.genshin is None: @@ -55,18 +48,10 @@ def _update_cache_with_live_data(self, cache: EnkaCache, live_data: "ShowcaseRes cache.extras[str(character.id)].update({"live": False}) cache_data.characters = cache_characters_not_in_live + live_data.characters + cache_data.player = live_data.player cache.genshin = pickle.dumps(cache_data) def _set_all_live_to_false(self, cache: EnkaCache) -> None: - """ - Sets the 'live' attribute of all characters in the cache to False. - - Args: - cache (EnkaCache): The cache object containing the character data. - - Returns: - None - """ if cache.genshin is None: return diff --git a/hoyo_buddy/hoyo/clients/mihomo_client.py b/hoyo_buddy/hoyo/clients/mihomo_client.py index b1bc38c6..5b5c78ec 100644 --- a/hoyo_buddy/hoyo/clients/mihomo_client.py +++ b/hoyo_buddy/hoyo/clients/mihomo_client.py @@ -46,8 +46,17 @@ def _update_cache_with_live_data( cache.extras[str(character.id)].update({"live": False}) cache_data.characters = cache_characters_not_in_live + live_data.characters + cache_data.player = live_data.player cache.hsr = pickle.dumps(cache_data) + def _set_all_live_to_false(self, cache: EnkaCache) -> None: + if cache.genshin is None: + return + + cache_data: StarrailInfoParsed = pickle.loads(cache.genshin) + for character in cache_data.characters: + cache.extras[str(character.id)].update({"live": False}) + async def fetch_user(self, uid: int) -> "StarrailInfoParsed": cache, _ = await EnkaCache.get_or_create(uid=uid) @@ -56,6 +65,9 @@ async def fetch_user(self, uid: int) -> "StarrailInfoParsed": except mihomo.UserNotFound: if not cache.hsr: raise + + self._set_all_live_to_false(cache) + await cache.save() cache_data: StarrailInfoParsed = pickle.loads(cache.hsr) else: self._update_cache_with_live_data(cache, live_data)