Add API initialization and cog loading in Leaderboard cog
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run

Introduce an optional API connection setup in the Leaderboard cog with error handling. Implement a cog_load method to ensure the API is initialized when the cog is loaded, enhancing overall functionality and resource management.
This commit is contained in:
Valerie 2025-05-26 04:59:31 -04:00
parent 0114307e67
commit 51320a8ed8

View file

@ -89,6 +89,20 @@ class Leaderboard(commands.Cog):
self.config.register_guild(**default_guild)
async def initialize(self):
"""Initialize optional API connection."""
try:
self.admin_secret = await self.bot.get_shared_api_tokens("ruby_api")
if self.admin_secret.get("admin_secret"):
self.session = aiohttp.ClientSession()
except Exception as e:
log.error(f"Failed to initialize API connection: {e}")
# Don't return anything - initialization is optional
async def cog_load(self):
"""Initialize the cog when it's loaded."""
await self.initialize()
async def get_user_credits(self, user: discord.Member) -> int:
"""Get a user's total credits from Red's bank system."""
try: