This commit is contained in:
pacnpal
2024-11-16 01:50:34 +00:00
parent 669db54442
commit 18792c77f2

View File

@@ -106,38 +106,33 @@ class VideoArchiver(GroupCog):
async def enable_database(self, ctx: Context): async def enable_database(self, ctx: Context):
"""Enable the video archive database.""" """Enable the video archive database."""
try: try:
# First check if database is already enabled # Check if database is already enabled
try:
current_setting = await self.config_manager.get_setting( current_setting = await self.config_manager.get_setting(
ctx.guild.id, "use_database" ctx.guild.id, "use_database"
) )
if current_setting: if current_setting:
await ctx.send("The video archive database is already enabled.") await ctx.send("The video archive database is already enabled.")
return return
except Exception as e:
logger.error(f"Failed to get setting use_database: {e}")
# If setting doesn't exist, we'll create it
await self.config_manager.update_setting(ctx.guild.id, "use_database", False)
# Initialize database if it's being enabled # Initialize database
try:
self.db = VideoArchiveDB(self.data_path) self.db = VideoArchiveDB(self.data_path)
# Update processor with database # Update processor with database
if self.processor: if self.processor:
self.processor.db = self.db self.processor.db = self.db
if self.processor.queue_handler: if self.processor.queue_handler:
self.processor.queue_handler.db = self.db self.processor.queue_handler.db = self.db
# Update setting
await self.config_manager.update_setting(ctx.guild.id, "use_database", True) await self.config_manager.update_setting(ctx.guild.id, "use_database", True)
# Send success message
await ctx.send("Video archive database has been enabled.") await ctx.send("Video archive database has been enabled.")
except Exception as e:
logger.error(f"Error initializing database: {e}")
await ctx.send("An error occurred while initializing the database.")
return
except Exception as e: except Exception as e:
logger.error(f"Error enabling database: {e}") logger.error(f"Error enabling database: {e}")
await ctx.send("An error occurred while enabling the database.") # Send single error message
await ctx.send("An error occurred while enabling the database. Please check the logs for details.")
@archivedb.command(name="disable") @archivedb.command(name="disable")
@guild_only() @guild_only()