From f8b013a091f4f5df2aa699c774cd637cbb81d979 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Fri, 13 Dec 2024 18:26:02 +0000 Subject: [PATCH] Create effect use command --- src/commands/effects.ts | 57 ++++++++++++++++++++++++++++++++-- src/constants/EffectDetails.ts | 17 ++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) create mode 100644 src/constants/EffectDetails.ts diff --git a/src/commands/effects.ts b/src/commands/effects.ts index bcaa929..db19b5e 100644 --- a/src/commands/effects.ts +++ b/src/commands/effects.ts @@ -1,6 +1,7 @@ -import {CommandInteraction, SlashCommandBuilder} from "discord.js"; +import {CommandInteraction, EmbedBuilder, SlashCommandBuilder} from "discord.js"; import {Command} from "../type/command"; import EffectHelper from "../helpers/EffectHelper"; +import {EffectDetails} from "../constants/EffectDetails"; export default class Effects extends Command { constructor() { @@ -15,7 +16,17 @@ export default class Effects extends Command { .addNumberOption(x => x .setName("page") .setDescription("The page number") - .setMinValue(1))); + .setMinValue(1))) + .addSubcommand(x => x + .setName("use") + .setDescription("Use an effect in your inventory") + .addStringOption(y => y + .setName("id") + .setDescription("The effect id to use") + .setRequired(true) + .setChoices([ + { name: "Unclaimed Chance Up", value: "unclaimed" }, + ]))); } public override async execute(interaction: CommandInteraction) { @@ -27,6 +38,9 @@ export default class Effects extends Command { case "list": await this.List(interaction); break; + case "use": + await this.Use(interaction); + break; } } @@ -42,4 +56,43 @@ export default class Effects extends Command { components: [ result.row ], }); } + + private async Use(interaction: CommandInteraction) { + const id = interaction.options.get("id", true).value!.toString(); + + const effectDetail = EffectDetails.get(id); + + if (!effectDetail) { + await interaction.reply("Unable to find effect!"); + return; + } + + const now = new Date(); + const whenExpires = new Date(now.getMilliseconds() + effectDetail.duration); + + const result = await EffectHelper.UseEffect(interaction.user.id, id, whenExpires); + + if (result) { + const embed = new EmbedBuilder() + .setTitle("Effect Used") + .setDescription("You now have an active effect!") + .addFields([ + { + name: "Effect", + value: effectDetail.friendlyName, + inline: true, + }, + { + name: "Expires", + value: ``, + inline: true, + }, + ]); + + await interaction.reply({ embeds: [ embed ] }); + return; + } + + await interaction.reply("Unable to use effect! Please make sure you have it in your inventory"); + } } diff --git a/src/constants/EffectDetails.ts b/src/constants/EffectDetails.ts new file mode 100644 index 0000000..c59d33d --- /dev/null +++ b/src/constants/EffectDetails.ts @@ -0,0 +1,17 @@ +class EffectDetail { + public readonly id: string; + public readonly friendlyName: string; + public readonly duration: number; + public readonly cost: number; + + constructor(id: string, friendlyName: string, duration: number, cost: number) { + this.id = id; + this.friendlyName = friendlyName; + this.duration = duration; + this.cost = cost; + } +}; + +export const EffectDetails = new Map([ + [ "unclaimed", new EffectDetail("unclaimed", "Unclaimed Chance Up", 24 * 60 * 60 * 1000, 100) ], +]);