This commit is contained in:
parent
ed52f3e3dc
commit
f8b013a091
2 changed files with 72 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
||||||
import {CommandInteraction, 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";
|
||||||
|
|
||||||
export default class Effects extends Command {
|
export default class Effects extends Command {
|
||||||
constructor() {
|
constructor() {
|
||||||
|
@ -15,7 +16,17 @@ export default class Effects extends Command {
|
||||||
.addNumberOption(x => x
|
.addNumberOption(x => x
|
||||||
.setName("page")
|
.setName("page")
|
||||||
.setDescription("The page number")
|
.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) {
|
public override async execute(interaction: CommandInteraction) {
|
||||||
|
@ -27,6 +38,9 @@ export default class Effects extends Command {
|
||||||
case "list":
|
case "list":
|
||||||
await this.List(interaction);
|
await this.List(interaction);
|
||||||
break;
|
break;
|
||||||
|
case "use":
|
||||||
|
await this.Use(interaction);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -42,4 +56,43 @@ export default class Effects extends Command {
|
||||||
components: [ result.row ],
|
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");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
17
src/constants/EffectDetails.ts
Normal file
17
src/constants/EffectDetails.ts
Normal 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) ],
|
||||||
|
]);
|
Loading…
Reference in a new issue