include graceful exits
This commit is contained in:
parent
cbfeb8e51e
commit
7d547130ea
3 changed files with 47 additions and 42 deletions
|
|
@ -61,13 +61,14 @@ def relaunch_in_terminal():
|
||||||
async def main():
|
async def main():
|
||||||
relaunch_in_terminal()
|
relaunch_in_terminal()
|
||||||
setup_logging()
|
setup_logging()
|
||||||
|
await run_disco_reaper()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
try:
|
try:
|
||||||
await run_disco_reaper()
|
asyncio.run(main())
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\nExiting...")
|
print("\nOperation terminated by user.")
|
||||||
|
sys.exit(0)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Error: {e}")
|
print(f"Error: {e}")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
asyncio.run(main())
|
|
||||||
|
|
|
||||||
|
|
@ -148,8 +148,8 @@ def main():
|
||||||
relaunch_in_terminal()
|
relaunch_in_terminal()
|
||||||
config = load_config()
|
config = load_config()
|
||||||
setup_logging()
|
setup_logging()
|
||||||
platform = select_platform(config)
|
|
||||||
try:
|
try:
|
||||||
|
platform = select_platform(config)
|
||||||
asyncio.run(run_cli(target_platform=platform))
|
asyncio.run(run_cli(target_platform=platform))
|
||||||
except KeyboardInterrupt:
|
except KeyboardInterrupt:
|
||||||
print("\nOperation terminated by user.")
|
print("\nOperation terminated by user.")
|
||||||
|
|
|
||||||
|
|
@ -96,42 +96,46 @@ class DiscoReaperCLI:
|
||||||
async def run(self):
|
async def run(self):
|
||||||
await self.validate_config()
|
await self.validate_config()
|
||||||
|
|
||||||
while True:
|
try:
|
||||||
console.print("")
|
while True:
|
||||||
console.print(Panel.fit("Disco Reaper - Server Backup Tool", style="bold green"))
|
console.print("")
|
||||||
|
console.print(Panel.fit("Disco Reaper - Server Backup Tool", style="bold green"))
|
||||||
|
|
||||||
d_name = self.validation_results.get("discord_server_name")
|
d_name = self.validation_results.get("discord_server_name")
|
||||||
d_display = f"[bold green]\"{d_name}\"[/bold green]" if d_name else "[bold red]NOT CONNECTED[/bold red]"
|
d_display = f"[bold green]\"{d_name}\"[/bold green]" if d_name else "[bold red]NOT CONNECTED[/bold red]"
|
||||||
console.print(f"[bold cyan]Source Server:[/bold cyan] {d_display}")
|
console.print(f"[bold cyan]Source Server:[/bold cyan] {d_display}")
|
||||||
|
|
||||||
b_name = self.validation_results.get("discord_bot_name")
|
b_name = self.validation_results.get("discord_bot_name")
|
||||||
b_display = f"[bold green]\"{b_name}\"[/bold green]" if b_name else "[bold red]UNKNOWN[/bold red]"
|
b_display = f"[bold green]\"{b_name}\"[/bold green]" if b_name else "[bold red]UNKNOWN[/bold red]"
|
||||||
console.print(f"[bold cyan]Bot name:[/bold cyan] {b_display}")
|
console.print(f"[bold cyan]Bot name:[/bold cyan] {b_display}")
|
||||||
|
|
||||||
backup_ts = self.get_backup_info()
|
backup_ts = self.get_backup_info()
|
||||||
if backup_ts:
|
if backup_ts:
|
||||||
console.print(f"[bold cyan]Backup Found:[/bold cyan] [bold yellow]{backup_ts}[/bold yellow]")
|
console.print(f"[bold cyan]Backup Found:[/bold cyan] [bold yellow]{backup_ts}[/bold yellow]")
|
||||||
|
|
||||||
console.print("\n[bold]Main Menu[/bold]")
|
console.print("\n[bold]Main Menu[/bold]")
|
||||||
console.print("(1) Backup Server Profile")
|
console.print("(1) Backup Server Profile")
|
||||||
console.print("(2) Backup Channel Messages")
|
console.print("(2) Backup Channel Messages")
|
||||||
console.print("(3) Update & Sync Backup")
|
console.print("(3) Update & Sync Backup")
|
||||||
console.print("(4) Configuration")
|
console.print("(4) Configuration")
|
||||||
console.print("(Q) Exit")
|
console.print("(Q) Exit")
|
||||||
|
|
||||||
choice = Prompt.ask("\nSelect an option", choices=["1", "2", "3", "4", "Q"], default="Q", show_choices=False).upper()
|
choice = Prompt.ask("\nSelect an option", choices=["1", "2", "3", "4", "Q"], default="Q", show_choices=False).upper()
|
||||||
|
|
||||||
if choice == "1":
|
if choice == "1":
|
||||||
await self.backup_server_profile()
|
await self.backup_server_profile()
|
||||||
elif choice == "2":
|
elif choice == "2":
|
||||||
await self.backup_messages()
|
await self.backup_messages()
|
||||||
elif choice == "3":
|
elif choice == "3":
|
||||||
await self.sync_backup()
|
await self.sync_backup()
|
||||||
elif choice == "4":
|
elif choice == "4":
|
||||||
await self.edit_configuration()
|
await self.edit_configuration()
|
||||||
elif choice == "Q":
|
elif choice == "Q":
|
||||||
await self.engine.close_connections()
|
break
|
||||||
break
|
except (KeyboardInterrupt, asyncio.CancelledError):
|
||||||
|
console.print("\n[yellow]Operation terminated by user.[/yellow]")
|
||||||
|
finally:
|
||||||
|
await self.engine.close_connections()
|
||||||
|
|
||||||
async def backup_server_profile(self):
|
async def backup_server_profile(self):
|
||||||
"""Option 1: Backup name, banner, logo, roles, structure, and custom assets."""
|
"""Option 1: Backup name, banner, logo, roles, structure, and custom assets."""
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue