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:
parent
0008327bd0
commit
d89645ca28
@ -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):
|
||||
|
@ -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);
|
||||
});
|
||||
|
@ -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)
|
||||
|
@ -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:
|
||||
|
Loading…
x
Reference in New Issue
Block a user