Add list moons command #449

Merged
Vylpes merged 15 commits from feature/195-list-moons into develop 2024-08-17 16:47:14 +01:00
2 changed files with 10 additions and 4 deletions
Showing only changes of commit 6f4ff1df06 - Show all commits

View file

@ -12,7 +12,11 @@ export default class Moons extends Command {
.addSubcommand(subcommand =>
subcommand
.setName('list')
.setDescription('List moons you have obtained'));
.setDescription('List moons you have obtained')
.addUserOption(option =>
option
.setName("user")
.setDescription("The user to view (Defaults to yourself)")));
}
public override async execute(interaction: CommandInteraction) {

View file

@ -3,17 +3,19 @@ import Moon from "../../../database/entities/Moon";
import EmbedColours from "../../../constants/EmbedColours";
export default async function ListMoons(interaction: CommandInteraction) {
const moons = await Moon.FetchMoonsByUserId(interaction.user.id);
const user = interaction.options.get("user")?.user ?? interaction.user;
const moons = await Moon.FetchMoonsByUserId(user.id);
if (!moons || moons.length == 0) {
await interaction.reply("You do not have any moons.");
await interaction.reply(`${user.username} does not have any moons.`);
return;
}
const description = moons.flatMap(x => `${x.MoonNumber}. ${x.Description.slice(0, 15)}`);
const embed = new EmbedBuilder()
.setTitle(`${interaction.user.username}'s Moons`)
.setTitle(`${user.username}'s Moons`)
.setColor(EmbedColours.Ok)
.setDescription(description.join("\n"))
.setFooter({ text: `${moons.length} moons` });