From 3873983b32e54af1d46846df99b9fca047494eb0 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Thu, 28 Nov 2024 18:56:26 +0000 Subject: [PATCH 1/2] Create effects list subcommand --- src/commands/effects.ts | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/src/commands/effects.ts b/src/commands/effects.ts index df8a515..aa58d3b 100644 --- a/src/commands/effects.ts +++ b/src/commands/effects.ts @@ -1,5 +1,6 @@ import {CommandInteraction, SlashCommandBuilder} from "discord.js"; import {Command} from "../type/command"; +import EffectHelper from "../helpers/EffectHelper"; export default class Effects extends Command { constructor() { @@ -10,7 +11,11 @@ export default class Effects extends Command { .setDescription("Effects") .addSubcommand(x => x .setName("list") - .setDescription("List all effects I have")); + .setDescription("List all effects I have") + .addNumberOption(x => x + .setName("page") + .setDescription("The page number") + .setMinValue(1))); } public override async execute(interaction: CommandInteraction) { @@ -26,5 +31,15 @@ export default class Effects extends Command { } private async List(interaction: CommandInteraction) { + const pageOption = interaction.options.get("page"); + + const page = pageOption && Number(pageOption.value) ? Number(pageOption.value) : 1; + + const result = await EffectHelper.GenerateEffectEmbed(interaction.user.id, page); + + await interaction.reply({ + embeds: [ result.embed ], + components: [ result.row ], + }); } } From 7944b3aeac223ae8c0468fc151c5b11cfd51e336 Mon Sep 17 00:00:00 2001 From: Ethan Lane Date: Thu, 28 Nov 2024 19:01:34 +0000 Subject: [PATCH 2/2] Create paginated button event --- src/buttonEvents/Effects.ts | 33 +++++++++++++++++++++++++++++++++ src/registry.ts | 2 ++ 2 files changed, 35 insertions(+) create mode 100644 src/buttonEvents/Effects.ts diff --git a/src/buttonEvents/Effects.ts b/src/buttonEvents/Effects.ts new file mode 100644 index 0000000..0810c94 --- /dev/null +++ b/src/buttonEvents/Effects.ts @@ -0,0 +1,33 @@ +import {ButtonInteraction} from "discord.js"; +import {ButtonEvent} from "../type/buttonEvent"; +import EffectHelper from "../helpers/EffectHelper"; + +export default class Effects extends ButtonEvent { + public override async execute(interaction: ButtonInteraction) { + const action = interaction.customId.split(" ")[1]; + + switch (action) { + case "list": + await this.List(interaction); + break; + } + } + + private async List(interaction: ButtonInteraction) { + const pageOption = interaction.customId.split(" ")[2]; + + const page = Number(pageOption); + + if (!page) { + await interaction.reply("Page option is not a valid number"); + return; + } + + const result = await EffectHelper.GenerateEffectEmbed(interaction.user.id, page); + + await interaction.update({ + embeds: [ result.embed ], + components: [ result.row ], + }); + } +} diff --git a/src/registry.ts b/src/registry.ts index 3be1fb8..3ae885d 100644 --- a/src/registry.ts +++ b/src/registry.ts @@ -26,6 +26,7 @@ import Droprarity from "./commands/stage/droprarity"; // Button Event Imports import Claim from "./buttonEvents/Claim"; +import EffectsButtonEvent from "./buttonEvents/Effects"; import InventoryButtonEvent from "./buttonEvents/Inventory"; import MultidropButtonEvent from "./buttonEvents/Multidrop"; import Reroll from "./buttonEvents/Reroll"; @@ -65,6 +66,7 @@ export default class Registry { public static RegisterButtonEvents() { CoreClient.RegisterButtonEvent("claim", new Claim()); + CoreClient.RegisterButtonEvent("effects", new EffectsButtonEvent()); CoreClient.RegisterButtonEvent("inventory", new InventoryButtonEvent()); CoreClient.RegisterButtonEvent("multidrop", new MultidropButtonEvent()); CoreClient.RegisterButtonEvent("reroll", new Reroll());