Add confirmation button event
This commit is contained in:
parent
d874cb7a12
commit
b37c087393
2 changed files with 30 additions and 4 deletions
|
@ -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 {Command} from "../type/command";
|
||||||
import EffectHelper from "../helpers/EffectHelper";
|
import EffectHelper from "../helpers/EffectHelper";
|
||||||
import {EffectDetails} from "../constants/EffectDetails";
|
import {EffectDetails} from "../constants/EffectDetails";
|
||||||
import UserEffect from "../database/entities/app/UserEffect";
|
import UserEffect from "../database/entities/app/UserEffect";
|
||||||
|
import TimeLengthInput from "../helpers/TimeLengthInput";
|
||||||
|
|
||||||
export default class Effects extends Command {
|
export default class Effects extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -68,13 +69,15 @@ export default class Effects extends Command {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const canUseEffect = await EffectHelper.CanUseEffect(interaction.user.id, id)
|
const canUseEffect = await EffectHelper.CanUseEffect(interaction.user.id, id);
|
||||||
|
|
||||||
if (!canUseEffect) {
|
if (!canUseEffect) {
|
||||||
await interaction.reply("Unable to use effect! Please make sure you have it in your inventory and is not on cooldown");
|
await interaction.reply("Unable to use effect! Please make sure you have it in your inventory and is not on cooldown");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const timeLengthInput = TimeLengthInput.ConvertFromMilliseconds(effectDetail.duration);
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle("Effect Confirmation")
|
.setTitle("Effect Confirmation")
|
||||||
.setDescription("Would you like to use this effect?")
|
.setDescription("Would you like to use this effect?")
|
||||||
|
@ -86,11 +89,22 @@ export default class Effects extends Command {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Length",
|
name: "Length",
|
||||||
value: "",
|
value: timeLengthInput.GetLengthShort(),
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
await interaction.reply({ embeds: [ embed ] });
|
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||||
|
.addComponents([
|
||||||
|
new ButtonBuilder()
|
||||||
|
.setLabel("Confirm")
|
||||||
|
.setCustomId(`effects use confirm ${effectDetail.id}`)
|
||||||
|
.setStyle(ButtonStyle.Primary),
|
||||||
|
]);
|
||||||
|
|
||||||
|
await interaction.reply({
|
||||||
|
embeds: [ embed ],
|
||||||
|
components: [ row ],
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,5 +120,17 @@ export default class TimeLengthInput {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static ConvertFromMilliseconds(ms: number): 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
Reference in a new issue