Create simple inventory list #120

Merged
Vylpes merged 10 commits from feature/97-simple-inventory-list into develop 2023-12-22 14:41:14 +00:00
3 changed files with 28 additions and 14 deletions
Showing only changes of commit cb57b24521 - Show all commits

View file

@ -7,11 +7,15 @@ export default class Inventory extends ButtonEvent {
const userid = interaction.customId.split(' ')[1]; const userid = interaction.customId.split(' ')[1];
const page = interaction.customId.split(' ')[2]; const page = interaction.customId.split(' ')[2];
const embed = await InventoryHelper.GenerateInventoryPage(interaction.user.username, userid, Number(page)); try {
const embed = await InventoryHelper.GenerateInventoryPage(interaction.user.username, userid, Number(page));
await interaction.reply({ await interaction.update({
embeds: [ embed.embed ], embeds: [ embed.embed ],
components: [ embed.row ], components: [ embed.row ],
}); });
} catch {
await interaction.reply("No page for user found.");
}
} }
} }

View file

@ -18,11 +18,21 @@ export default class Inventory extends Command {
public override async execute(interaction: CommandInteraction) { public override async execute(interaction: CommandInteraction) {
const page = interaction.options.get('page'); const page = interaction.options.get('page');
const embed = await InventoryHelper.GenerateInventoryPage(interaction.user.username, interaction.user.id, page ? Number(page.value) : 0); try {
let pageNumber = 0;
await interaction.reply({ if (page && page.value) {
embeds: [ embed.embed ], pageNumber = Number(page.value) - 1;
components: [ embed.row ], }
});
const embed = await InventoryHelper.GenerateInventoryPage(interaction.user.username, interaction.user.id, pageNumber);
await interaction.reply({
embeds: [ embed.embed ],
components: [ embed.row ],
});
} catch {
await interaction.reply("No page for user found.");
}
} }
} }

View file

@ -21,7 +21,7 @@ interface InventoryPageCards {
export default class InventoryHelper { export default class InventoryHelper {
public static async GenerateInventoryPage(username: string, userid: string, page: number): Promise<{ embed: EmbedBuilder, row: ActionRowBuilder<ButtonBuilder> }> { public static async GenerateInventoryPage(username: string, userid: string, page: number): Promise<{ embed: EmbedBuilder, row: ActionRowBuilder<ButtonBuilder> }> {
const cardsPerPage = 9; const cardsPerPage = 15;
const inventory = await Inventory.FetchAllByUserId(userid); const inventory = await Inventory.FetchAllByUserId(userid);
@ -77,8 +77,8 @@ export default class InventoryHelper {
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setTitle(username) .setTitle(username)
.setDescription(currentPage.cards.map(x => `[${x.id}] ${x.name} (${CardRarityToString(x.type)}) x${x.quantity}`).join('\n')) .setDescription(`**${currentPage.name} (${currentPage.seriesSubpage + 1})**\n${currentPage.cards.map(x => `[${x.id}] ${x.name} (${CardRarityToString(x.type)}) x${x.quantity}`).join('\n')}`)
.setFooter({ text: `${currentPage.name} (${currentPage.seriesSubpage + 1}) · Page ${page} of ${pages.length}` }) .setFooter({ text: `Page ${page + 1} of ${pages.length}` })
.setColor(EmbedColours.Ok); .setColor(EmbedColours.Ok);
const row = new ActionRowBuilder<ButtonBuilder>() const row = new ActionRowBuilder<ButtonBuilder>()
@ -92,7 +92,7 @@ export default class InventoryHelper {
.setCustomId(`inventory ${userid} ${page + 1}`) .setCustomId(`inventory ${userid} ${page + 1}`)
.setLabel("Next") .setLabel("Next")
.setStyle(ButtonStyle.Primary) .setStyle(ButtonStyle.Primary)
.setDisabled(page == pages.length)); .setDisabled(page + 1 == pages.length));
return { embed, row }; return { embed, row };
} }