Update view command to use fuzzy search instead of direct card number (#340)
- Install `fuse.js` package to allow for fuzzy finding - Update the `/view` command to use fuzzy search by name instead of the card number - Add pagination for the command via the `View` button event #154 Reviewed-on: #340 Reviewed-by: VylpesTester <tester@vylpes.com> Co-authored-by: Ethan Lane <ethan@vylpes.com> Co-committed-by: Ethan Lane <ethan@vylpes.com>
This commit is contained in:
parent
8bd5f44524
commit
5defb682c1
7 changed files with 112 additions and 58 deletions
25
src/buttonEvents/View.ts
Normal file
25
src/buttonEvents/View.ts
Normal file
|
@ -0,0 +1,25 @@
|
|||
import {ButtonInteraction} from "discord.js";
|
||||
import {ButtonEvent} from "../type/buttonEvent.js";
|
||||
import CardSearchHelper from "../helpers/CardSearchHelper.js";
|
||||
|
||||
export default class View extends ButtonEvent {
|
||||
public override async execute(interaction: ButtonInteraction) {
|
||||
const page = interaction.customId.split(" ")[1];
|
||||
const query = interaction.customId.split(" ").splice(1).join(" ");
|
||||
|
||||
await interaction.deferUpdate();
|
||||
|
||||
const searchResult = await CardSearchHelper.GenerateSearchPage(query, interaction.user.id, Number(page));
|
||||
|
||||
if (!searchResult) {
|
||||
await interaction.followUp("No results found");
|
||||
return;
|
||||
}
|
||||
|
||||
await interaction.editReply({
|
||||
embeds: [ searchResult.embed ],
|
||||
components: [ searchResult.row ],
|
||||
files: [ searchResult.attachment ],
|
||||
});
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue