feat: add memory refresh button and update admin panel with memory usage details

This commit is contained in:
2025-09-23 23:37:50 -05:00
parent acb41f8a46
commit eb92edb19a
2 changed files with 82 additions and 33 deletions

View File

@@ -4,6 +4,59 @@ import { CommandMessage } from "../../../core/types/commands";
const OWNER_ID = '327207082203938818';
function formatBytesMB(bytes: number) {
return (bytes / 1024 / 1024).toFixed(1) + 'MB';
}
function buildAdminPanel() {
const m = process.memoryUsage();
const rss = formatBytesMB(m.rss);
const heapUsed = formatBytesMB(m.heapUsed);
const heapTotal = formatBytesMB(m.heapTotal);
const ext = formatBytesMB(m.external);
const now = new Date();
const ts = now.toISOString().replace('T', ' ').split('.')[0];
return {
type: 17,
accent_color: 0x2b2d31,
components: [
{
type: 10,
content: '### 🛠️ Panel de Administración de Comandos\nGestiona el registro y limpieza de comandos **Slash**.'
},
{ type: 14, divider: true, spacing: 1 },
{
type: 10,
content: 'Acciones disponibles:\n• Registrar comandos de GUILD (testing)\n• Registrar comandos GLOBAL (propagación lenta)\n• Limpiar comandos de GUILD\n• Limpiar comandos GLOBAL\n\nUsa los botones de abajo. Se evita ejecución simultánea.'
},
{ type: 14, divider: true, spacing: 1 },
{
type: 10,
content: `**Memoria (actual)**\n• RSS: ${rss}\n• Heap Used: ${heapUsed}\n• Heap Total: ${heapTotal}\n• External: ${ext}\n\nÚltima actualización: ${ts} UTC`
},
{ type: 14, divider: false, spacing: 1 },
// Fila 1 (acciones de registro)
{
type: 1,
components: [
{ type: 2, style: 1, label: 'Registrar GUILD', custom_id: 'cmd_reg_guild' },
{ type: 2, style: 1, label: 'Registrar GLOBAL', custom_id: 'cmd_reg_global' },
{ type: 2, style: 2, label: '🔄 Refrescar Memoria', custom_id: 'cmd_mem_refresh' }
]
},
// Fila 2 (acciones de limpieza)
{
type: 1,
components: [
{ type: 2, style: 4, label: 'Limpiar GUILD', custom_id: 'cmd_clear_guild' },
{ type: 2, style: 4, label: 'Limpiar GLOBAL', custom_id: 'cmd_clear_global' }
]
}
]
};
}
export const command: CommandMessage = {
name: 'admin-comandos',
type: 'message',
@@ -15,42 +68,14 @@ export const command: CommandMessage = {
return;
}
const panel = {
type: 17,
accent_color: 0x2b2d31,
components: [
{
type: 10,
content: '### 🛠️ Panel de Administración de Comandos\nGestiona el registro y limpieza de comandos **Slash**.'
},
{ type: 14, divider: true, spacing: 1 },
{
type: 10,
content: 'Acciones disponibles:\n• Registrar comandos de GUILD (testing)\n• Registrar comandos GLOBAL (propagación lenta)\n• Limpiar comandos de GUILD\n• Limpiar comandos GLOBAL\n\nUsa los botones de abajo. Se evita ejecución simultánea.'
}
]
};
const rows = [
{
type: 1,
components: [
{ type: 2, style: 1, label: 'Registrar GUILD', custom_id: 'cmd_reg_guild' },
{ type: 2, style: 1, label: 'Registrar GLOBAL', custom_id: 'cmd_reg_global' }
]
},
{
type: 1,
components: [
{ type: 2, style: 4, label: 'Limpiar GUILD', custom_id: 'cmd_clear_guild' },
{ type: 2, style: 4, label: 'Limpiar GLOBAL', custom_id: 'cmd_clear_global' }
]
}
];
const panel = buildAdminPanel();
await message.reply({
flags: 32768,
components: [panel, ...rows]
components: [panel]
});
}
};
// Exportamos builder para reutilizar en el botón de refresco
export { buildAdminPanel };

View File

@@ -0,0 +1,24 @@
import type { ButtonInteraction } from 'discord.js';
import { buildAdminPanel } from '../../commands/messages/net/commandsAdmin';
const OWNER_ID = '327207082203938818';
export default {
customId: 'cmd_mem_refresh',
run: async (interaction: ButtonInteraction) => {
if (interaction.user.id !== OWNER_ID) {
return interaction.reply({ content: '❌ No autorizado.', ephemeral: true });
}
try {
await interaction.deferUpdate();
const panel = buildAdminPanel();
// Edita el mensaje original reemplazando componentes (solo el contenedor con filas internas)
await interaction.message.edit({ components: [panel] });
} catch (e) {
console.error('Error refrescando panel de memoria:', e);
if (!interaction.deferred && !interaction.replied)
await interaction.reply({ content: '❌ Error refrescando panel.', ephemeral: true });
}
}
};