Create effect use command
Some checks failed
Test / build (push) Failing after 29s

This commit is contained in:
Ethan Lane 2024-12-13 18:26:02 +00:00
parent ed52f3e3dc
commit f8b013a091
2 changed files with 72 additions and 2 deletions

View file

@ -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: `<t:${whenExpires.getMilliseconds()}:f>`,
inline: true,
},
]);
await interaction.reply({ embeds: [ embed ] });
return;
}
await interaction.reply("Unable to use effect! Please make sure you have it in your inventory");
}
}

View file

@ -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<string, EffectDetail>([
[ "unclaimed", new EffectDetail("unclaimed", "Unclaimed Chance Up", 24 * 60 * 60 * 1000, 100) ],
]);