ni yo se que hice xd

This commit is contained in:
2025-09-20 16:35:38 -05:00
parent bb30b90bea
commit b57b104a85
3 changed files with 40 additions and 34 deletions

View File

@@ -2,6 +2,7 @@ import { CommandMessage } from "../../../core/types/commands";
// @ts-ignore // @ts-ignore
import { ComponentType, ButtonStyle, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder, Message, MessageFlags } from "discord.js"; import { ComponentType, ButtonStyle, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder, Message, MessageFlags } from "discord.js";
import { replaceVars, isValidUrlOrVariable, listVariables } from "../../../core/lib/vars"; import { replaceVars, isValidUrlOrVariable, listVariables } from "../../../core/lib/vars";
import { patchMessageWithDisplay } from "../../../core/api/discordAPI";
/** /**
* Botones de edición - VERSIÓN MEJORADA * Botones de edición - VERSIÓN MEJORADA
@@ -217,6 +218,11 @@ const renderPreview = async (blockState: any, member: any, guild: any) => {
}; };
}; };
// Helper para actualizar el editor vía REST y no filtrar display
const updateEditor = async (msg: any, data: any) => {
await patchMessageWithDisplay(msg.channelId, msg.id, data);
};
export const command: CommandMessage = { export const command: CommandMessage = {
name: "crear-embed", name: "crear-embed",
type: "message", type: "message",
@@ -269,10 +275,9 @@ export const command: CommandMessage = {
await new Promise(resolve => setTimeout(resolve, 5000)); await new Promise(resolve => setTimeout(resolve, 5000));
//@ts-ignore //@ts-ignore
await editorMessage.edit({ await updateEditor(editorMessage, {
content: null, content: null,
flags: 4096, flags: 4096,
// @ts-ignore - display (Display Components)
display: await renderPreview(blockState, message.member, message.guild), display: await renderPreview(blockState, message.member, message.guild),
components: btns(false) components: btns(false)
}); });
@@ -309,8 +314,7 @@ export const command: CommandMessage = {
} }
} }
}); });
await editorMessage.edit({ await updateEditor(editorMessage, {
// @ts-ignore
display: { display: {
type: 17, type: 17,
accent_color: blockState.color ?? null, accent_color: blockState.color ?? null,
@@ -490,8 +494,7 @@ export const command: CommandMessage = {
} else if (b.customId === "delete_cover") { } else if (b.customId === "delete_cover") {
blockState.coverImage = null; blockState.coverImage = null;
await b.update({ content: "✅ Imagen de portada eliminada.", components: [] }); await b.update({ content: "✅ Imagen de portada eliminada.", components: [] });
await editorMessage.edit({ await updateEditor(editorMessage, {
// @ts-ignore
display: await renderPreview(blockState, message.member, message.guild), display: await renderPreview(blockState, message.member, message.guild),
components: btns(false) components: btns(false)
}); });
@@ -603,8 +606,7 @@ export const command: CommandMessage = {
await b.update({ content: "✅ Bloque movido abajo.", components: [] }); await b.update({ content: "✅ Bloque movido abajo.", components: [] });
} }
await editorMessage.edit({ await updateEditor(editorMessage, {
// @ts-ignore
display: await renderPreview(blockState, message.member, message.guild), display: await renderPreview(blockState, message.member, message.guild),
components: btns(false) components: btns(false)
}); });
@@ -692,8 +694,7 @@ export const command: CommandMessage = {
await sel.update({ content: "✅ Elemento eliminado.", components: [] }); await sel.update({ content: "✅ Elemento eliminado.", components: [] });
} }
await editorMessage.edit({ await updateEditor(editorMessage, {
// @ts-ignore
display: await renderPreview(blockState, message.member, message.guild), display: await renderPreview(blockState, message.member, message.guild),
components: btns(false) components: btns(false)
}); });
@@ -785,8 +786,7 @@ export const command: CommandMessage = {
blockState.components.splice(idx + 1, 0, duplicatedComponent); blockState.components.splice(idx + 1, 0, duplicatedComponent);
await sel.update({ content: "✅ Elemento duplicado.", components: [] }); await sel.update({ content: "✅ Elemento duplicado.", components: [] });
await editorMessage.edit({ await updateEditor(editorMessage, {
// @ts-ignore
display: await renderPreview(blockState, message.member, message.guild), display: await renderPreview(blockState, message.member, message.guild),
components: btns(false) components: btns(false)
}); });
@@ -1044,7 +1044,7 @@ export const command: CommandMessage = {
} else if (b.customId.startsWith('delete_link_button_')) { } else if (b.customId.startsWith('delete_link_button_')) {
delete textComp.linkButton; delete textComp.linkButton;
await b.update({ content: '✅ Botón link eliminado.', components: [] }); await b.update({ content: '✅ Botón link eliminado.', components: [] });
await editorMessage.edit({ components: [await renderPreview(blockState, message.member, message.guild), ...btns(false)] }); await updateEditor(editorMessage, { components: [await renderPreview(blockState, message.member, message.guild), ...btns(false)] });
} }
}); });
} else { } else {
@@ -1091,8 +1091,7 @@ export const command: CommandMessage = {
} }
} }
await editorMessage.edit({ await updateEditor(editorMessage, {
// @ts-ignore
display: await renderPreview(blockState, message.member, message.guild), display: await renderPreview(blockState, message.member, message.guild),
components: btns(false) components: btns(false)
}); });
@@ -1248,7 +1247,7 @@ export const command: CommandMessage = {
try { try {
const messageExists = await editorMessage.fetch().catch(() => null); const messageExists = await editorMessage.fetch().catch(() => null);
if (!messageExists) return; if (!messageExists) return;
await editorMessage.edit({ // @ts-ignore await updateEditor(editorMessage, { // @ts-ignore
display: await renderPreview(blockState, message.member, message.guild), display: await renderPreview(blockState, message.member, message.guild),
components: btns(false) components: btns(false)
}); });
@@ -1286,7 +1285,7 @@ export const command: CommandMessage = {
try { try {
const messageExists = await editorMessage.fetch().catch(() => null); const messageExists = await editorMessage.fetch().catch(() => null);
if (messageExists) { if (messageExists) {
await editorMessage.edit({ await updateEditor(editorMessage, {
// @ts-ignore // @ts-ignore
display: { display: {
type: 17, type: 17,

View File

@@ -2,6 +2,7 @@ import { CommandMessage } from "../../../core/types/commands";
// @ts-ignore // @ts-ignore
import { ComponentType, ButtonStyle, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder, MessageFlags } from "discord.js"; import { ComponentType, ButtonStyle, ModalBuilder, TextInputBuilder, TextInputStyle, ActionRowBuilder, MessageFlags } from "discord.js";
import { replaceVars, isValidUrlOrVariable, listVariables } from "../../../core/lib/vars"; import { replaceVars, isValidUrlOrVariable, listVariables } from "../../../core/lib/vars";
import { patchMessageWithDisplay } from "../../../core/api/discordAPI";
// Botones de edición (máx 5 por fila) // Botones de edición (máx 5 por fila)
const btns = (disabled = false) => ([ const btns = (disabled = false) => ([
@@ -104,6 +105,11 @@ const renderPreview = async (blockState: any, member: any, guild: any) => {
return { type: 17, accent_color: blockState.color ?? null, components: previewComponents }; return { type: 17, accent_color: blockState.color ?? null, components: previewComponents };
}; };
// Helper para actualizar el editor vía REST y no filtrar display
const updateEditor = async (msg: any, data: any) => {
await patchMessageWithDisplay(msg.channelId, msg.id, data);
};
export const command: CommandMessage = { export const command: CommandMessage = {
name: "editar-embed", name: "editar-embed",
type: "message", type: "message",
@@ -151,10 +157,9 @@ export const command: CommandMessage = {
await new Promise(r => setTimeout(r, 3000)); await new Promise(r => setTimeout(r, 3000));
// @ts-ignore // @ts-ignore
await editorMessage.edit({ await updateEditor(editorMessage, {
content: null, content: null,
flags: 4096, flags: 4096,
// @ts-ignore - Display Components
display: await renderPreview(blockState, message.member, message.guild), display: await renderPreview(blockState, message.member, message.guild),
components: btns(false) components: btns(false)
}); });
@@ -174,7 +179,7 @@ export const command: CommandMessage = {
where: { guildId_name: { guildId: message.guildId!, name: blockName } }, where: { guildId_name: { guildId: message.guildId!, name: blockName } },
data: { config: blockState } data: { config: blockState }
}); });
await editorMessage.edit({ await updateEditor(editorMessage, {
// @ts-ignore // @ts-ignore
display: { display: {
type: 17, type: 17,
@@ -263,7 +268,7 @@ export const command: CommandMessage = {
} else if (b.customId === 'delete_cover') { } else if (b.customId === 'delete_cover') {
blockState.coverImage = null; blockState.coverImage = null;
await b.update({ content: '✅ Imagen de portada eliminada.', components: [] }); await b.update({ content: '✅ Imagen de portada eliminada.', components: [] });
await editorMessage.edit({ // @ts-ignore await updateEditor(editorMessage, { // @ts-ignore
display: await renderPreview(blockState, message.member, message.guild), display: await renderPreview(blockState, message.member, message.guild),
components: btns(false) components: btns(false)
}); });
@@ -316,7 +321,7 @@ export const command: CommandMessage = {
} }
await b.update({ content: '✅ Bloque movido abajo.', components: [] }); await b.update({ content: '✅ Bloque movido abajo.', components: [] });
} }
await editorMessage.edit({ // @ts-ignore await updateEditor(editorMessage, { // @ts-ignore
display: await renderPreview(blockState, message.member, message.guild), display: await renderPreview(blockState, message.member, message.guild),
components: btns(false) components: btns(false)
}); });
@@ -354,7 +359,7 @@ export const command: CommandMessage = {
blockState.components.splice(idx, 1); blockState.components.splice(idx, 1);
await sel.update({ content: '✅ Elemento eliminado.', components: [] }); await sel.update({ content: '✅ Elemento eliminado.', components: [] });
} }
await editorMessage.edit({ // @ts-ignore await updateEditor(editorMessage, { // @ts-ignore
display: await renderPreview(blockState, message.member, message.guild), display: await renderPreview(blockState, message.member, message.guild),
components: btns(false) components: btns(false)
}); });
@@ -408,7 +413,7 @@ export const command: CommandMessage = {
const duplicatedComponent = JSON.parse(JSON.stringify(originalComponent)); const duplicatedComponent = JSON.parse(JSON.stringify(originalComponent));
blockState.components.splice(idx + 1, 0, duplicatedComponent); blockState.components.splice(idx + 1, 0, duplicatedComponent);
await sel.update({ content: '✅ Elemento duplicado.', components: [] }); await sel.update({ content: '✅ Elemento duplicado.', components: [] });
await editorMessage.edit({ // @ts-ignore await updateEditor(editorMessage, { // @ts-ignore
display: await renderPreview(blockState, message.member, message.guild), display: await renderPreview(blockState, message.member, message.guild),
components: btns(false) components: btns(false)
}); });
@@ -519,7 +524,7 @@ export const command: CommandMessage = {
} else if (b.customId.startsWith('delete_link_button_')) { } else if (b.customId.startsWith('delete_link_button_')) {
delete textComp.linkButton; delete textComp.linkButton;
await b.update({ content: '✅ Botón link eliminado.', components: [] }); await b.update({ content: '✅ Botón link eliminado.', components: [] });
await editorMessage.edit({ // @ts-ignore await updateEditor(editorMessage, { // @ts-ignore
display: await renderPreview(blockState, message.member, message.guild), display: await renderPreview(blockState, message.member, message.guild),
components: btns(false) components: btns(false)
}); });
@@ -543,7 +548,7 @@ export const command: CommandMessage = {
} }
} }
await editorMessage.edit({ // @ts-ignore await updateEditor(editorMessage, { // @ts-ignore
display: await renderPreview(blockState, message.member, message.guild), display: await renderPreview(blockState, message.member, message.guild),
components: btns(false) components: btns(false)
}); });
@@ -626,7 +631,7 @@ export const command: CommandMessage = {
try { try {
const exists = await editorMessage.fetch().catch(() => null); const exists = await editorMessage.fetch().catch(() => null);
if (!exists) return; if (!exists) return;
await editorMessage.edit({ // @ts-ignore await updateEditor(editorMessage, { // @ts-ignore
display: await renderPreview(blockState, message.member, message.guild), display: await renderPreview(blockState, message.member, message.guild),
components: btns(false) components: btns(false)
}); });
@@ -643,7 +648,7 @@ export const command: CommandMessage = {
try { try {
const exists = await editorMessage.fetch().catch(() => null); const exists = await editorMessage.fetch().catch(() => null);
if (exists) { if (exists) {
await editorMessage.edit({ // @ts-ignore await updateEditor(editorMessage, { // @ts-ignore
display: { type: 17, components: [{ type: 10, content: '⏰ Editor finalizado por inactividad.' }] }, display: { type: 17, components: [{ type: 10, content: '⏰ Editor finalizado por inactividad.' }] },
components: [] components: []
}); });

View File

@@ -3,6 +3,9 @@ import { REST } from "discord.js";
import { Routes } from "discord-api-types/v10"; import { Routes } from "discord-api-types/v10";
import { commands } from "../loader"; import { commands } from "../loader";
// Reutilizamos una instancia REST singleton
const rest = new REST({ version: '10' }).setToken(process.env.TOKEN ?? "");
export async function registeringCommands(): Promise<void> { export async function registeringCommands(): Promise<void> {
const commandsToRegister: any[] = []; const commandsToRegister: any[] = [];
@@ -20,8 +23,6 @@ export async function registeringCommands(): Promise<void> {
} }
} }
const rest = new REST().setToken(process.env.TOKEN ?? "");
try { try {
console.log(`🧹 Limpiando comandos antiguos/residuales...`); console.log(`🧹 Limpiando comandos antiguos/residuales...`);
@@ -61,8 +62,6 @@ export async function registeringCommands(): Promise<void> {
* Función específica para eliminar TODOS los comandos slash (útil para limpieza) * Función específica para eliminar TODOS los comandos slash (útil para limpieza)
*/ */
export async function clearAllCommands(): Promise<void> { export async function clearAllCommands(): Promise<void> {
const rest = new REST().setToken(process.env.TOKEN ?? "");
try { try {
console.log(`🧹 Eliminando TODOS los comandos slash...`); console.log(`🧹 Eliminando TODOS los comandos slash...`);
@@ -84,8 +83,6 @@ export async function clearAllCommands(): Promise<void> {
* Función para limpiar comandos globales (si los hay) * Función para limpiar comandos globales (si los hay)
*/ */
export async function clearGlobalCommands(): Promise<void> { export async function clearGlobalCommands(): Promise<void> {
const rest = new REST().setToken(process.env.TOKEN ?? "");
try { try {
console.log(`🌍 Eliminando comandos globales...`); console.log(`🌍 Eliminando comandos globales...`);
@@ -99,3 +96,8 @@ export async function clearGlobalCommands(): Promise<void> {
console.error("❌ Error eliminando comandos globales:", error); console.error("❌ Error eliminando comandos globales:", error);
} }
} }
export async function patchMessageWithDisplay(channelId: string, messageId: string, data: any): Promise<void> {
// data puede incluir: content, flags, display (container), components (action rows), etc.
await rest.patch(Routes.channelMessage(channelId, messageId), { body: data });
}