display server,community name in menu
This commit is contained in:
parent
9da66326fc
commit
5dbcac68b6
4 changed files with 51 additions and 19 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import asyncio
|
||||
import logging
|
||||
from typing import Callable, Awaitable, List
|
||||
from typing import Callable, Awaitable, List, Dict, Any
|
||||
from src.config import AppConfig
|
||||
from src.core.state import MigrationState
|
||||
from src.discord_bot.reader import DiscordReader
|
||||
|
|
@ -27,17 +27,20 @@ class MigrationEngine:
|
|||
|
||||
self.is_running = False
|
||||
|
||||
async def validate_all(self) -> Dict[str, bool]:
|
||||
async def validate_all(self) -> Dict[str, Any]:
|
||||
"""Returns True if both connections are valid."""
|
||||
try:
|
||||
# Note: in real scenarios we might want concurrent validation
|
||||
d_valid = await self.discord_reader.validate()
|
||||
f_valid = await self.fluxer_writer.validate()
|
||||
return {
|
||||
"discord_token": d_valid.get("token", False),
|
||||
"discord_bot_name": d_valid.get("bot_name"),
|
||||
"discord_server": d_valid.get("server", False),
|
||||
"discord_server_name": d_valid.get("server_name"),
|
||||
"fluxer_token": f_valid.get("token", False),
|
||||
"fluxer_community": f_valid.get("community", False)
|
||||
"fluxer_bot_name": f_valid.get("bot_name"),
|
||||
"fluxer_community": f_valid.get("community", False),
|
||||
"fluxer_community_name": f_valid.get("community_name")
|
||||
}
|
||||
except Exception as e:
|
||||
logger.error(f"Validation failed with exception: {e}")
|
||||
|
|
|
|||
|
|
@ -25,16 +25,20 @@ class DiscordReader:
|
|||
# In a real app we'd wait until ready, here we simulate fetching the guild
|
||||
self.guild = await self.client.fetch_guild(self.server_id)
|
||||
|
||||
async def validate(self) -> Dict[str, bool]:
|
||||
async def validate(self) -> Dict[str, Any]:
|
||||
"""Validates the token and server ID."""
|
||||
results = {"token": False, "server": False}
|
||||
results = {"token": False, "server": False, "bot_name": None, "server_name": None}
|
||||
temp_client = self._create_client()
|
||||
try:
|
||||
await temp_client.login(self.token)
|
||||
results["token"] = True
|
||||
if temp_client.user:
|
||||
results["bot_name"] = temp_client.user.name
|
||||
|
||||
guild = await temp_client.fetch_guild(self.server_id)
|
||||
if guild is not None:
|
||||
results["server"] = True
|
||||
results["server_name"] = guild.name
|
||||
except Exception:
|
||||
pass
|
||||
finally:
|
||||
|
|
|
|||
|
|
@ -21,21 +21,28 @@ class FluxerWriter:
|
|||
|
||||
is_token_valid = False
|
||||
is_community_valid = False
|
||||
bot_name = None
|
||||
community_name = None
|
||||
try:
|
||||
# Check token by fetching me
|
||||
await self.client.get_current_user()
|
||||
is_token_valid = True
|
||||
me = await self.client.get_current_user()
|
||||
if me:
|
||||
is_token_valid = True
|
||||
bot_name = me.get("username")
|
||||
|
||||
# Check community
|
||||
guild = await self.client.get_guild(self.community_id)
|
||||
if guild:
|
||||
is_community_valid = True
|
||||
community_name = guild.get("name")
|
||||
except Exception:
|
||||
pass
|
||||
|
||||
return {
|
||||
"token": is_token_valid,
|
||||
"community": is_community_valid
|
||||
"community": is_community_valid,
|
||||
"bot_name": bot_name,
|
||||
"community_name": community_name
|
||||
}
|
||||
|
||||
async def create_channel(self, name: str, topic: str = "", type: int = 0, parent_id: Optional[str] = None) -> str:
|
||||
|
|
|
|||
|
|
@ -55,8 +55,10 @@ class MigrationCLI:
|
|||
old_settings = termios.tcgetattr(fd) if fd is not None else None
|
||||
|
||||
self.validation_results = {
|
||||
"discord_token": False, "discord_server": False,
|
||||
"fluxer_token": False, "fluxer_community": False
|
||||
"discord_token": False, "discord_bot_name": None,
|
||||
"discord_server": False, "discord_server_name": None,
|
||||
"fluxer_token": False, "fluxer_bot_name": None,
|
||||
"fluxer_community": False, "fluxer_community_name": None
|
||||
}
|
||||
self.tokens_valid = False
|
||||
|
||||
|
|
@ -94,7 +96,9 @@ class MigrationCLI:
|
|||
try:
|
||||
res = discord_task.result()
|
||||
self.validation_results["discord_token"] = res.get("token", False)
|
||||
self.validation_results["discord_bot_name"] = res.get("bot_name")
|
||||
self.validation_results["discord_server"] = res.get("server", False)
|
||||
self.validation_results["discord_server_name"] = res.get("server_name")
|
||||
if not res.get("token"):
|
||||
console.print("[bold red]Discord Token validation failed (Invalid Token).[/bold red]")
|
||||
elif not res.get("server"):
|
||||
|
|
@ -110,7 +114,9 @@ class MigrationCLI:
|
|||
try:
|
||||
res = fluxer_task.result()
|
||||
self.validation_results["fluxer_token"] = res.get("token", False)
|
||||
self.validation_results["fluxer_bot_name"] = res.get("bot_name")
|
||||
self.validation_results["fluxer_community"] = res.get("community", False)
|
||||
self.validation_results["fluxer_community_name"] = res.get("community_name")
|
||||
if not res.get("token"):
|
||||
console.print("[bold red]Fluxer Token validation failed (Invalid Token).[/bold red]")
|
||||
elif not res.get("community"):
|
||||
|
|
@ -146,8 +152,17 @@ class MigrationCLI:
|
|||
await self.validate_config()
|
||||
|
||||
while True:
|
||||
console.print(Panel.fit("Fluxer Reaper", style="bold blue"))
|
||||
console.print("[bold]Main Menu[/bold]")
|
||||
console.print("")
|
||||
console.print(Panel.fit("Fluxer Reaper", style="bold blue"))
|
||||
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 SET UP[/bold red]"
|
||||
|
||||
f_name = self.validation_results.get("fluxer_community_name")
|
||||
f_display = f"[bold green]\"{f_name}\"[/bold green]" if f_name else "[bold red]NOT SET UP[/bold red]"
|
||||
|
||||
console.print(f"[bold cyan]Discord Server:[/bold cyan] {d_display}")
|
||||
console.print(f"[bold magenta]Fluxer Community:[/bold magenta] {f_display}")
|
||||
console.print("[bold]Main Menu[/bold]")
|
||||
console.print("(1) Clone Server Template (Channels & Categories)")
|
||||
console.print("(2) Copy Roles & Permissions")
|
||||
console.print("(3) Copy Emojis & Stickers")
|
||||
|
|
@ -181,13 +196,16 @@ class MigrationCLI:
|
|||
await self.validate_config()
|
||||
console.print("\n[bold]Configuration Status:[/bold]")
|
||||
|
||||
def get_status_str(is_valid):
|
||||
return "[bold green][VALID][/bold green]" if is_valid else "[bold red][INVALID][/bold red]"
|
||||
def get_status_str(is_valid, name=None):
|
||||
status = "[bold green][VALID][/bold green]" if is_valid else "[bold red][INVALID][/bold red]"
|
||||
if is_valid and name:
|
||||
return f"{status} \"{name}\""
|
||||
return status
|
||||
|
||||
console.print(f"Discord Bot Token {get_status_str(self.validation_results.get('discord_token', False))}")
|
||||
console.print(f"Fluxer Bot Token {get_status_str(self.validation_results.get('fluxer_token', False))}")
|
||||
console.print(f"Discord Server ID {get_status_str(self.validation_results.get('discord_server', False))}")
|
||||
console.print(f"Fluxer Community ID {get_status_str(self.validation_results.get('fluxer_community', False))}")
|
||||
console.print(f"Discord Bot Token {get_status_str(self.validation_results.get('discord_token', False), self.validation_results.get('discord_bot_name'))}")
|
||||
console.print(f"Fluxer Bot Token {get_status_str(self.validation_results.get('fluxer_token', False), self.validation_results.get('fluxer_bot_name'))}")
|
||||
console.print(f"Discord Server ID {get_status_str(self.validation_results.get('discord_server', False), self.validation_results.get('discord_server_name'))}")
|
||||
console.print(f"Fluxer Community ID {get_status_str(self.validation_results.get('fluxer_community', False), self.validation_results.get('fluxer_community_name'))}")
|
||||
|
||||
if not Confirm.ask("Edit now?"):
|
||||
return
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue