Skip to content

Commit

Permalink
fix: Fix not updating player info
Browse files Browse the repository at this point in the history
  • Loading branch information
seriaati committed Mar 13, 2024
1 parent da23784 commit a9beb14
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 16 deletions.
17 changes: 1 addition & 16 deletions hoyo_buddy/hoyo/clients/enka_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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

Expand Down
12 changes: 12 additions & 0 deletions hoyo_buddy/hoyo/clients/mihomo_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)
Expand Down

0 comments on commit a9beb14

Please sign in to comment.