Clean up code

This commit is contained in:
Ethan Lane 2023-12-19 15:55:56 +00:00
parent b9f6ea69b7
commit 366bf08d3e

View file

@ -25,31 +25,17 @@ export default class InventoryHelper {
const inventory = await Inventory.FetchAllByUserId(userid); const inventory = await Inventory.FetchAllByUserId(userid);
const allSeries: SeriesMetadata[] = []; const allSeriesClaimed = CoreClient.Cards
.sort((a, b) => a.id - b.id)
.filter(x => {
x.cards = x.cards.filter(y => inventory.find(z => z.CardNumber == y.id));
for (let item of inventory) { return x;
const series = CoreClient.Cards.find(x => x.cards.find(y => y.id == item.CardNumber)); });
if (!series || allSeries.includes(series)) {
continue;
}
allSeries.push(series);
}
const seriesToDisplay: SeriesMetadata[] = [];
for (let series of allSeries.sort((a, b) => a.id - b.id)) {
const seriesCards = series.cards.filter(x => inventory.find(y => y.CardNumber == x.id));
series.cards = seriesCards;
seriesToDisplay.push(series);
}
const pages: InventoryPage[] = []; const pages: InventoryPage[] = [];
for (let series of seriesToDisplay) { for (let series of allSeriesClaimed) {
const seriesCards = series.cards.sort((a, b) => b.type - a.type); const seriesCards = series.cards.sort((a, b) => b.type - a.type);
for (let i = 0; i < seriesCards.length; i+= cardsPerPage) { for (let i = 0; i < seriesCards.length; i+= cardsPerPage) {
@ -87,15 +73,9 @@ export default class InventoryHelper {
return Promise.reject("Unable to find page"); return Promise.reject("Unable to find page");
} }
const embedDescription: string[] = [];
for (let card of currentPage.cards) {
embedDescription.push(`[${card.id}] ${card.name} (${CardRarityToString(card.type)}) x${card.quantity}`);
}
const embed = new EmbedBuilder() const embed = new EmbedBuilder()
.setTitle(`${currentPage.name} (${currentPage.seriesSubpage + 1})`) .setTitle(`${currentPage.name} (${currentPage.seriesSubpage + 1})`)
.setDescription(embedDescription.join('\n')) .setDescription(currentPage.cards.map(x => `[${x.id}] ${x.name} (${CardRarityToString(x.type)}) x${x.quantity}`).join('\n'))
.setFooter({ text: `Page ${page} of ${pages.length}` }) .setFooter({ text: `Page ${page} of ${pages.length}` })
.setColor(EmbedColours.Ok); .setColor(EmbedColours.Ok);