Compare commits
No commits in common. "dd1f25917062b527826c84793c53a160966530e6" and "d874cb7a12b16e2ad693f097f2b9bacab5c2eafd" have entirely different histories.
dd1f259170
...
d874cb7a12
3 changed files with 7 additions and 111 deletions
|
@ -1,9 +1,7 @@
|
||||||
import {ActionRowBuilder, ButtonBuilder, ButtonInteraction,ButtonStyle,Embed,EmbedBuilder} from "discord.js";
|
import {ButtonInteraction,EmbedBuilder} from "discord.js";
|
||||||
import {ButtonEvent} from "../type/buttonEvent";
|
import {ButtonEvent} from "../type/buttonEvent";
|
||||||
import EffectHelper from "../helpers/EffectHelper";
|
import EffectHelper from "../helpers/EffectHelper";
|
||||||
import { EffectDetails } from "../constants/EffectDetails";
|
import { EffectDetails } from "../constants/EffectDetails";
|
||||||
import TimeLengthInput from "../helpers/TimeLengthInput";
|
|
||||||
import EmbedColours from "../constants/EmbedColours";
|
|
||||||
|
|
||||||
export default class Effects extends ButtonEvent {
|
export default class Effects extends ButtonEvent {
|
||||||
public override async execute(interaction: ButtonInteraction) {
|
public override async execute(interaction: ButtonInteraction) {
|
||||||
|
@ -44,9 +42,6 @@ export default class Effects extends ButtonEvent {
|
||||||
case "confirm":
|
case "confirm":
|
||||||
await this.UseConfirm(interaction);
|
await this.UseConfirm(interaction);
|
||||||
break;
|
break;
|
||||||
case "cancel":
|
|
||||||
await this.UseCancel(interaction);
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -69,7 +64,6 @@ export default class Effects extends ButtonEvent {
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
.setTitle("Effect Used")
|
.setTitle("Effect Used")
|
||||||
.setDescription("You now have an active effect!")
|
.setDescription("You now have an active effect!")
|
||||||
.setColor(EmbedColours.Green)
|
|
||||||
.addFields([
|
.addFields([
|
||||||
{
|
{
|
||||||
name: "Effect",
|
name: "Effect",
|
||||||
|
@ -83,76 +77,10 @@ export default class Effects extends ButtonEvent {
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
await interaction.update({ embeds: [ embed ] });
|
||||||
.addComponents([
|
|
||||||
new ButtonBuilder()
|
|
||||||
.setLabel("Confirm")
|
|
||||||
.setCustomId(`effects use confirm ${effectDetail.id}`)
|
|
||||||
.setStyle(ButtonStyle.Primary)
|
|
||||||
.setDisabled(true),
|
|
||||||
new ButtonBuilder()
|
|
||||||
.setLabel("Cancel")
|
|
||||||
.setCustomId(`effects use cancel ${effectDetail.id}`)
|
|
||||||
.setStyle(ButtonStyle.Danger)
|
|
||||||
.setDisabled(true),
|
|
||||||
]);
|
|
||||||
|
|
||||||
await interaction.update({
|
|
||||||
embeds: [ embed ],
|
|
||||||
components: [ row ],
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
private async UseCancel(interaction: ButtonInteraction) {
|
|
||||||
const id = interaction.customId.split(" ")[3];
|
|
||||||
|
|
||||||
const effectDetail = EffectDetails.get(id);
|
|
||||||
|
|
||||||
if (!effectDetail) {
|
|
||||||
await interaction.reply("Unable to find effect!");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const timeLengthInput = TimeLengthInput.ConvertFromMilliseconds(effectDetail.duration);
|
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
|
||||||
.setTitle("Effect Use Cancelled")
|
|
||||||
.setDescription("The effect from your inventory has not been used")
|
|
||||||
.setColor(EmbedColours.Grey)
|
|
||||||
.addFields([
|
|
||||||
{
|
|
||||||
name: "Effect",
|
|
||||||
value: effectDetail.friendlyName,
|
|
||||||
inline: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "Expires",
|
|
||||||
value: timeLengthInput.GetLengthShort(),
|
|
||||||
inline: true,
|
|
||||||
},
|
|
||||||
]);
|
|
||||||
|
|
||||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
|
||||||
.addComponents([
|
|
||||||
new ButtonBuilder()
|
|
||||||
.setLabel("Confirm")
|
|
||||||
.setCustomId(`effects use confirm ${effectDetail.id}`)
|
|
||||||
.setStyle(ButtonStyle.Primary)
|
|
||||||
.setDisabled(true),
|
|
||||||
new ButtonBuilder()
|
|
||||||
.setLabel("Cancel")
|
|
||||||
.setCustomId(`effects use cancel ${effectDetail.id}`)
|
|
||||||
.setStyle(ButtonStyle.Danger)
|
|
||||||
.setDisabled(true),
|
|
||||||
]);
|
|
||||||
|
|
||||||
await interaction.update({
|
|
||||||
embeds: [ embed ],
|
|
||||||
components: [ row ],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
import {ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder, SlashCommandBuilder} from "discord.js";
|
import {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";
|
|
||||||
import EmbedColours from "../constants/EmbedColours";
|
|
||||||
|
|
||||||
export default class Effects extends Command {
|
export default class Effects extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -70,19 +68,16 @@ 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?")
|
||||||
.setColor(EmbedColours.Ok)
|
|
||||||
.addFields([
|
.addFields([
|
||||||
{
|
{
|
||||||
name: "Effect",
|
name: "Effect",
|
||||||
|
@ -91,26 +86,11 @@ export default class Effects extends Command {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
name: "Length",
|
name: "Length",
|
||||||
value: timeLengthInput.GetLengthShort(),
|
value: "",
|
||||||
inline: true,
|
inline: true,
|
||||||
},
|
},
|
||||||
]);
|
]);
|
||||||
|
|
||||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
await interaction.reply({ embeds: [ embed ] });
|
||||||
.addComponents([
|
|
||||||
new ButtonBuilder()
|
|
||||||
.setLabel("Confirm")
|
|
||||||
.setCustomId(`effects use confirm ${effectDetail.id}`)
|
|
||||||
.setStyle(ButtonStyle.Primary),
|
|
||||||
new ButtonBuilder()
|
|
||||||
.setLabel("Cancel")
|
|
||||||
.setCustomId(`effects use cancel ${effectDetail.id}`)
|
|
||||||
.setStyle(ButtonStyle.Danger),
|
|
||||||
]);
|
|
||||||
|
|
||||||
await interaction.reply({
|
|
||||||
embeds: [ embed ],
|
|
||||||
components: [ row ],
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,17 +120,5 @@ 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…
Add table
Reference in a new issue