-
Notifications
You must be signed in to change notification settings - Fork 63
/
index.js
139 lines (124 loc) · 5.2 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
const {default: axios} = require("axios")
const config = require("./config.json")
const discord = require('discord.js')
const {Worker} = require("worker_threads")
const { asyncInterval, addNotation } = require("./src/helperFunctions")
let threadsToUse = config.data["threadsToUse/speed"] ?? 1
let lastUpdated = 0
let doneWorkers = 0
let startingTime
let maxPrice = 0
let itemDatas = {}
const workers = []
const webhookRegex = /https:\/\/discord.com\/api\/webhooks\/(.+)\/(.+)/
const bazaarPrice = {
"RECOMBOBULATOR_3000": 0,
"HOT_POTATO_BOOK": 0,
"FUMING_POTATO_BOOK": 0
}
async function initialize() {
matches = config.webhook.discordWebhookUrl.match(webhookRegex)
if (!matches) return console.log(`[Main thread] Couldn't parse Webhook URL`)
const webhook = new discord.WebhookClient(matches[1], matches[2]);
await getBzData()
await getMoulberry()
await getLBINs()
for (let j = 0; j < threadsToUse; j++) {
workers[j] = new Worker('./AuctionHandler.js', {
workerData: {
itemDatas: itemDatas,
bazaarData: bazaarPrice,
workerNumber: j,
maxPrice: maxPrice
}
})
workers[j].on("message", async (result) => {
if (result.itemData !== undefined) {
if (result.auctionData.lbin >= result.auctionData.price) {
await webhook.send({
username: config.webhook.webhookName,
avatarURL: config.webhook.webhookPFP,
embeds: [new discord.MessageEmbed()
.setTitle(`**${(result.itemData.name).replaceAll(/§./g, '')}**`)
.setColor("#2e3137")
.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}\``)
]
})
}
} else if (result === "finished") {
doneWorkers++
if (doneWorkers === threadsToUse) {
doneWorkers = 0
console.log(`Completed in ${(Date.now() - startingTime) / 1000} seconds`)
startingTime = 0
workers[0].emit("done")
}
}
});
}
asyncInterval(async () => {
await getLBINs()
workers.forEach((worker) => {
worker.postMessage({type: "moulberry", data: itemDatas})
})
}, "lbin", 60000)
asyncInterval(async () => {
await getMoulberry()
workers.forEach((worker) => {
worker.postMessage({type: "moulberry", data: itemDatas})
})
}, "avg", 60e5)
asyncInterval(async () => {
return new Promise(async (resolve) => {
const ahFirstPage = await axios.get("https://api.hypixel.net/skyblock/auctions?page=0")
const totalPages = ahFirstPage.data.totalPages
if (ahFirstPage.data.lastUpdated === lastUpdated) {
resolve()
} else {
lastUpdated = ahFirstPage.data.lastUpdated
startingTime = Date.now()
console.log("Getting auctions..")
workers.forEach((worker) => {
worker.postMessage({type: "pageCount", data: totalPages})
})
workers[0].once("done", () => {
resolve()
})
}
})
}, "check", 0)
}
async function getLBINs() {
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] = {}
itemDatas[item].lbin = lbinData[item]
}
}
async function getMoulberry() {
const moulberryAvgs = await axios.get("https://moulberry.codes/auction_averages/3day.json")
const avgData = moulberryAvgs.data
for (const item of Object.keys(avgData)) {
itemDatas[item] = {}
const itemInfo = avgData[item]
if (itemInfo.sales !== undefined) {
itemDatas[item].sales = itemInfo.sales
} else {
itemDatas[item].sales = 0
}
if (itemInfo.clean_price) {
itemDatas[item].cleanPrice = itemInfo.clean_price
} else {
itemDatas[item].cleanPrice = itemInfo.price
}
}
}
async function getBzData() {
const bzData = await axios.get("https://api.hypixel.net/skyblock/bazaar")
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["FUMING_POTATO_BOOK"] = bzData.data.products.FUMING_POTATO_BOOK.quick_status.buyPrice
}
initialize()