adding mariadb

This commit is contained in:
Ulysia 2024-12-28 15:09:44 +01:00
parent 13035edc40
commit be1ec59e0e
2 changed files with 36 additions and 33 deletions

View file

@ -4,11 +4,31 @@ services:
container_name: hypixel-auc-notifier container_name: hypixel-auc-notifier
build: . build: .
restart: unless-stopped restart: unless-stopped
depends_on:
- db
env_file: env_file:
- .env - .env
environment: environment:
NODE_ENV: "production" NODE_ENV: "production"
DB_HOST: db
DB_USER: root
DB_PASSWORD: example
volumes: volumes:
- /etc/localtime:/etc/localtime:ro - /etc/localtime:/etc/localtime:ro
- /etc/timezone:/etc/timezone:ro - /etc/timezone:/etc/timezone:ro
- ./config.json:/app/dist/src/config.json - ./config.json:/app/dist/src/config.json
db:
image: mariadb
restart: always
environment:
MARIADB_ROOT_PASSWORD: example
adminer:
image: adminer
restart: always
depends_on:
- db
ports:
- 8080:8080

View file

@ -24,7 +24,7 @@ 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() {
@ -43,16 +43,15 @@ async function initialize() {
itemDatas: itemDatas, itemDatas: itemDatas,
bazaarData: bazaarPrice, bazaarData: bazaarPrice,
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: number | null = itemDatas[result.itemData.id]?.cleanPrice || null; 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 || averagePrice! - result.auctionData.price >= config.data.minAvgProfit) (averagePrice || averagePrice! - result.auctionData.price >= config.data.minAvgProfit)
) { ) {
let mustBuyMessage = ''; let mustBuyMessage = '';
@ -63,16 +62,11 @@ async function initialize() {
.setDescription( .setDescription(
`${mustBuyMessage}\nAuction: `${mustBuyMessage}\nAuction:
\`\`\`/viewauction ${result.auctionData.auctionID}\`\`\` \`\`\`/viewauction ${result.auctionData.auctionID}\`\`\`
\nProfit: \`${addNotation( \nProfit: \`${addNotation('oneLetters', result.auctionData.profit)} (${result.auctionData.percentProfit
'oneLetters', }%)\`
result.auctionData.profit
)} (${result.auctionData.percentProfit}%)\`
\nCost: \`${addNotation('oneLetters', result.auctionData.price)}\` \nCost: \`${addNotation('oneLetters', result.auctionData.price)}\`
\nLBIN: \`${addNotation('oneLetters', result.auctionData.lbin)}\` \nLBIN: \`${addNotation('oneLetters', result.auctionData.lbin)}\`
\nSales/Day: \`${addNotation( \nSales/Day: \`${addNotation('oneLetters', result.auctionData.sales)}\`
'oneLetters',
result.auctionData.sales
)}\`
\nType: \`${result.auctionData.ahType}\` \nType: \`${result.auctionData.ahType}\`
\nAverage Price: \`${averagePrice ? addNotation('oneLetters', averagePrice) : 'N/A'}\`` \nAverage Price: \`${averagePrice ? addNotation('oneLetters', averagePrice) : 'N/A'}\``
); );
@ -80,16 +74,14 @@ async function initialize() {
await webhook.send({ await webhook.send({
username: process.env.WEBHOOK_NAME, username: process.env.WEBHOOK_NAME,
avatarURL: process.env.WEBHOOK_PROFILE_PICTURE, avatarURL: process.env.WEBHOOK_PROFILE_PICTURE,
embeds: [embed], embeds: [embed]
}); });
} }
} else if (result === 'finished') { } else if (result === 'finished') {
doneWorkers++; doneWorkers++;
if (doneWorkers === worker_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`
);
startingTime = 0; startingTime = 0;
workers[0].emit('done'); workers[0].emit('done');
} }
@ -122,9 +114,7 @@ async function initialize() {
asyncInterval( asyncInterval(
async () => { async () => {
return new Promise(async (resolve) => { return new Promise(async (resolve) => {
const ahFirstPage = await axios.get( const ahFirstPage = await axios.get('https://api.hypixel.net/skyblock/auctions?page=0');
'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();
@ -156,14 +146,10 @@ async function getLBINs(): Promise<void> {
} }
async function getMoulberry(): Promise<void> { async function getMoulberry(): Promise<void> {
const moulberryAvgs = await axios.get( const moulberryAvgs = await axios.get('https://moulberry.codes/auction_averages/3day.json');
'https://moulberry.codes/auction_averages/3day.json'
);
const avgData = moulberryAvgs.data; const avgData = moulberryAvgs.data;
const cleanPriceAvgs = await axios.get( const cleanPriceAvgs = await axios.get('https://moulberry.codes/auction_averages_lbin/1day.json');
'https://moulberry.codes/auction_averages_lbin/1day.json'
);
const cleanPriceData = cleanPriceAvgs.data; const cleanPriceData = cleanPriceAvgs.data;
for (const item of Object.keys(avgData)) { for (const item of Object.keys(avgData)) {
@ -182,12 +168,9 @@ async function getMoulberry(): Promise<void> {
async function getBzData(): Promise<void> { async function getBzData(): Promise<void> {
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'] = bazaarPrice['RECOMBOBULATOR_3000'] = bzData.data.products.RECOMBOBULATOR_3000.quick_status.buyPrice;
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'] = bazaarPrice['FUMING_POTATO_BOOK'] = bzData.data.products.FUMING_POTATO_BOOK.quick_status.buyPrice;
bzData.data.products.HOT_POTATO_BOOK.quick_status.buyPrice;
bazaarPrice['FUMING_POTATO_BOOK'] =
bzData.data.products.FUMING_POTATO_BOOK.quick_status.buyPrice;
} }
initialize(); initialize();