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.
This commit is contained in:
Slipstream 2025-05-26 16:23:47 -06:00
parent 0008327bd0
commit d89645ca28
Signed by: slipstream
GPG Key ID: 13E498CE010AC6FD
4 changed files with 14 additions and 6 deletions

View File

@ -36,7 +36,7 @@ class CommandCustomizationDetail(BaseModel):
class CommandCustomizationResponse(BaseModel): class CommandCustomizationResponse(BaseModel):
command_customizations: Dict[str, Dict[str, Optional[str]]] = {} # Original command name -> {name, description} 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 command_aliases: Dict[str, List[str]] = {} # Original command name -> List of aliases
class CommandCustomizationUpdate(BaseModel): class CommandCustomizationUpdate(BaseModel):

View File

@ -320,7 +320,8 @@ function renderGroupCustomizations(groupCustomizations) {
// Create group items // Create group items
sortedGroups.forEach(groupName => { 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); const groupItem = createGroupItem(groupName, customName);
groupList.appendChild(groupItem); groupList.appendChild(groupItem);
}); });

View File

@ -373,11 +373,11 @@ class SettingsCog(commands.Cog, name="Settings"):
embed = discord.Embed(title="Command Customizations", color=discord.Color.blue()) embed = discord.Embed(title="Command Customizations", color=discord.Color.blue())
if cmd_customizations: 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) embed.add_field(name="Custom Command Names", value=cmd_text, inline=False)
if group_customizations: 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) embed.add_field(name="Custom Group Names", value=group_text, inline=False)
await ctx.send(embed=embed) await ctx.send(embed=embed)

View File

@ -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: async def get_all_group_customizations(guild_id: int) -> dict[str, dict[str, str]] | None:
"""Gets all command group customizations for a guild. """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() bot = get_bot_instance()
if not bot or not bot.pg_pool: 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.") 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", "SELECT original_group_name, custom_group_name FROM command_group_customization WHERE guild_id = $1",
guild_id 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}.") log.debug(f"Fetched {len(customizations)} group customizations for guild {guild_id}.")
return customizations return customizations
except Exception as e: except Exception as e: