added more types
This commit is contained in:
parent
d4275929ac
commit
9f7cc8f8e9
8 changed files with 75 additions and 30 deletions
|
@ -2,6 +2,7 @@ import axios from 'axios';
|
||||||
import { getParsed, getProfit, splitNumber, getRawCraft } from './src/helperFunctions';
|
import { getParsed, getProfit, splitNumber, getRawCraft } from './src/helperFunctions';
|
||||||
import { parentPort, workerData, isMainThread } from 'worker_threads';
|
import { parentPort, workerData, isMainThread } from 'worker_threads';
|
||||||
import { Item } from './src/Item';
|
import { Item } from './src/Item';
|
||||||
|
import { AuctionResponse, Auction, Bid } from './src/auctionType';
|
||||||
|
|
||||||
import { loadConfig } from './src/configLoader';
|
import { loadConfig } from './src/configLoader';
|
||||||
const config = loadConfig();
|
const config = loadConfig();
|
||||||
|
@ -10,8 +11,7 @@ if (isMainThread || !parentPort) {
|
||||||
throw new Error('This module can only be run in a Worker thread.');
|
throw new Error('This module can only be run in a Worker thread.');
|
||||||
}
|
}
|
||||||
|
|
||||||
const threadsToUse: number = config.data['threadsToUse/speed'];
|
const worker_count: number = config.data.worker_count;
|
||||||
|
|
||||||
let minProfit = config.data.minSnipeProfit;
|
let minProfit = config.data.minSnipeProfit;
|
||||||
let minPercentProfit = config.data.minSnipePP;
|
let minPercentProfit = config.data.minSnipePP;
|
||||||
let ignoredAuctions: any[] = [];
|
let ignoredAuctions: any[] = [];
|
||||||
|
@ -31,10 +31,10 @@ parentPort.on('message', async (message) => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
async function parsePage(i) {
|
async function parsePage(i: number) {
|
||||||
console.log(`[Worker ${workerData.workerNumber}] Parsing page ${i}`);
|
console.log(`[Worker ${workerData.workerNumber}] Parsing page ${i}`);
|
||||||
try {
|
try {
|
||||||
const auctionPage = await axios.get(
|
const auctionPage = await axios.get<AuctionResponse>(
|
||||||
`https://api.hypixel.net/skyblock/auctions?page=${i}`
|
`https://api.hypixel.net/skyblock/auctions?page=${i}`
|
||||||
);
|
);
|
||||||
for (const auction of auctionPage.data.auctions) {
|
for (const auction of auctionPage.data.auctions) {
|
||||||
|
@ -144,12 +144,12 @@ async function parsePage(i) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async function doTask(totalPages) {
|
async function doTask(totalPages: number) {
|
||||||
console.log(
|
console.log(
|
||||||
`[Worker ${workerData.workerNumber}] Starting task for ${totalPages} pages`
|
`[Worker ${workerData.workerNumber}] Starting task for ${totalPages} pages`
|
||||||
);
|
);
|
||||||
let startingPage = 0;
|
let startingPage = 0;
|
||||||
const pagePerThread = splitNumber(totalPages, threadsToUse);
|
const pagePerThread = splitNumber(totalPages, worker_count);
|
||||||
|
|
||||||
if (workerData.workerNumber !== 0 && startingPage === 0) {
|
if (workerData.workerNumber !== 0 && startingPage === 0) {
|
||||||
const clonedStarting = pagePerThread.slice();
|
const clonedStarting = pagePerThread.slice();
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"data": {
|
"data": {
|
||||||
"thread_count/speed": 48,
|
"worker_count": 48,
|
||||||
|
|
||||||
"minSnipeProfit": 900000,
|
"minSnipeProfit": 900000,
|
||||||
"minAvgProfit": 500000,
|
"minAvgProfit": 500000,
|
||||||
|
|
34
index.ts
34
index.ts
|
@ -7,13 +7,27 @@ import { InitTable } from './src/sqlFunctions';
|
||||||
import { loadConfig } from './src/configLoader';
|
import { loadConfig } from './src/configLoader';
|
||||||
const config = loadConfig();
|
const config = loadConfig();
|
||||||
|
|
||||||
|
class ItemData {
|
||||||
|
public sales: number;
|
||||||
|
public lbin: number;
|
||||||
|
public cleanPrice: number;
|
||||||
|
public price: number;
|
||||||
|
|
||||||
let thread_count = config.data['thread_count/speed'] ?? 1;
|
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 lastUpdated = 0;
|
||||||
let doneWorkers = 0;
|
let doneWorkers = 0;
|
||||||
let startingTime;
|
let startingTime: number;
|
||||||
let maxPrice = 0;
|
let maxPrice = 0;
|
||||||
let itemDatas = {};
|
let itemDatas: Record<string, ItemData> = {};
|
||||||
const workers: Worker[] = [];
|
const workers: Worker[] = [];
|
||||||
const webhookRegex = /https:\/\/discord.com\/api\/webhooks\/(.+)\/(.+)/;
|
const webhookRegex = /https:\/\/discord.com\/api\/webhooks\/(.+)\/(.+)/;
|
||||||
|
|
||||||
|
@ -33,7 +47,7 @@ async function initialize() {
|
||||||
await getMoulberry();
|
await getMoulberry();
|
||||||
await getLBINs();
|
await getLBINs();
|
||||||
|
|
||||||
for (let j = 0; j < thread_count; j++) {
|
for (let j = 0; j < worker_count; j++) {
|
||||||
workers[j] = new Worker('/app/dist/AuctionHandler.worker.js', {
|
workers[j] = new Worker('/app/dist/AuctionHandler.worker.js', {
|
||||||
workerData: {
|
workerData: {
|
||||||
itemDatas: itemDatas,
|
itemDatas: itemDatas,
|
||||||
|
@ -45,11 +59,11 @@ async function initialize() {
|
||||||
|
|
||||||
workers[j].on('message', async (result) => {
|
workers[j].on('message', async (result) => {
|
||||||
if (result.itemData !== undefined) {
|
if (result.itemData !== undefined) {
|
||||||
let averagePrice = itemDatas[result.itemData.id]?.cleanPrice || 'N/A';
|
let averagePrice: number | null = itemDatas[result.itemData.id]?.cleanPrice || null;
|
||||||
if (
|
if (
|
||||||
result.auctionData.lbin - result.auctionData.price >=
|
result.auctionData.lbin - result.auctionData.price >=
|
||||||
config.data.minSnipeProfit &&
|
config.data.minSnipeProfit &&
|
||||||
averagePrice - result.auctionData.price >= config.data.minAvgProfit
|
(averagePrice || averagePrice! - result.auctionData.price >= config.data.minAvgProfit)
|
||||||
) {
|
) {
|
||||||
let mustBuyMessage = '';
|
let mustBuyMessage = '';
|
||||||
const embed = new EmbedBuilder()
|
const embed = new EmbedBuilder()
|
||||||
|
@ -70,7 +84,7 @@ async function initialize() {
|
||||||
result.auctionData.sales
|
result.auctionData.sales
|
||||||
)}\`
|
)}\`
|
||||||
\nType: \`${result.auctionData.ahType}\`
|
\nType: \`${result.auctionData.ahType}\`
|
||||||
\nAverage Price: \`${addNotation('oneLetters', averagePrice)}\``
|
\nAverage Price: \`${averagePrice ? addNotation('oneLetters', averagePrice) : 'N/A'}\``
|
||||||
);
|
);
|
||||||
|
|
||||||
await webhook.send({
|
await webhook.send({
|
||||||
|
@ -81,7 +95,7 @@ async function initialize() {
|
||||||
}
|
}
|
||||||
} else if (result === 'finished') {
|
} else if (result === 'finished') {
|
||||||
doneWorkers++;
|
doneWorkers++;
|
||||||
if (doneWorkers === thread_count) {
|
if (doneWorkers === worker_count) {
|
||||||
doneWorkers = 0;
|
doneWorkers = 0;
|
||||||
console.log(
|
console.log(
|
||||||
`Completed in ${(Date.now() - startingTime) / 1000} seconds`
|
`Completed in ${(Date.now() - startingTime) / 1000} seconds`
|
||||||
|
@ -146,7 +160,7 @@ async function getLBINs(): Promise<void> {
|
||||||
const lbins = await axios.get('https://moulberry.codes/lowestbin.json');
|
const lbins = await axios.get('https://moulberry.codes/lowestbin.json');
|
||||||
const lbinData = lbins.data;
|
const lbinData = lbins.data;
|
||||||
for (const item of Object.keys(lbinData)) {
|
for (const item of Object.keys(lbinData)) {
|
||||||
if (!itemDatas[item]) itemDatas[item] = {};
|
if (!itemDatas[item]) itemDatas[item] = new ItemData();
|
||||||
itemDatas[item].lbin = lbinData[item];
|
itemDatas[item].lbin = lbinData[item];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -163,7 +177,7 @@ async function getMoulberry(): Promise<void> {
|
||||||
const cleanPriceData = cleanPriceAvgs.data;
|
const cleanPriceData = cleanPriceAvgs.data;
|
||||||
|
|
||||||
for (const item of Object.keys(avgData)) {
|
for (const item of Object.keys(avgData)) {
|
||||||
if (!itemDatas[item]) itemDatas[item] = {};
|
if (!itemDatas[item]) itemDatas[item] = new ItemData();
|
||||||
const itemInfo = avgData[item];
|
const itemInfo = avgData[item];
|
||||||
|
|
||||||
itemDatas[item].sales = itemInfo.sales !== undefined ? itemInfo.sales : 0;
|
itemDatas[item].sales = itemInfo.sales !== undefined ? itemInfo.sales : 0;
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
"copy-paste": "^1.5.3",
|
"copy-paste": "^1.5.3",
|
||||||
"discord.js": "^14.16.3",
|
"discord.js": "^14.16.3",
|
||||||
"express": "^4.21.2",
|
"express": "^4.21.2",
|
||||||
"node": "^23.5.0",
|
|
||||||
"node-notifier": "^10.0.1",
|
"node-notifier": "^10.0.1",
|
||||||
"open": "^8.4.2",
|
"open": "^8.4.2",
|
||||||
"prismarine-nbt": "^2.7.0",
|
"prismarine-nbt": "^2.7.0",
|
||||||
|
|
|
@ -6,7 +6,7 @@ export interface ItemData {
|
||||||
stars: number;
|
stars: number;
|
||||||
rarity: string;
|
rarity: string;
|
||||||
recomb: boolean;
|
recomb: boolean;
|
||||||
enchants: string[];
|
enchants: Record<string, number>;
|
||||||
hpbs: number;
|
hpbs: number;
|
||||||
fpbs: number;
|
fpbs: number;
|
||||||
gemstones: string[];
|
gemstones: string[];
|
||||||
|
@ -34,7 +34,7 @@ export class Item {
|
||||||
auctionID: string,
|
auctionID: string,
|
||||||
price: number,
|
price: number,
|
||||||
rarity: string,
|
rarity: string,
|
||||||
enchants: string[],
|
enchants: Record<string, number>,
|
||||||
hpbs: number,
|
hpbs: number,
|
||||||
fpbs: number,
|
fpbs: number,
|
||||||
recomb: boolean,
|
recomb: boolean,
|
||||||
|
|
39
src/auctionType.ts
Normal file
39
src/auctionType.ts
Normal file
|
@ -0,0 +1,39 @@
|
||||||
|
export type AuctionResponse = {
|
||||||
|
success: boolean
|
||||||
|
page: number
|
||||||
|
totalPages: number
|
||||||
|
totalAuctions: number
|
||||||
|
lastUpdated: number
|
||||||
|
auctions: Auction[]
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Auction = {
|
||||||
|
uuid: string
|
||||||
|
auctioneer: string
|
||||||
|
profile_id: string
|
||||||
|
coop: string[]
|
||||||
|
start: number
|
||||||
|
end: number
|
||||||
|
item_name: string
|
||||||
|
item_lore: string
|
||||||
|
extra: string
|
||||||
|
category: string
|
||||||
|
tier: string
|
||||||
|
starting_bid: number
|
||||||
|
item_bytes: string
|
||||||
|
claimed: boolean
|
||||||
|
claimed_bidders: any[]
|
||||||
|
highest_bid_amount: number
|
||||||
|
last_updated: number
|
||||||
|
bin: boolean
|
||||||
|
bids: Bid[]
|
||||||
|
item_uuid?: string
|
||||||
|
}
|
||||||
|
|
||||||
|
export type Bid = {
|
||||||
|
auction_id: string
|
||||||
|
bidder: string
|
||||||
|
profile_id: string
|
||||||
|
amount: number
|
||||||
|
timestamp: number
|
||||||
|
}
|
|
@ -3,7 +3,7 @@ import * as path from 'path';
|
||||||
|
|
||||||
export interface ConfigType {
|
export interface ConfigType {
|
||||||
data: {
|
data: {
|
||||||
'threadsToUse/speed': number;
|
worker_count: number;
|
||||||
minSnipeProfit: number;
|
minSnipeProfit: number;
|
||||||
minAvgProfit: number;
|
minAvgProfit: number;
|
||||||
minCraftProfit: number;
|
minCraftProfit: number;
|
||||||
|
@ -11,14 +11,7 @@ export interface ConfigType {
|
||||||
rawCraftMaxWeightPP: number;
|
rawCraftMaxWeightPP: number;
|
||||||
minSnipePP: number;
|
minSnipePP: number;
|
||||||
minCraftPP: number;
|
minCraftPP: number;
|
||||||
ignoreCategories: {
|
ignoreCategories: Record<string, boolean>;
|
||||||
weapon: boolean;
|
|
||||||
accessories: boolean;
|
|
||||||
armor: boolean;
|
|
||||||
misc: boolean;
|
|
||||||
blocks: boolean;
|
|
||||||
consumables: boolean;
|
|
||||||
}
|
|
||||||
minSales: number;
|
minSales: number;
|
||||||
includeCraftCost: boolean;
|
includeCraftCost: boolean;
|
||||||
minPriceForRawcraft: number;
|
minPriceForRawcraft: number;
|
||||||
|
|
|
@ -22,7 +22,7 @@ async function InitTable() {
|
||||||
// Retrieve all rows
|
// Retrieve all rows
|
||||||
const rows = await allQuery(db, 'SELECT * FROM users');
|
const rows = await allQuery(db, 'SELECT * FROM users');
|
||||||
console.log('All rows:', rows);
|
console.log('All rows:', rows);
|
||||||
} catch (err) {
|
} catch (err: any) {
|
||||||
console.error('Database error:', err.message);
|
console.error('Database error:', err.message);
|
||||||
} finally {
|
} finally {
|
||||||
db.close();
|
db.close();
|
||||||
|
|
Loading…
Reference in a new issue