From 4190e8ef892f2f2fd2ea68a5ff8c7e0f1e139eaf Mon Sep 17 00:00:00 2001 From: shni Date: Sun, 5 Oct 2025 15:53:42 -0500 Subject: [PATCH] Add support for description field in display component editor state and rendering --- .../messages/alliaces/editDisplayComponent.ts | 45 ++++++++++++++++--- src/core/types/displayComponentEditor.ts | 23 ++++++++++ 2 files changed, 61 insertions(+), 7 deletions(-) diff --git a/src/commands/messages/alliaces/editDisplayComponent.ts b/src/commands/messages/alliaces/editDisplayComponent.ts index 8bce2e6..f3757cd 100644 --- a/src/commands/messages/alliaces/editDisplayComponent.ts +++ b/src/commands/messages/alliaces/editDisplayComponent.ts @@ -81,6 +81,24 @@ const renderPreview = async (blockState: any, member: any, guild: any) => { const processedTitle = await replaceVars(blockState.title ?? "Sin título", member, guild); previewComponents.push({ type: 10, content: validateContent(processedTitle) }); + const rawDescription = typeof blockState.description === 'string' ? blockState.description.trim() : ''; + if (rawDescription.length > 0) { + // @ts-ignore + const processedDescription = await replaceVars(rawDescription, member, guild); + const validatedDescription = validateContent(processedDescription); + const firstTextComponent = Array.isArray(blockState.components) + ? blockState.components.find((c: any) => c?.type === 10 && typeof c.content === 'string') + : null; + const duplicatesWithFirstText = Boolean( + firstTextComponent && typeof firstTextComponent.content === 'string' + && firstTextComponent.content.trim() === rawDescription + ); + + if (!duplicatesWithFirstText) { + previewComponents.push({ type: 10, content: validatedDescription }); + } + } + for (const c of blockState.components) { if (c.type === 10) { // @ts-ignore @@ -159,6 +177,8 @@ export const command: CommandMessage = { //@ts-ignore title: existingBlock.config?.title ?? `## Block: ${blockName}`, //@ts-ignore + description: typeof existingBlock.config?.description === 'string' ? existingBlock.config.description : undefined, + //@ts-ignore color: existingBlock.config?.color ?? 0x427AE3, //@ts-ignore coverImage: existingBlock.config?.coverImage ?? null, @@ -166,6 +186,15 @@ export const command: CommandMessage = { components: Array.isArray(existingBlock.config?.components) ? existingBlock.config.components : [] }; + if (!blockState.description || typeof blockState.description !== 'string' || blockState.description.trim().length === 0) { + const firstText = Array.isArray(blockState.components) + ? blockState.components.find((c: any) => c?.type === 10 && typeof c.content === 'string') + : null; + if (firstText) { + blockState.description = firstText.content; + } + } + // @ts-ignore const editorMessage = await message.channel.send({ content: "⚠️ **EDITANDO BLOCK EXISTENTE**\n\n" + @@ -256,8 +285,11 @@ export const command: CommandMessage = { break; } case "edit_description": { - const descComp = blockState.components.find((c: any) => c.type === 10); - const currentDesc = descComp ? descComp.content : ''; + let currentDesc = typeof blockState.description === 'string' ? blockState.description : ''; + if (!currentDesc) { + const legacyComp = blockState.components.find((c: any) => c.type === 10 && typeof c.content === 'string'); + if (legacyComp) currentDesc = legacyComp.content; + } const modal = { title: '📄 Editar Descripción', customId: 'edit_description_modal', @@ -269,8 +301,8 @@ export const command: CommandMessage = { customId: 'description_input', style: TextInputStyle.Paragraph, required: true, - placeholder: 'Escribe la nueva descripción aquí...', - value: currentDesc || '', + placeholder: 'Escribe la nueva descripción aquí...', + value: currentDesc || '', maxLength: 2000 } }] @@ -798,9 +830,8 @@ export const command: CommandMessage = { blockState.title = interaction.fields.getTextInputValue('title_input'); await interaction.reply({ content: '✅ Título actualizado.', flags: 64 }); } else if (id === 'edit_description_modal') { - const newDescription = interaction.fields.getTextInputValue('description_input'); - const firstText = blockState.components.find((c: any) => c.type === 10); - if (firstText) firstText.content = newDescription; else blockState.components.push({ type: 10, content: newDescription, thumbnail: null }); + const newDescription = interaction.fields.getTextInputValue('description_input').trim(); + blockState.description = newDescription.length > 0 ? newDescription : undefined; await interaction.reply({ content: '✅ Descripción actualizada.', flags: 64 }); } else if (id === 'edit_color_modal') { const colorInput = interaction.fields.getTextInputValue('color_input'); diff --git a/src/core/types/displayComponentEditor.ts b/src/core/types/displayComponentEditor.ts index 7f602c5..499518b 100644 --- a/src/core/types/displayComponentEditor.ts +++ b/src/core/types/displayComponentEditor.ts @@ -189,6 +189,29 @@ export class DisplayComponentUtils { content: this.validateContent(processedTitle) } as any); + // Optional description section (before additional components) + const rawDescription = typeof blockState.description === 'string' ? blockState.description.trim() : ''; + if (rawDescription.length > 0) { + const processedDescription = await replaceVars(rawDescription, member, guild); + const validatedDescription = this.validateContent(processedDescription); + + const firstTextComponent = Array.isArray(blockState.components) + ? blockState.components.find((c: any) => c?.type === 10 && typeof c.content === 'string') + : null; + const duplicatesWithFirstText = Boolean( + firstTextComponent?.type === 10 + && typeof (firstTextComponent as EditorTextDisplay).content === 'string' + && (firstTextComponent as EditorTextDisplay).content.trim() === rawDescription + ); + + if (!duplicatesWithFirstText) { + previewComponents.push({ + type: 10, + content: validatedDescription + } as any); + } + } + // Process components in order for (const c of blockState.components) { if (c.type === 10) {