moved to types

This commit is contained in:
Ulysia 2024-12-28 14:05:03 +01:00
parent 1dc528fd30
commit 13035edc40
5 changed files with 41 additions and 20 deletions

View file

@ -1,7 +1,7 @@
import axios from 'axios';
import { getParsed, getProfit, splitNumber, getRawCraft } from './src/helperFunctions';
import { parentPort, workerData, isMainThread } from 'worker_threads';
import { Item } from './src/Item';
import { Item } from './src/Types';
import { AuctionResponse, Auction, Bid } from './src/auctionType';
import { loadConfig } from './src/configLoader';

View file

@ -4,30 +4,20 @@ import { Worker } from 'worker_threads';
import { asyncInterval, addNotation } from './src/helperFunctions';
import { string } from 'prismarine-nbt';
import { SqlSystem } from './src/sqlFunctions';
import { setupErrorHandlers } from './src/errorHandler';
import { ItemCompactData } from './src/Types';
setupErrorHandlers();
import { loadConfig } from './src/configLoader';
const config = loadConfig();
class ItemData {
public sales: number;
public lbin: number;
public cleanPrice: number;
public price: number;
constructor(sales: number = 0, lbin: number = 0, cleanPrice: number = 0, price: number = 0) {
this.sales = sales;
this.lbin = lbin;
this.cleanPrice = cleanPrice;
this.price = price;
}
}
let worker_count = config.data.worker_count ?? 1;
let lastUpdated = 0;
let doneWorkers = 0;
let startingTime: number;
let maxPrice = 0;
let itemDatas: Record<string, ItemData> = {};
let itemDatas: Record<string, ItemCompactData> = {};
const workers: Worker[] = [];
const webhookRegex = /https:\/\/discord.com\/api\/webhooks\/(.+)\/(.+)/;
@ -160,7 +150,7 @@ async function getLBINs(): Promise<void> {
const lbins = await axios.get('https://moulberry.codes/lowestbin.json');
const lbinData = lbins.data;
for (const item of Object.keys(lbinData)) {
if (!itemDatas[item]) itemDatas[item] = new ItemData();
if (!itemDatas[item]) itemDatas[item] = new ItemCompactData();
itemDatas[item].lbin = lbinData[item];
}
}
@ -177,7 +167,7 @@ async function getMoulberry(): Promise<void> {
const cleanPriceData = cleanPriceAvgs.data;
for (const item of Object.keys(avgData)) {
if (!itemDatas[item]) itemDatas[item] = new ItemData();
if (!itemDatas[item]) itemDatas[item] = new ItemCompactData();
const itemInfo = avgData[item];
itemDatas[item].sales = itemInfo.sales !== undefined ? itemInfo.sales : 0;

View file

@ -1,5 +1,6 @@
// item.ts
//#region ItemData Interface
export interface ItemData {
name: string;
id: string;
@ -76,3 +77,20 @@ export class Item {
};
}
}
//#endregion
//#region ItemCompactData
export class ItemCompactData {
public sales: number;
public lbin: number;
public cleanPrice: number;
public price: number;
constructor(sales: number = 0, lbin: number = 0, cleanPrice: number = 0, price: number = 0) {
this.sales = sales;
this.lbin = lbin;
this.cleanPrice = cleanPrice;
this.price = price;
}
}
//#endregion

13
src/errorHandler.ts Normal file
View file

@ -0,0 +1,13 @@
// errorHandler.ts
export function setupErrorHandlers(): void {
process.on('uncaughtException', (error) => {
console.error('Uncaught Exception:', error);
process.exit(1);
});
process.on('unhandledRejection', (reason, promise) => {
console.error('Unhandled Rejection at:', promise, 'reason:', reason);
process.exit(1);
});
}

View file

@ -1,6 +1,6 @@
// utils.ts
import nbt from 'prismarine-nbt';
import { Item } from './Item';
import { Item } from './Types';
import { loadConfig } from './configLoader';
const config = loadConfig();