feat: mejorar la presentación de estadísticas y mensajes de error en los comandos de racha, estadísticas y tienda
This commit is contained in:
@@ -29,13 +29,15 @@ export const command: CommandMessage = {
|
||||
|
||||
// Construir bloques de display (evitando type:9 sin accessory)
|
||||
const blocks: any[] = [
|
||||
textBlock(`# 🔥 Racha Diaria de ${message.author.username}`),
|
||||
textBlock(
|
||||
`## <a:0fire:1425690572945100860> Racha diaria de ${message.author.username}`
|
||||
),
|
||||
dividerBlock(),
|
||||
textBlock(
|
||||
`**📊 ESTADÍSTICAS**\n` +
|
||||
`🔥 Racha Actual: **${streak.currentStreak}** días\n` +
|
||||
`⭐ Mejor Racha: **${streak.longestStreak}** días\n` +
|
||||
`📅 Días Activos: **${streak.totalDaysActive}** días`
|
||||
`**<:stats:1425689271788113991> ESTADÍSTICAS**\n` +
|
||||
`<a:0fire:1425690572945100860> Racha Actual: **${streak.currentStreak}** días\n` +
|
||||
`<a:bluestargif:1425691124214927452> Mejor Racha: **${streak.longestStreak}** días\n` +
|
||||
`<:events:1425691310194561106> Días Activos: **${streak.totalDaysActive}** días`
|
||||
),
|
||||
dividerBlock({ spacing: 1 }),
|
||||
];
|
||||
@@ -45,22 +47,23 @@ export const command: CommandMessage = {
|
||||
if (daysIncreased) {
|
||||
blocks.push(
|
||||
textBlock(
|
||||
`**✅ ¡RACHA INCREMENTADA!**\nHas mantenido tu racha por **${streak.currentStreak}** días seguidos.`
|
||||
`**<:Sup_res:1420535051162095747> ¡RACHA INCREMENTADA!**\nHas mantenido tu racha por **${streak.currentStreak}** días seguidos.`
|
||||
)
|
||||
);
|
||||
} else {
|
||||
blocks.push(
|
||||
textBlock(
|
||||
`**⚠️ RACHA REINICIADA**\nPasó más de un día sin actividad. Tu racha se ha reiniciado.`
|
||||
`**<:Sup_urg:1420535068056748042> RACHA REINICIADA**\nPasó más de un día sin actividad. Tu racha se ha reiniciado.`
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
// Mostrar recompensas
|
||||
if (rewards) {
|
||||
let rewardsText = "**🎁 RECOMPENSA DEL DÍA**\n";
|
||||
let rewardsText =
|
||||
"**<a:Chest:1425691840614764645> RECOMPENSA DEL DÍA**\n";
|
||||
if (rewards.coins)
|
||||
rewardsText += `💰 **${rewards.coins.toLocaleString()}** monedas\n`;
|
||||
rewardsText += `<:coin:1425667511013081169> **${rewards.coins.toLocaleString()}** monedas\n`;
|
||||
if (rewards.items && rewards.items.length) {
|
||||
const basics = await fetchItemBasics(
|
||||
guildId,
|
||||
@@ -83,7 +86,7 @@ export const command: CommandMessage = {
|
||||
} else {
|
||||
blocks.push(
|
||||
textBlock(
|
||||
`**ℹ️ YA RECLAMASTE HOY**\nYa has reclamado tu recompensa diaria. Vuelve mañana para continuar tu racha.`
|
||||
`**<:apin:1336533845541126174> YA RECLAMASTE HOY**\nYa has reclamado tu recompensa diaria. Vuelve mañana para continuar tu racha.`
|
||||
)
|
||||
);
|
||||
}
|
||||
@@ -107,7 +110,9 @@ export const command: CommandMessage = {
|
||||
await sendDisplayReply(message, display);
|
||||
} catch (error) {
|
||||
console.error("Error en comando racha:", error);
|
||||
await message.reply("❌ Error al obtener tu racha diaria.");
|
||||
await message.reply(
|
||||
"<:Cross:1420535096208920576> Error al obtener tu racha diaria."
|
||||
);
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
import type { CommandMessage } from '../../../core/types/commands';
|
||||
import type Amayo from '../../../core/client';
|
||||
import { getPlayerStatsFormatted } from '../../../game/stats/service';
|
||||
import type { TextBasedChannel } from 'discord.js';
|
||||
import type { CommandMessage } from "../../../core/types/commands";
|
||||
import type Amayo from "../../../core/client";
|
||||
import { getPlayerStatsFormatted } from "../../../game/stats/service";
|
||||
import type { TextBasedChannel } from "discord.js";
|
||||
|
||||
export const command: CommandMessage = {
|
||||
name: 'stats',
|
||||
type: 'message',
|
||||
aliases: ['estadisticas', 'est'],
|
||||
name: "stats",
|
||||
type: "message",
|
||||
aliases: ["estadisticas", "est"],
|
||||
cooldown: 5,
|
||||
description: 'Ver estadísticas detalladas de un jugador',
|
||||
usage: 'stats [@usuario]',
|
||||
description: "Ver estadísticas detalladas de un jugador",
|
||||
usage: "stats [@usuario]",
|
||||
run: async (message, args, client: Amayo) => {
|
||||
try {
|
||||
const guildId = message.guild!.id;
|
||||
@@ -20,52 +20,75 @@ export const command: CommandMessage = {
|
||||
const stats = await getPlayerStatsFormatted(userId, guildId);
|
||||
|
||||
const formatValue = (value: unknown): string => {
|
||||
if (typeof value === 'number') return value.toLocaleString();
|
||||
if (typeof value === 'bigint') return value.toString();
|
||||
if (typeof value === 'string') return value.trim() || '0';
|
||||
return value == null ? '0' : String(value);
|
||||
if (typeof value === "number") return value.toLocaleString();
|
||||
if (typeof value === "bigint") return value.toString();
|
||||
if (typeof value === "string") return value.trim() || "0";
|
||||
return value == null ? "0" : String(value);
|
||||
};
|
||||
|
||||
const components: any[] = [
|
||||
{
|
||||
type: 10,
|
||||
content: `# 📊 Estadísticas de ${targetUser.username}`
|
||||
content: `## <:stats:1425689271788113991> Estadísticas de ${targetUser.username}`,
|
||||
},
|
||||
{ type: 14, divider: true }
|
||||
{ type: 14, divider: false, spacing: 1 },
|
||||
];
|
||||
|
||||
const addSection = (title: string, data?: Record<string, unknown>) => {
|
||||
if (!data || typeof data !== 'object') return;
|
||||
if (!data || typeof data !== "object") return;
|
||||
const entries = Object.entries(data);
|
||||
const lines = entries.map(([key, value]) => `${key}: **${formatValue(value)}**`);
|
||||
const content = lines.length > 0 ? lines.join('\n') : 'Sin datos';
|
||||
const lines = entries.map(
|
||||
([key, value]) => `${key}: **${formatValue(value)}**`
|
||||
);
|
||||
const content = lines.length > 0 ? lines.join("\n") : "Sin datos";
|
||||
components.push({
|
||||
type: 10,
|
||||
content: `**${title}**\n${content}`
|
||||
content: `**${title}**\n${content}`,
|
||||
});
|
||||
components.push({ type: 14, divider: false, spacing: 1 });
|
||||
};
|
||||
|
||||
addSection('🎮 ACTIVIDADES', stats.activities as Record<string, unknown> | undefined);
|
||||
addSection('⚔️ COMBATE', stats.combat as Record<string, unknown> | undefined);
|
||||
addSection('💰 ECONOMÍA', stats.economy as Record<string, unknown> | undefined);
|
||||
addSection('📦 ITEMS', stats.items as Record<string, unknown> | undefined);
|
||||
addSection('🏆 RÉCORDS', stats.records as Record<string, unknown> | undefined);
|
||||
addSection(
|
||||
"<:stats:1425689271788113991> ACTIVIDADES",
|
||||
stats.activities as Record<string, unknown> | undefined
|
||||
);
|
||||
addSection(
|
||||
"<:damage:1425670476449189998> COMBATE",
|
||||
stats.combat as Record<string, unknown> | undefined
|
||||
);
|
||||
addSection(
|
||||
"<:coin:1425667511013081169> ECONOMÍA",
|
||||
stats.economy as Record<string, unknown> | undefined
|
||||
);
|
||||
addSection(
|
||||
"<:emptybox:1425678700753588305> ITEMS",
|
||||
stats.items as Record<string, unknown> | undefined
|
||||
);
|
||||
addSection(
|
||||
"<a:trophy:1425690252118462526> RÉCORDS",
|
||||
stats.records as Record<string, unknown> | undefined
|
||||
);
|
||||
|
||||
// Remove trailing separator if present
|
||||
if (components.length > 0 && components[components.length - 1]?.type === 14) {
|
||||
if (
|
||||
components.length > 0 &&
|
||||
components[components.length - 1]?.type === 14
|
||||
) {
|
||||
components.pop();
|
||||
}
|
||||
|
||||
if (components.length === 1) {
|
||||
components.push({ type: 10, content: '*Sin estadísticas registradas.*' });
|
||||
components.push({
|
||||
type: 10,
|
||||
content: "*Sin estadísticas registradas.*",
|
||||
});
|
||||
}
|
||||
|
||||
// Crear DisplayComponent
|
||||
const display = {
|
||||
type: 17,
|
||||
accent_color: 0x5865F2,
|
||||
components
|
||||
accent_color: 0x5865f2,
|
||||
components,
|
||||
};
|
||||
|
||||
// Enviar con flags
|
||||
@@ -74,11 +97,13 @@ export const command: CommandMessage = {
|
||||
content: null,
|
||||
components: [display],
|
||||
flags: 32768, // MessageFlags.IS_COMPONENTS_V2
|
||||
reply: { messageReference: message.id }
|
||||
reply: { messageReference: message.id },
|
||||
});
|
||||
} catch (error) {
|
||||
console.error('Error en comando stats:', error);
|
||||
await message.reply('❌ Error al obtener las estadísticas.');
|
||||
console.error("Error en comando stats:", error);
|
||||
await message.reply(
|
||||
"<:Cross:1420535096208920576> Error al obtener las estadísticas."
|
||||
);
|
||||
}
|
||||
}
|
||||
},
|
||||
};
|
||||
|
||||
@@ -178,7 +178,9 @@ export const command: CommandMessage = {
|
||||
console.error("Error handling shop interaction:", error);
|
||||
if (!interaction.replied && !interaction.deferred) {
|
||||
await interaction.reply({
|
||||
content: `❌ Error: ${error?.message ?? error}`,
|
||||
content: `<:Cross:1420535096208920576> Error: ${
|
||||
error?.message ?? error
|
||||
}`,
|
||||
flags: MessageFlags.Ephemeral,
|
||||
});
|
||||
}
|
||||
@@ -229,7 +231,7 @@ async function buildShopPanel(
|
||||
},
|
||||
{
|
||||
type: 14,
|
||||
divider: true,
|
||||
divider: false,
|
||||
spacing: 2,
|
||||
},
|
||||
],
|
||||
@@ -277,13 +279,13 @@ async function buildShopPanel(
|
||||
container.components.push({
|
||||
type: 10,
|
||||
content: `${label}\n\n${
|
||||
item.description || undefined
|
||||
item.description || null
|
||||
}${statsInfo}\n\nPrecio: ${price}${stockInfo}`,
|
||||
});
|
||||
|
||||
container.components.push({
|
||||
type: 14,
|
||||
divider: true,
|
||||
divider: false,
|
||||
spacing: 1,
|
||||
});
|
||||
}
|
||||
@@ -308,7 +310,7 @@ async function buildShopPanel(
|
||||
|
||||
const stockText =
|
||||
offer.stock != null ? ` (${offer.stock} disponibles)` : "";
|
||||
const selectedMark = isSelected ? " ✓" : "";
|
||||
const selectedMark = isSelected ? " <a:Sparkles:1321196183133098056>" : "";
|
||||
|
||||
container.components.push({
|
||||
type: 9,
|
||||
|
||||
Reference in New Issue
Block a user