Update inventory command so it errors gracefully if no page is found for the user #286
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));
|
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({
|
await interaction.followUp({
|
||||||
files: [ embed.image ],
|
files: [ embed.image ],
|
||||||
embeds: [ embed.embed ],
|
embeds: [ embed.embed ],
|
||||||
|
@ -34,7 +39,7 @@ export default class Inventory extends ButtonEvent {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
AppLogger.LogError("Button/Inventory", `Error generating inventory page for ${member.user.username} with id ${member.user.id}: ${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);
|
const embed = await InventoryHelper.GenerateInventoryPage(user.username, user.id, pageNumber);
|
||||||
|
|
||||||
|
if (!embed) {
|
||||||
|
await interaction.followUp("No page for user found.");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
await interaction.followUp({
|
await interaction.followUp({
|
||||||
files: [ embed.image ],
|
files: [ embed.image ],
|
||||||
embeds: [ embed.embed ],
|
embeds: [ embed.embed ],
|
||||||
|
@ -47,7 +52,7 @@ export default class Inventory extends Command {
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
AppLogger.LogError("Commands/Inventory", e as string);
|
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 {
|
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}`);
|
AppLogger.LogSilly("Helpers/InventoryHelper", `Parameters: username=${username}, userid=${userid}, page=${page}`);
|
||||||
|
|
||||||
const cardsPerPage = 9;
|
const cardsPerPage = 9;
|
||||||
|
|
||||||
const inventory = await Inventory.FetchAllByUserId(userid);
|
const inventory = await Inventory.FetchAllByUserId(userid);
|
||||||
|
|
||||||
|
if (!inventory || inventory.length == 0) return undefined;
|
||||||
|
|
||||||
const clientCards = cloneDeep(CoreClient.Cards);
|
const clientCards = cloneDeep(CoreClient.Cards);
|
||||||
|
|
||||||
const allSeriesClaimed = clientCards
|
const allSeriesClaimed = clientCards
|
||||||
|
@ -88,8 +90,7 @@ export default class InventoryHelper {
|
||||||
const currentPage = pages[page];
|
const currentPage = pages[page];
|
||||||
|
|
||||||
if (!currentPage) {
|
if (!currentPage) {
|
||||||
AppLogger.LogError("Helpers/InventoryHelper", "Unable to find page");
|
return undefined;
|
||||||
return Promise.reject("Unable to find page");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
|
|
Loading…
Reference in a new issue