Add new logic for when to display auctions

- Uses a different and more accurate JSON for retrieving average auction prices
- Added the average price to message description
This commit is contained in:
MashClashXD 2024-06-05 17:04:10 -04:00 committed by GitHub
parent c7fcad5929
commit 6c54283153
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -18,6 +18,7 @@ const bazaarPrice = {
"FUMING_POTATO_BOOK": 0 "FUMING_POTATO_BOOK": 0
} }
async function initialize() { async function initialize() {
matches = config.webhook.discordWebhookUrl.match(webhookRegex) matches = config.webhook.discordWebhookUrl.match(webhookRegex)
if (!matches) return console.log(`[Main thread] Couldn't parse Webhook URL`) if (!matches) return console.log(`[Main thread] Couldn't parse Webhook URL`)
@ -39,7 +40,9 @@ async function initialize() {
workers[j].on("message", async (result) => { workers[j].on("message", async (result) => {
if (result.itemData !== undefined) { if (result.itemData !== undefined) {
if (result.auctionData.lbin >= result.auctionData.price) { let averagePrice = itemDatas[result.itemData.id]?.cleanPrice || "N/A";
if (result.auctionData.lbin - result.auctionData.price >= config.data.minSnipeProfit && averagePrice - result.auctionData.price >= minAvgProfit) {
let mustBuyMessage = '';
await webhook.send({ await webhook.send({
username: config.webhook.webhookName, username: config.webhook.webhookName,
avatarURL: config.webhook.webhookPFP, avatarURL: config.webhook.webhookPFP,
@ -47,7 +50,7 @@ async function initialize() {
.setTitle(`**${(result.itemData.name).replaceAll(/§./g, '')}**`) .setTitle(`**${(result.itemData.name).replaceAll(/§./g, '')}**`)
.setColor("#2e3137") .setColor("#2e3137")
.setThumbnail(`https://sky.shiiyu.moe/item/${result.itemData.id}`) .setThumbnail(`https://sky.shiiyu.moe/item/${result.itemData.id}`)
.setDescription(`Auction: \`/viewauction ${result.auctionData.auctionID}\`\nProfit: \`${addNotation("oneLetters", (result.auctionData.profit))} (${result.auctionData.percentProfit}%)\`\nCost: \`${addNotation("oneLetters", (result.auctionData.price))}\`\nLBIN: \`${addNotation("oneLetters", (result.auctionData.lbin))}\`\nSales/Day: \`${addNotation("oneLetters", result.auctionData.sales)}\`\nType: \`${result.auctionData.ahType}\``) .setDescription(`${mustBuyMessage}\nAuction: \`/viewauction ${result.auctionData.auctionID}\`\nProfit: \`${addNotation("oneLetters", (result.auctionData.profit))} (${result.auctionData.percentProfit}%)\`\nCost: \`${addNotation("oneLetters", (result.auctionData.price))}\`\nLBIN: \`${addNotation("oneLetters", (result.auctionData.lbin))}\`\nSales/Day: \`${addNotation("oneLetters", result.auctionData.sales)}\`\nType: \`${result.auctionData.ahType}\`\nAverage Price: \`${addNotation("oneLetters", averagePrice)}\``)
] ]
}) })
@ -64,6 +67,7 @@ async function initialize() {
}); });
} }
asyncInterval(async () => { asyncInterval(async () => {
await getLBINs() await getLBINs()
workers.forEach((worker) => { workers.forEach((worker) => {
@ -110,24 +114,27 @@ async function getLBINs() {
} }
async function getMoulberry() { async function getMoulberry() {
const moulberryAvgs = await axios.get("https://moulberry.codes/auction_averages/3day.json") // Fetch the original data for sales and clean price information
const avgData = moulberryAvgs.data const moulberryAvgs = await axios.get("https://moulberry.codes/auction_averages/3day.json");
const avgData = moulberryAvgs.data;
// Fetch the new clean price data
const cleanPriceAvgs = await axios.get("https://moulberry.codes/auction_averages_lbin/1day.json");
const cleanPriceData = cleanPriceAvgs.data;
for (const item of Object.keys(avgData)) { for (const item of Object.keys(avgData)) {
itemDatas[item] = {} if (!itemDatas[item]) itemDatas[item] = {};
const itemInfo = avgData[item] const itemInfo = avgData[item];
if (itemInfo.sales !== undefined) {
itemDatas[item].sales = itemInfo.sales // Set sales data
} else { itemDatas[item].sales = itemInfo.sales !== undefined ? itemInfo.sales : 0;
itemDatas[item].sales = 0
} // Set clean price data from the new endpoint if available, otherwise use the old data
if (itemInfo.clean_price) { itemDatas[item].cleanPrice = cleanPriceData[item] !== undefined ? Math.round(cleanPriceData[item]) : (itemInfo.clean_price !== undefined ? itemInfo.clean_price : itemInfo.price);
itemDatas[item].cleanPrice = itemInfo.clean_price
} else {
itemDatas[item].cleanPrice = itemInfo.price
}
} }
} }
async function getBzData() { async function getBzData() {
const bzData = await axios.get("https://api.hypixel.net/skyblock/bazaar") const bzData = await axios.get("https://api.hypixel.net/skyblock/bazaar")
bazaarPrice["RECOMBOBULATOR_3000"] = bzData.data.products.RECOMBOBULATOR_3000.quick_status.buyPrice bazaarPrice["RECOMBOBULATOR_3000"] = bzData.data.products.RECOMBOBULATOR_3000.quick_status.buyPrice
@ -135,5 +142,4 @@ async function getBzData() {
bazaarPrice["FUMING_POTATO_BOOK"] = bzData.data.products.FUMING_POTATO_BOOK.quick_status.buyPrice bazaarPrice["FUMING_POTATO_BOOK"] = bzData.data.products.FUMING_POTATO_BOOK.quick_status.buyPrice
} }
initialize() initialize()