feat: simplify point management modal by removing unnecessary inputs and enhancing total points input
This commit is contained in:
@@ -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 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) {
|
||||||
if (!totalInput && !weeklyInput && !monthlyInput) {
|
|
||||||
return interaction.reply({
|
return interaction.reply({
|
||||||
content: '❌ Debes ingresar al menos un valor para modificar.',
|
content: '❌ Debes ingresar un valor para modificar.',
|
||||||
flags: MessageFlags.Ephemeral
|
flags: MessageFlags.Ephemeral
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -74,16 +72,19 @@ export default {
|
|||||||
|
|
||||||
// Función para parsear el input y calcular el nuevo valor
|
// Función para parsear el input y calcular el nuevo valor
|
||||||
const calculateNewValue = (input: string, currentValue: number): number => {
|
const calculateNewValue = (input: string, currentValue: number): number => {
|
||||||
if (!input) return currentValue;
|
|
||||||
|
|
||||||
const firstChar = input[0];
|
const firstChar = input[0];
|
||||||
const numValue = parseInt(input.substring(1)) || 0;
|
|
||||||
|
|
||||||
if (firstChar === '+') {
|
if (firstChar === '+') {
|
||||||
|
// Añadir puntos
|
||||||
|
const numValue = parseInt(input.substring(1)) || 0;
|
||||||
return Math.max(0, currentValue + numValue);
|
return Math.max(0, currentValue + numValue);
|
||||||
} else if (firstChar === '-') {
|
} else if (firstChar === '-') {
|
||||||
|
// Quitar puntos (los últimos N puntos añadidos)
|
||||||
|
const numValue = parseInt(input.substring(1)) || 0;
|
||||||
return Math.max(0, currentValue - numValue);
|
return Math.max(0, currentValue - numValue);
|
||||||
} else if (firstChar === '=') {
|
} else if (firstChar === '=') {
|
||||||
|
// Establecer valor absoluto
|
||||||
|
const numValue = parseInt(input.substring(1)) || 0;
|
||||||
return Math.max(0, numValue);
|
return Math.max(0, numValue);
|
||||||
} else {
|
} else {
|
||||||
// Si no tiene símbolo, tratar como valor absoluto
|
// 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 newTotalPoints = calculateNewValue(totalInput, stats.totalPoints);
|
||||||
const newWeeklyPoints = calculateNewValue(weeklyInput, stats.weeklyPoints);
|
|
||||||
const newMonthlyPoints = calculateNewValue(monthlyInput, stats.monthlyPoints);
|
|
||||||
|
|
||||||
// Actualizar en base de datos
|
// Actualizar en base de datos (solo puntos totales)
|
||||||
const updatedStats = await prisma.partnershipStats.update({
|
await prisma.partnershipStats.update({
|
||||||
where: {
|
where: {
|
||||||
userId_guildId: {
|
userId_guildId: {
|
||||||
userId,
|
userId,
|
||||||
@@ -106,9 +105,7 @@ export default {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
data: {
|
data: {
|
||||||
totalPoints: newTotalPoints,
|
totalPoints: newTotalPoints
|
||||||
weeklyPoints: newWeeklyPoints,
|
|
||||||
monthlyPoints: newMonthlyPoints
|
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -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
|
// Crear embed de confirmación
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setColor(0x00ff00)
|
.setColor(difference >= 0 ? 0x00ff00 : 0xff9900)
|
||||||
.setTitle('✅ Puntos Actualizados')
|
.setTitle('✅ Puntos Actualizados')
|
||||||
.setDescription(`Se han actualizado los puntos de **${userName}**`)
|
.setDescription(`Se han actualizado los puntos de **${userName}**`)
|
||||||
.addFields(
|
.addFields(
|
||||||
{
|
{
|
||||||
name: '📊 Puntos Totales',
|
name: '📊 Puntos Totales',
|
||||||
value: `${stats.totalPoints} → **${newTotalPoints}**`,
|
value: `${stats.totalPoints} → **${newTotalPoints}** (${diffText})`,
|
||||||
inline: true
|
inline: false
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: '📅 Puntos Semanales',
|
name: '📝 Operación',
|
||||||
value: `${stats.weeklyPoints} → **${newWeeklyPoints}**`,
|
value: `\`${totalInput}\``,
|
||||||
inline: true
|
inline: false
|
||||||
},
|
|
||||||
{
|
|
||||||
name: '🗓️ Puntos Mensuales',
|
|
||||||
value: `${stats.monthlyPoints} → **${newMonthlyPoints}**`,
|
|
||||||
inline: true
|
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
.setFooter({ text: `Modificado por ${interaction.user.username}` })
|
.setFooter({ text: `Modificado por ${interaction.user.username}` })
|
||||||
|
|||||||
@@ -40,35 +40,19 @@ export default {
|
|||||||
.setCustomId(`ld_points_modal:${selectedUserId}`)
|
.setCustomId(`ld_points_modal:${selectedUserId}`)
|
||||||
.setTitle(`Gestionar puntos de ${userName}`);
|
.setTitle(`Gestionar puntos de ${userName}`);
|
||||||
|
|
||||||
// Input para puntos totales
|
// Input para puntos totales (simplificado)
|
||||||
const totalInput = new TextInputBuilder()
|
const totalInput = new TextInputBuilder()
|
||||||
.setCustomId('total_points')
|
.setCustomId('total_points')
|
||||||
.setLabel('Puntos Totales')
|
.setLabel('Modificar Puntos Totales')
|
||||||
.setPlaceholder('+50 (añadir) / -25 (quitar) / =100 (establecer)')
|
.setPlaceholder('+50 (añadir) / -2 (quitar últimos 2) / =100 (establecer)')
|
||||||
.setStyle(TextInputStyle.Short)
|
.setStyle(TextInputStyle.Short)
|
||||||
.setRequired(false);
|
.setRequired(true);
|
||||||
|
|
||||||
// Input para puntos semanales
|
// Añadir el input al modal
|
||||||
const weeklyInput = new TextInputBuilder()
|
// @ts-ignore
|
||||||
.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
|
|
||||||
modal.addComponents(
|
modal.addComponents(
|
||||||
new ActionRowBuilder<TextInputBuilder>().addComponents(totalInput),
|
// @ts-ignore
|
||||||
new ActionRowBuilder<TextInputBuilder>().addComponents(weeklyInput),
|
new ActionRowBuilder().addComponents(totalInput)
|
||||||
new ActionRowBuilder<TextInputBuilder>().addComponents(monthlyInput)
|
|
||||||
);
|
);
|
||||||
|
|
||||||
await interaction.showModal(modal);
|
await interaction.showModal(modal);
|
||||||
|
|||||||
Reference in New Issue
Block a user