aboutsummaryrefslogtreecommitdiff
path: root/src/commands/utilities
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/utilities')
-rw-r--r--src/commands/utilities/price.ts79
1 files changed, 44 insertions, 35 deletions
diff --git a/src/commands/utilities/price.ts b/src/commands/utilities/price.ts
index c44b47e..3973844 100644
--- a/src/commands/utilities/price.ts
+++ b/src/commands/utilities/price.ts
@@ -9,6 +9,12 @@ assert(got);
export default class PriceCommand extends BushCommand {
public static cachedItemList: string[] = [];
+ public static readonly urls = [
+ { url: 'https://api.hypixel.net/skyblock/bazaar', error: 'bazaar' },
+ { url: 'https://moulberry.codes/lowestbin.json', error: 'current lowest BIN' },
+ { url: 'https://moulberry.codes/auction_averages_lbin/3day.json', error: 'average Lowest BIN' },
+ { url: 'https://moulberry.codes/auction_averages/3day.json', error: 'auction average' }
+ ] as const;
public constructor() {
super('price', {
@@ -49,13 +55,14 @@ export default class PriceCommand extends BushCommand {
if (message.util.isSlashMessage(message)) await message.interaction.deferReply();
const errors: string[] = [];
- //prettier-ignore
- const [bazaar, currentLowestBIN, averageLowestBIN, auctionAverages] = (await Promise.all([
- got.get('https://api.hypixel.net/skyblock/bazaar').json().catch(() => { errors.push('bazaar') }),
- got.get('https://moulberry.codes/lowestbin.json').json().catch(() => { errors.push('current lowest BIN') }),
- got.get('https://moulberry.codes/auction_averages_lbin/3day.json').json().catch(() => { errors.push('average Lowest BIN') }),
- got.get('https://moulberry.codes/auction_averages/3day.json').json().catch(() => { errors.push('auction average') })
- ])) as [Bazaar | undefined, LowestBIN | undefined, LowestBIN | undefined, AuctionAverages | undefined];
+ const [bazaar, currentLowestBIN, averageLowestBIN, auctionAverages] = (await Promise.all(
+ PriceCommand.urls.map(({ url, error }) =>
+ got
+ .get(url)
+ .json()
+ .catch(() => (errors.push(error), undefined))
+ )
+ )) as [Bazaar?, LowestBIN?, LowestBIN?, AuctionAverages?];
let parsedItem = args.item.toString().toUpperCase().replace(/ /g, '_').replace(/'S/g, '');
const priceEmbed = new EmbedBuilder().setColor(errors?.length ? colors.warn : colors.success).setTimestamp();
@@ -126,11 +133,7 @@ export default class PriceCommand extends BushCommand {
return await message.util.reply({ embeds: [priceEmbed] });
- function addBazaarInformation(
- Information: keyof Bazaar['products'][string]['quick_status'],
- digits: number,
- commas: boolean
- ): string {
+ function addBazaarInformation(Information: keyof BazarProductQuickStatus, digits: number, commas: boolean): string {
const price = bazaar?.products?.[parsedItem]?.quick_status?.[Information];
return commas
? Number(price)?.toLocaleString(undefined, { minimumFractionDigits: digits, maximumFractionDigits: digits })
@@ -158,41 +161,47 @@ export default class PriceCommand extends BushCommand {
}
}
-export interface Summary {
- amount: number;
- pricePerUnit: number;
- orders: number;
-}
+export type ItemID = string;
export interface Bazaar {
success: boolean;
lastUpdated: number;
products: {
- [key: string]: {
- product_id: string;
- sell_summary: Summary[];
- buy_summary: Summary[];
- quick_status: {
- productId: string;
- sellPrice: number;
- sellVolume: number;
- sellMovingWeek: number;
- sellOrders: number;
- buyPrice: number;
- buyVolume: number;
- buyMovingWeek: number;
- buyOrders: number;
- };
- };
+ [key: ItemID]: BazarProduct;
};
}
+export interface BazarProduct {
+ product_id: string;
+ sell_summary: BazarSummary[];
+ buy_summary: BazarSummary[];
+ quick_status: BazarProductQuickStatus;
+}
+
+export interface BazarSummary {
+ amount: number;
+ pricePerUnit: number;
+ orders: number;
+}
+
+export interface BazarProductQuickStatus {
+ productId: ItemID;
+ sellPrice: number;
+ sellVolume: number;
+ sellMovingWeek: number;
+ sellOrders: number;
+ buyPrice: number;
+ buyVolume: number;
+ buyMovingWeek: number;
+ buyOrders: number;
+}
+
export interface LowestBIN {
- [key: string]: number;
+ [key: ItemID]: number;
}
export interface AuctionAverages {
- [key: string]: {
+ [key: ItemID]: {
price?: number;
count?: number;
sales?: number;