From adb8c503f3f82041d7115f2bbb1479a18ca33821 Mon Sep 17 00:00:00 2001 From: shni Date: Fri, 3 Oct 2025 20:59:22 -0500 Subject: [PATCH] feat: simplify point management modal by removing unnecessary inputs and enhancing total points input --- src/components/modals/ldPointsModal.ts | 54 ++++++++++------------ src/components/selectmenus/ldSelectUser.ts | 32 ++++--------- 2 files changed, 33 insertions(+), 53 deletions(-) diff --git a/src/components/modals/ldPointsModal.ts b/src/components/modals/ldPointsModal.ts index 2b0f905..b2348be 100644 --- a/src/components/modals/ldPointsModal.ts +++ b/src/components/modals/ldPointsModal.ts @@ -36,15 +36,13 @@ export default { }); } - // Obtener valores del modal + // Obtener valor del modal + // @ts-ignore const totalInput = interaction.fields.getTextInputValue('total_points').trim(); - const weeklyInput = interaction.fields.getTextInputValue('weekly_points').trim(); - const monthlyInput = interaction.fields.getTextInputValue('monthly_points').trim(); - // Si no se ingresó nada, retornar - if (!totalInput && !weeklyInput && !monthlyInput) { + if (!totalInput) { return interaction.reply({ - content: '❌ Debes ingresar al menos un valor para modificar.', + content: '❌ Debes ingresar un valor para modificar.', flags: MessageFlags.Ephemeral }); } @@ -74,16 +72,19 @@ export default { // Función para parsear el input y calcular el nuevo valor const calculateNewValue = (input: string, currentValue: number): number => { - if (!input) return currentValue; - const firstChar = input[0]; - const numValue = parseInt(input.substring(1)) || 0; if (firstChar === '+') { + // Añadir puntos + const numValue = parseInt(input.substring(1)) || 0; return Math.max(0, currentValue + numValue); } else if (firstChar === '-') { + // Quitar puntos (los últimos N puntos añadidos) + const numValue = parseInt(input.substring(1)) || 0; return Math.max(0, currentValue - numValue); } else if (firstChar === '=') { + // Establecer valor absoluto + const numValue = parseInt(input.substring(1)) || 0; return Math.max(0, numValue); } else { // Si no tiene símbolo, tratar como valor absoluto @@ -92,13 +93,11 @@ export default { } }; - // Calcular nuevos valores + // Calcular nuevo valor de puntos totales const newTotalPoints = calculateNewValue(totalInput, stats.totalPoints); - const newWeeklyPoints = calculateNewValue(weeklyInput, stats.weeklyPoints); - const newMonthlyPoints = calculateNewValue(monthlyInput, stats.monthlyPoints); - // Actualizar en base de datos - const updatedStats = await prisma.partnershipStats.update({ + // Actualizar en base de datos (solo puntos totales) + await prisma.partnershipStats.update({ where: { userId_guildId: { userId, @@ -106,9 +105,7 @@ export default { } }, data: { - totalPoints: newTotalPoints, - weeklyPoints: newWeeklyPoints, - monthlyPoints: newMonthlyPoints + totalPoints: newTotalPoints } }); @@ -126,26 +123,25 @@ export default { } } + // Calcular la diferencia + const difference = newTotalPoints - stats.totalPoints; + const diffText = difference > 0 ? `+${difference}` : `${difference}`; + // Crear embed de confirmación const embed = new EmbedBuilder() - .setColor(0x00ff00) + .setColor(difference >= 0 ? 0x00ff00 : 0xff9900) .setTitle('✅ Puntos Actualizados') .setDescription(`Se han actualizado los puntos de **${userName}**`) .addFields( { name: '📊 Puntos Totales', - value: `${stats.totalPoints} → **${newTotalPoints}**`, - inline: true + value: `${stats.totalPoints} → **${newTotalPoints}** (${diffText})`, + inline: false }, - { - name: '📅 Puntos Semanales', - value: `${stats.weeklyPoints} → **${newWeeklyPoints}**`, - inline: true - }, - { - name: '🗓️ Puntos Mensuales', - value: `${stats.monthlyPoints} → **${newMonthlyPoints}**`, - inline: true + { + name: '📝 Operación', + value: `\`${totalInput}\``, + inline: false } ) .setFooter({ text: `Modificado por ${interaction.user.username}` }) diff --git a/src/components/selectmenus/ldSelectUser.ts b/src/components/selectmenus/ldSelectUser.ts index 15f8254..8c47826 100644 --- a/src/components/selectmenus/ldSelectUser.ts +++ b/src/components/selectmenus/ldSelectUser.ts @@ -40,35 +40,19 @@ export default { .setCustomId(`ld_points_modal:${selectedUserId}`) .setTitle(`Gestionar puntos de ${userName}`); - // Input para puntos totales + // Input para puntos totales (simplificado) const totalInput = new TextInputBuilder() .setCustomId('total_points') - .setLabel('Puntos Totales') - .setPlaceholder('+50 (añadir) / -25 (quitar) / =100 (establecer)') + .setLabel('Modificar Puntos Totales') + .setPlaceholder('+50 (añadir) / -2 (quitar últimos 2) / =100 (establecer)') .setStyle(TextInputStyle.Short) - .setRequired(false); + .setRequired(true); - // Input para puntos semanales - const weeklyInput = new TextInputBuilder() - .setCustomId('weekly_points') - .setLabel('Puntos Semanales') - .setPlaceholder('+10 (añadir) / -5 (quitar) / =50 (establecer)') - .setStyle(TextInputStyle.Short) - .setRequired(false); - - // Input para puntos mensuales - const monthlyInput = new TextInputBuilder() - .setCustomId('monthly_points') - .setLabel('Puntos Mensuales') - .setPlaceholder('+20 (añadir) / -10 (quitar) / =75 (establecer)') - .setStyle(TextInputStyle.Short) - .setRequired(false); - - // Añadir los inputs al modal + // Añadir el input al modal + // @ts-ignore modal.addComponents( - new ActionRowBuilder().addComponents(totalInput), - new ActionRowBuilder().addComponents(weeklyInput), - new ActionRowBuilder().addComponents(monthlyInput) + // @ts-ignore + new ActionRowBuilder().addComponents(totalInput) ); await interaction.showModal(modal);