Made auction command copyable in a single click

This commit is contained in:
MashClashXD 2024-06-06 00:13:48 -04:00 committed by GitHub
parent 153f60c72c
commit e829289e6b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

142
index.js
View file

@ -1,32 +1,32 @@
const {default: axios} = require("axios") const { default: axios } = require("axios");
const config = require("./config.json") const config = require("./config.json");
const discord = require('discord.js') const { WebhookClient, MessageEmbed } = require('discord.js');
const {Worker} = require("worker_threads") const { Worker } = require("worker_threads");
const { asyncInterval, addNotation } = require("./src/helperFunctions") const { asyncInterval, addNotation } = require("./src/helperFunctions");
let threadsToUse = config.data["threadsToUse/speed"] ?? 1
let lastUpdated = 0 let threadsToUse = config.data["threadsToUse/speed"] ?? 1;
let doneWorkers = 0 let lastUpdated = 0;
let startingTime let doneWorkers = 0;
let maxPrice = 0 let startingTime;
let itemDatas = {} let maxPrice = 0;
const workers = [] let itemDatas = {};
const webhookRegex = /https:\/\/discord.com\/api\/webhooks\/(.+)\/(.+)/ const workers = [];
const webhookRegex = /https:\/\/discord.com\/api\/webhooks\/(.+)\/(.+)/;
const bazaarPrice = { const bazaarPrice = {
"RECOMBOBULATOR_3000": 0, "RECOMBOBULATOR_3000": 0,
"HOT_POTATO_BOOK": 0, "HOT_POTATO_BOOK": 0,
"FUMING_POTATO_BOOK": 0 "FUMING_POTATO_BOOK": 0
} };
async function initialize() { async function initialize() {
matches = config.webhook.discordWebhookUrl.match(webhookRegex) const 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`);
const webhook = new discord.WebhookClient(matches[1], matches[2]); const webhook = new WebhookClient({ id: matches[1], token: matches[2] });
await getBzData() await getBzData();
await getMoulberry() await getMoulberry();
await getLBINs() await getLBINs();
for (let j = 0; j < threadsToUse; j++) { for (let j = 0; j < threadsToUse; j++) {
workers[j] = new Worker('./AuctionHandler.js', { workers[j] = new Worker('./AuctionHandler.js', {
@ -36,89 +36,85 @@ async function initialize() {
workerNumber: j, workerNumber: j,
maxPrice: maxPrice maxPrice: maxPrice
} }
}) });
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 = itemDatas[result.itemData.id]?.cleanPrice || "N/A";
if (result.auctionData.lbin - result.auctionData.price >= config.data.minSnipeProfit && averagePrice - result.auctionData.price >= minAvgProfit) { if (result.auctionData.lbin - result.auctionData.price >= config.data.minSnipeProfit && averagePrice - result.auctionData.price >= config.data.minAvgProfit) {
let mustBuyMessage = ''; let mustBuyMessage = '';
const embed = new MessageEmbed()
.setTitle(`**${(result.itemData.name).replace(/§./g, '')}**`)
.setColor("#2e3137")
.setThumbnail(`https://sky.shiiyu.moe/item/${result.itemData.id}`)
.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)}\``);
await webhook.send({ await webhook.send({
username: config.webhook.webhookName, username: config.webhook.webhookName,
avatarURL: config.webhook.webhookPFP, avatarURL: config.webhook.webhookPFP,
embeds: [new discord.MessageEmbed() embeds: [embed]
.setTitle(`**${(result.itemData.name).replaceAll(/§./g, '')}**`) });
.setColor("#2e3137")
.setThumbnail(`https://sky.shiiyu.moe/item/${result.itemData.id}`)
.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)}\``)
]
})
} }
} else if (result === "finished") { } else if (result === "finished") {
doneWorkers++ doneWorkers++;
if (doneWorkers === threadsToUse) { if (doneWorkers === threadsToUse) {
doneWorkers = 0 doneWorkers = 0;
console.log(`Completed in ${(Date.now() - startingTime) / 1000} seconds`) console.log(`Completed in ${(Date.now() - startingTime) / 1000} seconds`);
startingTime = 0 startingTime = 0;
workers[0].emit("done") workers[0].emit("done");
} }
} }
}); });
} }
asyncInterval(async () => {
await getLBINs();
workers.forEach((worker) => {
worker.postMessage({ type: "moulberry", data: itemDatas });
});
}, "lbin", 60000);
asyncInterval(async () => { asyncInterval(async () => {
await getLBINs() await getMoulberry();
workers.forEach((worker) => { workers.forEach((worker) => {
worker.postMessage({type: "moulberry", data: itemDatas}) worker.postMessage({ type: "moulberry", data: itemDatas });
}) });
}, "lbin", 60000) }, "avg", 60e5);
asyncInterval(async () => {
await getMoulberry()
workers.forEach((worker) => {
worker.postMessage({type: "moulberry", data: itemDatas})
})
}, "avg", 60e5)
asyncInterval(async () => { asyncInterval(async () => {
return new Promise(async (resolve) => { return new Promise(async (resolve) => {
const ahFirstPage = await axios.get("https://api.hypixel.net/skyblock/auctions?page=0") const ahFirstPage = await axios.get("https://api.hypixel.net/skyblock/auctions?page=0");
const totalPages = ahFirstPage.data.totalPages const totalPages = ahFirstPage.data.totalPages;
if (ahFirstPage.data.lastUpdated === lastUpdated) { if (ahFirstPage.data.lastUpdated === lastUpdated) {
resolve() resolve();
} else { } else {
lastUpdated = ahFirstPage.data.lastUpdated lastUpdated = ahFirstPage.data.lastUpdated;
startingTime = Date.now() startingTime = Date.now();
console.log("Getting auctions..") console.log("Getting auctions..");
workers.forEach((worker) => { workers.forEach((worker) => {
worker.postMessage({type: "pageCount", data: totalPages}) worker.postMessage({ type: "pageCount", data: totalPages });
}) });
workers[0].once("done", () => { workers[0].once("done", () => {
resolve() resolve();
}) });
} }
}) });
}, "check", 0) }, "check", 0);
} }
async function getLBINs() { async function getLBINs() {
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] = {};
itemDatas[item].lbin = lbinData[item] itemDatas[item].lbin = lbinData[item];
} }
} }
async function getMoulberry() { async function getMoulberry() {
// Fetch the original data for sales and clean price information
const moulberryAvgs = await axios.get("https://moulberry.codes/auction_averages/3day.json"); const moulberryAvgs = await axios.get("https://moulberry.codes/auction_averages/3day.json");
const avgData = moulberryAvgs.data; const avgData = moulberryAvgs.data;
// Fetch the new clean price data
const cleanPriceAvgs = await axios.get("https://moulberry.codes/auction_averages_lbin/1day.json"); const cleanPriceAvgs = await axios.get("https://moulberry.codes/auction_averages_lbin/1day.json");
const cleanPriceData = cleanPriceAvgs.data; const cleanPriceData = cleanPriceAvgs.data;
@ -126,20 +122,16 @@ async function getMoulberry() {
if (!itemDatas[item]) itemDatas[item] = {}; if (!itemDatas[item]) itemDatas[item] = {};
const itemInfo = avgData[item]; const itemInfo = avgData[item];
// Set sales data
itemDatas[item].sales = itemInfo.sales !== undefined ? itemInfo.sales : 0; itemDatas[item].sales = itemInfo.sales !== undefined ? itemInfo.sales : 0;
// Set clean price data from the new endpoint if available, otherwise use the old data
itemDatas[item].cleanPrice = cleanPriceData[item] !== undefined ? Math.round(cleanPriceData[item]) : (itemInfo.clean_price !== undefined ? itemInfo.clean_price : itemInfo.price); itemDatas[item].cleanPrice = cleanPriceData[item] !== undefined ? Math.round(cleanPriceData[item]) : (itemInfo.clean_price !== undefined ? itemInfo.clean_price : 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;
bazaarPrice["HOT_POTATO_BOOK"] = bzData.data.products.HOT_POTATO_BOOK.quick_status.buyPrice bazaarPrice["HOT_POTATO_BOOK"] = bzData.data.products.HOT_POTATO_BOOK.quick_status.buyPrice;
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();