Add list moons command (#449)
- Add concept of moons to the database - Add the list moons command to view a user's moons - This command is paginated using buttons #195 Reviewed-on: #449 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
8e87fd6618
commit
e2ec042fcd
10 changed files with 235 additions and 3 deletions
45
src/commands/304276391837302787/moons/list.ts
Normal file
45
src/commands/304276391837302787/moons/list.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import {ActionRowBuilder, ButtonBuilder, ButtonStyle, CommandInteraction, EmbedBuilder} from "discord.js";
|
||||
import Moon from "../../../database/entities/Moon";
|
||||
import EmbedColours from "../../../constants/EmbedColours";
|
||||
|
||||
export default async function ListMoons(interaction: CommandInteraction) {
|
||||
const user = interaction.options.get("user")?.user ?? interaction.user;
|
||||
const page = interaction.options.get("page")?.value as number ?? 0;
|
||||
|
||||
const pageLength = 10;
|
||||
|
||||
const moons = await Moon.FetchPaginatedMoonsByUserId(user.id, pageLength, page);
|
||||
|
||||
if (!moons || moons[0].length == 0) {
|
||||
await interaction.reply(`${user.username} does not have any moons or page is invalid.`);
|
||||
return;
|
||||
}
|
||||
|
||||
const totalPages = Math.ceil(moons[1] / pageLength);
|
||||
|
||||
const description = moons[0].flatMap(x => `${x.MoonNumber}. ${x.Description.slice(0, 15)}`);
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(`${user.username}'s Moons`)
|
||||
.setColor(EmbedColours.Ok)
|
||||
.setDescription(description.join("\n"))
|
||||
.setFooter({ text: `Page ${page + 1} of ${totalPages} · ${moons[1]} moons` });
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||
.addComponents(
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`moons list ${user.id} ${page - 1}`)
|
||||
.setLabel("Previous")
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setDisabled(page == 0),
|
||||
new ButtonBuilder()
|
||||
.setCustomId(`moons list ${user.id} ${page + 1}`)
|
||||
.setLabel("Next")
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setDisabled(page + 1 == totalPages));
|
||||
|
||||
await interaction.reply({
|
||||
embeds: [ embed ],
|
||||
components: [ row ],
|
||||
});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue