diff options
| author | Cory J Reid <[email protected]> | 2023-07-19 21:28:02 -0600 |
|---|---|---|
| committer | GitHub <[email protected]> | 2023-07-19 22:28:02 -0500 |
| commit | 9c6d2a7acf350ce563d3b4201cd9f18587e222da (patch) | |
| tree | a9c20dfe6843d0823825d4f71ae9c99fb9290eab /src | |
| parent | 2eb2b6d045386d3e0558fbf10b7157b03c7d5f02 (diff) | |
| download | muse-9c6d2a7acf350ce563d3b4201cd9f18587e222da.tar.xz muse-9c6d2a7acf350ce563d3b4201cd9f18587e222da.zip | |
Add pagination to the output of the `favorites list` command (#954)
Co-authored-by: Max Isom <[email protected]>
Diffstat (limited to 'src')
| -rw-r--r-- | src/commands/favorites.ts | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/commands/favorites.ts b/src/commands/favorites.ts index 3cfd716..303dc22 100644 --- a/src/commands/favorites.ts +++ b/src/commands/favorites.ts @@ -1,10 +1,11 @@ import {SlashCommandBuilder} from '@discordjs/builders'; -import {AutocompleteInteraction, ChatInputCommandInteraction, EmbedBuilder} from 'discord.js'; +import {APIEmbedField, AutocompleteInteraction, ChatInputCommandInteraction} from 'discord.js'; import {inject, injectable} from 'inversify'; import Command from '.'; import AddQueryToQueue from '../services/add-query-to-queue.js'; import {TYPES} from '../types.js'; import {prisma} from '../utils/db.js'; +import {Pagination} from 'pagination.djs'; @injectable() export default class implements Command { @@ -54,7 +55,8 @@ export default class implements Command { ), ); - constructor(@inject(TYPES.Services.AddQueryToQueue) private readonly addQueryToQueue: AddQueryToQueue) {} + constructor(@inject(TYPES.Services.AddQueryToQueue) private readonly addQueryToQueue: AddQueryToQueue) { + } requiresVC = (interaction: ChatInputCommandInteraction) => interaction.options.getSubcommand() === 'use'; @@ -135,18 +137,22 @@ export default class implements Command { return; } - const embed = new EmbedBuilder().setTitle('Favorites'); - - let description = ''; - for (const favorite of favorites) { - description += `**${favorite.name}**: ${favorite.query} (<@${favorite.authorId}>)\n`; + const fields = new Array<APIEmbedField>(favorites.length); + for (let index = 0; index < favorites.length; index++) { + const favorite = favorites[index]; + fields[index] = { + inline: false, + name: favorite.name, + value: `${favorite.query} (<@${favorite.authorId}>)`, + }; } - embed.setDescription(description); - - await interaction.reply({ - embeds: [embed], - }); + await new Pagination( + interaction as ChatInputCommandInteraction<'cached'>, + {ephemeral: true, limit: 25}) + .setFields(fields) + .paginateFields(true) + .render(); } private async create(interaction: ChatInputCommandInteraction) { |
