async def fetch_from_redis(self, bot: CustomBot) -> str: """Fetches information for the given user from the redis cache""" async with bot.redis() as re: self.name = await re.get(f"UserName-{self.user_id}") self.age = 0 self.fetch_when_expired = True # We can't trust redis forever if self.name is None: return await self.fetch_from_api(bot) return self.name
async def fetch_from_api(self, bot: CustomBot) -> str: """Fetches information for the given user from the Discord API""" # Grab user data try: data = await bot.fetch_user(self.user_id) except (discord.Forbidden, discord.NotFound): self.name = "Deleted User" self.age = -1 # This should never change babey self.fetch_when_expired = True else: self.name = str(data) self.age = 0 self.fetch_when_expired = False # Push it to redis async with bot.redis() as re: await re.set(f"UserName-{self.user_id}", self.name) # Return data return self.name