From d89645ca2848228592cef7af107a8c91cde2827d Mon Sep 17 00:00:00 2001 From: Slipstream Date: Mon, 26 May 2025 16:23:47 -0600 Subject: [PATCH] Refactor: Store group customizations as objects Changes the `group_customizations` data structure to store a dictionary containing `name` and `description` for each group, rather than just the custom name. This aligns with how command customizations are stored and prepares for future additions like custom group descriptions. Updates the dashboard UI and settings cog to correctly display the new group customization format, while maintaining backward compatibility for existing data. --- api_service/dashboard_models.py | 2 +- api_service/dashboard_web/js/command-customization.js | 3 ++- cogs/settings_cog.py | 4 ++-- settings_manager.py | 11 +++++++++-- 4 files changed, 14 insertions(+), 6 deletions(-) diff --git a/api_service/dashboard_models.py b/api_service/dashboard_models.py index d8a71b3..08a7da2 100644 --- a/api_service/dashboard_models.py +++ b/api_service/dashboard_models.py @@ -36,7 +36,7 @@ class CommandCustomizationDetail(BaseModel): class CommandCustomizationResponse(BaseModel): command_customizations: Dict[str, Dict[str, Optional[str]]] = {} # Original command name -> {name, description} - group_customizations: Dict[str, str] = {} # Original group name -> Custom group name + group_customizations: Dict[str, Dict[str, Optional[str]]] = {} # Original group name -> {name, description} command_aliases: Dict[str, List[str]] = {} # Original command name -> List of aliases class CommandCustomizationUpdate(BaseModel): diff --git a/api_service/dashboard_web/js/command-customization.js b/api_service/dashboard_web/js/command-customization.js index 5f46107..7cfcb23 100644 --- a/api_service/dashboard_web/js/command-customization.js +++ b/api_service/dashboard_web/js/command-customization.js @@ -320,7 +320,8 @@ function renderGroupCustomizations(groupCustomizations) { // Create group items sortedGroups.forEach(groupName => { - const customName = groupCustomizations[groupName]; + const customization = groupCustomizations[groupName]; + const customName = customization.name || customization; // Support both old and new format const groupItem = createGroupItem(groupName, customName); groupList.appendChild(groupItem); }); diff --git a/cogs/settings_cog.py b/cogs/settings_cog.py index 277735d..9bad83d 100644 --- a/cogs/settings_cog.py +++ b/cogs/settings_cog.py @@ -373,11 +373,11 @@ class SettingsCog(commands.Cog, name="Settings"): embed = discord.Embed(title="Command Customizations", color=discord.Color.blue()) if cmd_customizations: - cmd_text = "\n".join([f"`{orig}` → `{custom}`" for orig, custom in cmd_customizations.items()]) + cmd_text = "\n".join([f"`{orig}` → `{custom['name']}`" for orig, custom in cmd_customizations.items()]) embed.add_field(name="Custom Command Names", value=cmd_text, inline=False) if group_customizations: - group_text = "\n".join([f"`{orig}` → `{custom}`" for orig, custom in group_customizations.items()]) + group_text = "\n".join([f"`{orig}` → `{custom['name']}`" for orig, custom in group_customizations.items()]) embed.add_field(name="Custom Group Names", value=group_text, inline=False) await ctx.send(embed=embed) diff --git a/settings_manager.py b/settings_manager.py index a424e4e..1b29c37 100644 --- a/settings_manager.py +++ b/settings_manager.py @@ -2168,7 +2168,8 @@ async def get_all_command_customizations(guild_id: int) -> dict[str, dict[str, s async def get_all_group_customizations(guild_id: int) -> dict[str, dict[str, str]] | None: """Gets all command group customizations for a guild. - Returns a dictionary mapping original group names to custom names, or None on error.""" + Returns a dictionary mapping original group names to a dict with 'name' and 'description' keys, + or None on error.""" bot = get_bot_instance() if not bot or not bot.pg_pool: log.error(f"Bot instance or PostgreSQL pool not available in settings_manager for guild {guild_id}, cannot get group customizations.") @@ -2179,7 +2180,13 @@ async def get_all_group_customizations(guild_id: int) -> dict[str, dict[str, str "SELECT original_group_name, custom_group_name FROM command_group_customization WHERE guild_id = $1", guild_id ) - customizations = {record['original_group_name']: record['custom_group_name'] for record in records} + customizations = {} + for record in records: + group_name = record['original_group_name'] + customizations[group_name] = { + 'name': record['custom_group_name'], + 'description': None # Groups don't have custom descriptions yet + } log.debug(f"Fetched {len(customizations)} group customizations for guild {guild_id}.") return customizations except Exception as e: