Advertisement
LyndenSylvester

Untitled

Nov 19th, 2024
45
0
21 hours
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.79 KB | None | 0 0
  1. # Create a Database    
  2.     @admin.command(name="create_db", description="Create a new database")
  3.     async def create_database(self, interaction: discord.Interaction, db_name: str) -> None:
  4.         guild_id = interaction.guild.id
  5.  
  6.         ServerName = await asyncio.to_thread(utils.get_server_name, guild_id)
  7.         if not ServerName:
  8.             raise ValueError("Server not found in the database")
  9.            
  10.         BasePath = await asyncio.to_thread(utils.server_folder, ServerName)
  11.         if not BasePath:
  12.             raise ValueError(f"Server folder '{BasePath}' does not exist")
  13.  
  14.         PrimaryDatabasePath = await asyncio.to_thread(utils.primary_database_folder, BasePath, ServerName)
  15.         if not PrimaryDatabasePath:
  16.             raise ValueError(f"Folder path '{PrimaryDatabasePath}' does not exist")
  17.         await asyncio.to_thread(utils.create_database, PrimaryDatabasePath, db_name, guild_id)
  18.  
  19.         scheduler = Scheduler(guild_id)
  20.         print("Made Scheduler")
  21.         await scheduler.start()
  22.         print("Scheduler started")
  23.         scheduler = self.set_scheduler(guild_id, self.schedulers)
  24.         print("Scheduler set")
  25.  
  26.         await Scheduler.schedule_full_backup(scheduler, db_name)
  27.         print("Added full backup to scheduler")
  28.         await Scheduler.schedule_differential_backup(scheduler, db_name)
  29.         print("Added differential backup to scheduler")
  30.  
  31.         BackupsRoute = await asyncio.to_thread(utils.backup_folder, BasePath, ServerName)
  32.         if not BackupsRoute:
  33.             raise ValueError(f"Backup Route: '{BackupsRoute}' does not exist")
  34.         await asyncio.to_thread(utils.initial_backup_database, db_name, BackupsRoute)
  35.            
  36.         await interaction.response.send_message(f"Created database named: {db_name}", ephemeral=True)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement