Create simple inventory list #120
3 changed files with 28 additions and 14 deletions
|
@ -7,11 +7,15 @@ export default class Inventory extends ButtonEvent {
|
|||
const userid = interaction.customId.split(' ')[1];
|
||||
const page = interaction.customId.split(' ')[2];
|
||||
|
||||
try {
|
||||
const embed = await InventoryHelper.GenerateInventoryPage(interaction.user.username, userid, Number(page));
|
||||
|
||||
await interaction.reply({
|
||||
await interaction.update({
|
||||
embeds: [ embed.embed ],
|
||||
components: [ embed.row ],
|
||||
});
|
||||
} catch {
|
||||
await interaction.reply("No page for user found.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -18,11 +18,21 @@ export default class Inventory extends Command {
|
|||
public override async execute(interaction: CommandInteraction) {
|
||||
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;
|
||||
|
||||
if (page && page.value) {
|
||||
pageNumber = Number(page.value) - 1;
|
||||
}
|
||||
|
||||
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.");
|
||||
}
|
||||
}
|
||||
}
|
|
@ -21,7 +21,7 @@ interface InventoryPageCards {
|
|||
|
||||
export default class InventoryHelper {
|
||||
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);
|
||||
|
||||
|
@ -77,8 +77,8 @@ export default class InventoryHelper {
|
|||
|
||||
const embed = new EmbedBuilder()
|
||||
.setTitle(username)
|
||||
.setDescription(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}` })
|
||||
.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: `Page ${page + 1} of ${pages.length}` })
|
||||
.setColor(EmbedColours.Ok);
|
||||
|
||||
const row = new ActionRowBuilder<ButtonBuilder>()
|
||||
|
@ -92,7 +92,7 @@ export default class InventoryHelper {
|
|||
.setCustomId(`inventory ${userid} ${page + 1}`)
|
||||
.setLabel("Next")
|
||||
.setStyle(ButtonStyle.Primary)
|
||||
.setDisabled(page == pages.length));
|
||||
.setDisabled(page + 1 == pages.length));
|
||||
|
||||
return { embed, row };
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue