simplify user menu
This commit is contained in:
parent
4ab1c7cfe5
commit
8563826442
2 changed files with 6 additions and 71 deletions
|
|
@ -189,45 +189,6 @@ class DiscordExporter:
|
||||||
|
|
||||||
return len(emoji_data), len(sticker_data)
|
return len(emoji_data), len(sticker_data)
|
||||||
|
|
||||||
async def export_members(self):
|
|
||||||
"""Exports server members to server_assets.json."""
|
|
||||||
member_data = []
|
|
||||||
logger.info("Attempting to export members (requires Server Members Intent)...")
|
|
||||||
try:
|
|
||||||
members = await self.reader.get_members()
|
|
||||||
for m in members:
|
|
||||||
member_data.append({
|
|
||||||
"id": str(m.id),
|
|
||||||
"name": m.name,
|
|
||||||
"display_name": m.display_name,
|
|
||||||
"discriminator": m.discriminator,
|
|
||||||
"avatar_url": str(m.avatar.url) if m.avatar else None,
|
|
||||||
"bot": m.bot,
|
|
||||||
"roles": [str(r.id) for r in m.roles if not r.is_default()]
|
|
||||||
})
|
|
||||||
logger.info(f"Successfully exported {len(member_data)} members.")
|
|
||||||
except discord.Forbidden:
|
|
||||||
logger.warning("403 Forbidden: Missing Access to fetch members. Skipping members export.")
|
|
||||||
return 0
|
|
||||||
except Exception as e:
|
|
||||||
logger.error(f"Failed to fetch members: {e}")
|
|
||||||
return 0
|
|
||||||
|
|
||||||
# Merge with existing assets
|
|
||||||
custom_file = self.export_path / "server_assets.json"
|
|
||||||
customization = {"emojis": [], "stickers": [], "members": member_data}
|
|
||||||
if custom_file.exists():
|
|
||||||
try:
|
|
||||||
with open(custom_file, "r", encoding="utf-8") as f:
|
|
||||||
old_data = json.load(f)
|
|
||||||
customization["emojis"] = old_data.get("emojis", [])
|
|
||||||
customization["stickers"] = old_data.get("stickers", [])
|
|
||||||
except Exception: pass
|
|
||||||
|
|
||||||
with open(custom_file, "w", encoding="utf-8") as f:
|
|
||||||
json.dump(customization, f, indent=4, ensure_ascii=False)
|
|
||||||
|
|
||||||
return len(member_data)
|
|
||||||
|
|
||||||
async def export_channels_structure(self):
|
async def export_channels_structure(self):
|
||||||
"""Exports categories and channels hierarchy."""
|
"""Exports categories and channels hierarchy."""
|
||||||
|
|
@ -381,7 +342,6 @@ class DiscordExporter:
|
||||||
thread_msg_count += (t.message_count or 0)
|
thread_msg_count += (t.message_count or 0)
|
||||||
|
|
||||||
output_data = {
|
output_data = {
|
||||||
"channelName": channel_name,
|
|
||||||
"channelID": str(channel_id),
|
"channelID": str(channel_id),
|
||||||
"messageCount": len(messages),
|
"messageCount": len(messages),
|
||||||
"threadCount": thread_count,
|
"threadCount": thread_count,
|
||||||
|
|
|
||||||
|
|
@ -83,21 +83,18 @@ class ExodusCLI:
|
||||||
|
|
||||||
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 User Names & Avatars")
|
console.print("(2) Backup Messages")
|
||||||
console.print("(3) Backup Messages")
|
console.print("(3) Update & Sync Backup")
|
||||||
console.print("(4) Update & Sync Backup")
|
|
||||||
console.print("(C) Configuration")
|
console.print("(C) Configuration")
|
||||||
console.print("(Q) Exit")
|
console.print("(Q) Exit")
|
||||||
|
|
||||||
choice = Prompt.ask("\nSelect an option", choices=["1", "2", "3", "4", "C", "Q"], default="Q", show_choices=False).upper()
|
choice = Prompt.ask("\nSelect an option", choices=["1", "2", "3", "C", "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_customization()
|
|
||||||
elif choice == "3":
|
|
||||||
await self.backup_messages()
|
await self.backup_messages()
|
||||||
elif choice == "4":
|
elif choice == "3":
|
||||||
await self.sync_backup()
|
await self.sync_backup()
|
||||||
elif choice == "C":
|
elif choice == "C":
|
||||||
await self.edit_configuration()
|
await self.edit_configuration()
|
||||||
|
|
@ -145,29 +142,8 @@ class ExodusCLI:
|
||||||
finally:
|
finally:
|
||||||
await self.engine.close_connections()
|
await self.engine.close_connections()
|
||||||
|
|
||||||
async def backup_customization(self):
|
|
||||||
"""Option 2: Backup User Names & Avatars (Members)."""
|
|
||||||
if not self.tokens_valid: return
|
|
||||||
try:
|
|
||||||
await self.engine.discord_reader.start()
|
|
||||||
await self.exporter.setup()
|
|
||||||
with console.status("[yellow]Backing up members and names...[/yellow]"):
|
|
||||||
m_count = await self.exporter.export_members()
|
|
||||||
|
|
||||||
if m_count > 0:
|
|
||||||
console.print(f"[bold green]Backup complete: {m_count} members and avatars saved to customization.json[/bold green]")
|
|
||||||
else:
|
|
||||||
console.print("[yellow]No members exported. Ensure 'Server Members Intent' is enabled.[/yellow]")
|
|
||||||
except discord.Forbidden as e:
|
|
||||||
console.print(f"[bold red]Member backup failed: {e}[/bold red]")
|
|
||||||
console.print("[yellow]Hint: Missing Access. Ensure 'Server Members Intent' is enabled in the Developer Portal.[/yellow]")
|
|
||||||
except Exception as e:
|
|
||||||
console.print(f"[bold red]Member backup failed: {e}[/bold red]")
|
|
||||||
finally:
|
|
||||||
await self.engine.close_connections()
|
|
||||||
|
|
||||||
async def backup_messages(self):
|
async def backup_messages(self):
|
||||||
"""Option 3: Backup Channels structure and all message history."""
|
"""Option 2: Backup Channels structure and all message history."""
|
||||||
if not self.tokens_valid: return
|
if not self.tokens_valid: return
|
||||||
try:
|
try:
|
||||||
await self.engine.discord_reader.start()
|
await self.engine.discord_reader.start()
|
||||||
|
|
@ -241,10 +217,9 @@ class ExodusCLI:
|
||||||
await self.engine.close_connections()
|
await self.engine.close_connections()
|
||||||
|
|
||||||
async def sync_backup(self):
|
async def sync_backup(self):
|
||||||
"""Option 4: Update & Sync Backup (Runs a full pass but overwrites where needed)."""
|
"""Option 3: Update & Sync Backup (Runs a full pass but overwrites where needed)."""
|
||||||
console.print("[yellow]Syncing backup... (Re-validating all data)[/yellow]")
|
console.print("[yellow]Syncing backup... (Re-validating all data)[/yellow]")
|
||||||
await self.backup_server_profile()
|
await self.backup_server_profile()
|
||||||
await self.backup_customization()
|
|
||||||
await self.backup_messages()
|
await self.backup_messages()
|
||||||
|
|
||||||
async def edit_configuration(self):
|
async def edit_configuration(self):
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue