Add API initialization and cog loading in Leaderboard cog
Some checks are pending
Run pre-commit / Run pre-commit (push) Waiting to run
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:
parent
0114307e67
commit
51320a8ed8
1 changed files with 14 additions and 0 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Reference in a new issue