Create use effect command (#419)
All checks were successful
Deploy To Stage / build (push) Successful in 48s
Deploy To Stage / deploy (push) Successful in 17s

# Description

Please include a summary of the change and which issue is fixed. Please also include relevant motivation and context. List any dependencies that are required for this change.

#380

## Type of change

Please delete options that are not relevant.

- [ ] Bug fix (non-breaking change which fixes an issue)
- [ ] New feature (non-breaking change which adds functionality)
- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
- [ ] This change requires a documentation update

# How Has This Been Tested?

Please describe the tests that you ran to verify the changes. Provide instructions so we can reproduce. Please also list any relevant details to your test configuration.

# Checklist

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my own code
- [ ] I have commented my code, particularly in hard-to-understand areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that provde my fix is effective or that my feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream modules

Reviewed-on: #419
Reviewed-by: VylpesTester <tester@vylpes.com>
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
Ethan Lane 2025-01-25 17:29:01 +00:00 committed by Vylpes
parent 3e81f8ce1d
commit a3248e978a
42 changed files with 1241 additions and 1133 deletions

View file

@ -0,0 +1,132 @@
import { ActionRowBuilder, ButtonBuilder, ButtonInteraction, ButtonStyle, EmbedBuilder } from "discord.js";
import { EffectDetails } from "../../constants/EffectDetails";
import EffectHelper from "../../helpers/EffectHelper";
import EmbedColours from "../../constants/EmbedColours";
import TimeLengthInput from "../../helpers/TimeLengthInput";
import AppLogger from "../../client/appLogger";
export default class Use {
public static async Execute(interaction: ButtonInteraction) {
const subaction = interaction.customId.split(" ")[2];
switch (subaction) {
case "confirm":
await this.UseConfirm(interaction);
break;
case "cancel":
await this.UseCancel(interaction);
break;
}
}
private static async UseConfirm(interaction: ButtonInteraction) {
const id = interaction.customId.split(" ")[3];
const effectDetail = EffectDetails.get(id);
if (!effectDetail) {
AppLogger.LogError("Button/Effects/Use", `Effect not found, ${id}`);
await interaction.reply("Effect not found in system!");
return;
}
const now = new Date();
const whenExpires = new Date(now.getTime() + effectDetail.duration);
const result = await EffectHelper.UseEffect(interaction.user.id, id, whenExpires);
if (!result) {
await interaction.reply("Unable to use effect! Please make sure you have it in your inventory and is not on cooldown");
return;
}
const embed = new EmbedBuilder()
.setTitle("Effect Used")
.setDescription("You now have an active effect!")
.setColor(EmbedColours.Green)
.addFields([
{
name: "Effect",
value: effectDetail.friendlyName,
inline: true,
},
{
name: "Expires",
value: `<t:${Math.round(whenExpires.getTime() / 1000)}:f>`,
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 ],
});
}
private static async UseCancel(interaction: ButtonInteraction) {
const id = interaction.customId.split(" ")[3];
const effectDetail = EffectDetails.get(id);
if (!effectDetail) {
AppLogger.LogError("Button/Effects/Cancel", `Effect not found, ${id}`);
await interaction.reply("Effect not found in system!");
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 ],
});
}
}