Update inventory command so it errors gracefully if no page is found for the user
All checks were successful
Test / build (push) Successful in 9s
All checks were successful
Test / build (push) Successful in 9s
This commit is contained in:
parent
edf6c99bad
commit
51a5d20ce1
3 changed files with 16 additions and 5 deletions
|
@ -26,6 +26,11 @@ export default class Inventory extends ButtonEvent {
|
|||
|
||||
const embed = await InventoryHelper.GenerateInventoryPage(member.user.username, member.user.id, Number(page));
|
||||
|
||||
if (!embed) {
|
||||
await interaction.followUp("No page for user found.");
|
||||
return;
|
||||
}
|
||||
|
||||
await interaction.followUp({
|
||||
files: [ embed.image ],
|
||||
embeds: [ embed.embed ],
|
||||
|
@ -34,7 +39,7 @@ export default class Inventory extends ButtonEvent {
|
|||
} catch (e) {
|
||||
AppLogger.LogError("Button/Inventory", `Error generating inventory page for ${member.user.username} with id ${member.user.id}: ${e}`);
|
||||
|
||||
await interaction.reply("No page for user found.");
|
||||
await interaction.followUp("An error has occurred running this command.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,6 +39,11 @@ export default class Inventory extends Command {
|
|||
|
||||
const embed = await InventoryHelper.GenerateInventoryPage(user.username, user.id, pageNumber);
|
||||
|
||||
if (!embed) {
|
||||
await interaction.followUp("No page for user found.");
|
||||
return;
|
||||
}
|
||||
|
||||
await interaction.followUp({
|
||||
files: [ embed.image ],
|
||||
embeds: [ embed.embed ],
|
||||
|
@ -47,7 +52,7 @@ export default class Inventory extends Command {
|
|||
} catch (e) {
|
||||
AppLogger.LogError("Commands/Inventory", e as string);
|
||||
|
||||
await interaction.followUp("No page for user found.");
|
||||
await interaction.followUp("An error has occurred running this command.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,13 +31,15 @@ interface ReturnedInventoryPage {
|
|||
|
||||
|
||||
export default class InventoryHelper {
|
||||
public static async GenerateInventoryPage(username: string, userid: string, page: number): Promise<ReturnedInventoryPage> {
|
||||
public static async GenerateInventoryPage(username: string, userid: string, page: number): Promise<ReturnedInventoryPage | undefined> {
|
||||
AppLogger.LogSilly("Helpers/InventoryHelper", `Parameters: username=${username}, userid=${userid}, page=${page}`);
|
||||
|
||||
const cardsPerPage = 9;
|
||||
|
||||
const inventory = await Inventory.FetchAllByUserId(userid);
|
||||
|
||||
if (!inventory || inventory.length == 0) return undefined;
|
||||
|
||||
const clientCards = cloneDeep(CoreClient.Cards);
|
||||
|
||||
const allSeriesClaimed = clientCards
|
||||
|
@ -88,8 +90,7 @@ export default class InventoryHelper {
|
|||
const currentPage = pages[page];
|
||||
|
||||
if (!currentPage) {
|
||||
AppLogger.LogError("Helpers/InventoryHelper", "Unable to find page");
|
||||
return Promise.reject("Unable to find page");
|
||||
return undefined;
|
||||
}
|
||||
|
||||
const embed = new EmbedBuilder()
|
||||
|
|
Loading…
Reference in a new issue