diff --git a/src/commands/effects.ts b/src/commands/effects.ts index 3fe30ef..13e7eeb 100644 --- a/src/commands/effects.ts +++ b/src/commands/effects.ts @@ -1,8 +1,9 @@ -import {CommandInteraction, EmbedBuilder, SlashCommandBuilder} from "discord.js"; +import {ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder, SlashCommandBuilder} from "discord.js"; import {Command} from "../type/command"; import EffectHelper from "../helpers/EffectHelper"; import {EffectDetails} from "../constants/EffectDetails"; import UserEffect from "../database/entities/app/UserEffect"; +import TimeLengthInput from "../helpers/TimeLengthInput"; export default class Effects extends Command { constructor() { @@ -68,13 +69,15 @@ export default class Effects extends Command { return; } - const canUseEffect = await EffectHelper.CanUseEffect(interaction.user.id, id) + const canUseEffect = await EffectHelper.CanUseEffect(interaction.user.id, id); if (!canUseEffect) { await interaction.reply("Unable to use effect! Please make sure you have it in your inventory and is not on cooldown"); return; } + const timeLengthInput = TimeLengthInput.ConvertFromMilliseconds(effectDetail.duration); + const embed = new EmbedBuilder() .setTitle("Effect Confirmation") .setDescription("Would you like to use this effect?") @@ -86,11 +89,22 @@ export default class Effects extends Command { }, { name: "Length", - value: "", + value: timeLengthInput.GetLengthShort(), inline: true, }, ]); - await interaction.reply({ embeds: [ embed ] }); + const row = new ActionRowBuilder() + .addComponents([ + new ButtonBuilder() + .setLabel("Confirm") + .setCustomId(`effects use confirm ${effectDetail.id}`) + .setStyle(ButtonStyle.Primary), + ]); + + await interaction.reply({ + embeds: [ embed ], + components: [ row ], + }); } } diff --git a/src/helpers/TimeLengthInput.ts b/src/helpers/TimeLengthInput.ts index 8fa232d..aef58ba 100644 --- a/src/helpers/TimeLengthInput.ts +++ b/src/helpers/TimeLengthInput.ts @@ -120,5 +120,17 @@ export default class TimeLengthInput { } public static ConvertFromMilliseconds(ms: number): TimeLengthInput { + const seconds = Math.floor(ms / 1000); + const minutes = Math.floor(seconds / 60); + const hours = Math.floor(minutes / 60); + const days = Math.floor(hours / 24); + + const remainingSeconds = seconds % 60; + const remainingMinutes = minutes % 60; + const remainingHours = hours % 24; + + const timeString = `${days}d ${remainingHours}h ${remainingMinutes}m ${remainingSeconds}s`; + + return new TimeLengthInput(timeString); } } \ No newline at end of file