card-drop/src/commands/view.ts
Ethan Lane 66243e6742
All checks were successful
Deploy To Stage / build (push) Successful in 15s
Deploy To Stage / deploy (push) Successful in 16s
Fix fuzzy /view to be consistent with its pages (#345)
- Fix the `/view` command to have a set amount of cards in its page rotation
- This is done now by updating it so instead of requerying each page turn it instead queries once at the start and passes the top 5 results to the button event

#154

Reviewed-on: #345
Reviewed-by: VylpesTester <tester@vylpes.com>
Co-authored-by: Ethan Lane <ethan@vylpes.com>
Co-committed-by: Ethan Lane <ethan@vylpes.com>
2024-08-24 17:26:26 +01:00

40 lines
1.3 KiB
TypeScript

import { CommandInteraction, SlashCommandBuilder } from "discord.js";
import { Command } from "../type/command";
import AppLogger from "../client/appLogger";
import CardSearchHelper from "../helpers/CardSearchHelper";
export default class View extends Command {
constructor() {
super();
this.CommandBuilder = new SlashCommandBuilder()
.setName("view")
.setDescription("Search for a card by its name")
.addStringOption(x =>
x
.setName("name")
.setDescription("The card name to search for")
.setRequired(true));
}
public override async execute(interaction: CommandInteraction) {
const name = interaction.options.get("name", true);
AppLogger.LogSilly("Commands/View", `Parameters: name=${name.value}`);
await interaction.deferReply();
const searchResult = await CardSearchHelper.GenerateSearchQuery(name.value!.toString(), interaction.user.id, 7);
if (!searchResult) {
await interaction.editReply("No results found");
return;
}
await interaction.editReply({
embeds: [ searchResult.embed ],
components: [ searchResult.row ],
files: [ searchResult.attachment ],
});
}
}