mirror of
https://github.com/cassoule/flopobot_v2.git
synced 2026-01-18 16:37:40 +01:00
wip
This commit is contained in:
@@ -10,6 +10,7 @@ import {
|
|||||||
getAllUsers,
|
getAllUsers,
|
||||||
getMarketOffers,
|
getMarketOffers,
|
||||||
getOfferBids,
|
getOfferBids,
|
||||||
|
getSkin,
|
||||||
getUser,
|
getUser,
|
||||||
insertManySkins,
|
insertManySkins,
|
||||||
insertUser,
|
insertUser,
|
||||||
@@ -259,34 +260,36 @@ function handleMarketOffersUpdate() {
|
|||||||
const offers = getMarketOffers.all();
|
const offers = getMarketOffers.all();
|
||||||
offers.forEach((offer) => {
|
offers.forEach((offer) => {
|
||||||
console.log(`[Market Cron] Checking offer ID: ${offer.id}, Status: ${offer.status}`);
|
console.log(`[Market Cron] Checking offer ID: ${offer.id}, Status: ${offer.status}`);
|
||||||
console.log(`Now: ${now}, Closing At: ${offer.closing_at}, ${now >= offer.closing_at}`);
|
|
||||||
if (true) return; // Disable market offer closing for now
|
|
||||||
if (now >= offer.closing_at && offer.status !== "closed") {
|
if (now >= offer.closing_at && offer.status !== "closed") {
|
||||||
const bids = getOfferBids.all(offer.id);
|
const bids = getOfferBids.all(offer.id);
|
||||||
console.log(bids.length);
|
|
||||||
const lastBid = bids[0];
|
const lastBid = bids[0];
|
||||||
console.log(lastBid);
|
|
||||||
const seller = getUser.get(offer.seller_id);
|
const seller = getUser.get(offer.seller_id);
|
||||||
console.log(seller);
|
const buyer = getUser.get(lastBid.bidder_id);
|
||||||
const buyer = getUser.get(offer.buyer_id);
|
|
||||||
console.log(buyer);
|
|
||||||
|
|
||||||
console.log(offer.id, buyer.id, lastBid.offer_amount);
|
try {
|
||||||
|
// Change skin ownership
|
||||||
updateMarketOffer.run({
|
const skin = getSkin.get(offer.skin_uuid);
|
||||||
id: offer.id,
|
if (!skin) throw new Error(`Skin not found for offer ID: ${offer.id}`);
|
||||||
buyer_id: buyer.id,
|
updateSkin.run({
|
||||||
final_price: lastBid.offer_amount,
|
user_id: buyer.id,
|
||||||
status: "closed",
|
currentLvl: skin.currentLvl,
|
||||||
});
|
currentChroma: skin.currentChroma,
|
||||||
|
currentPrice: skin.currentPrice,
|
||||||
const newUserCoins = seller.coins + lastBid.offer_amount;
|
uuid: skin.uuid,
|
||||||
updateUserCoins.run({ id: seller.id, coins: newUserCoins });
|
});
|
||||||
|
updateMarketOffer.run({
|
||||||
// Change skin ownership
|
id: offer.id,
|
||||||
updateSkin.run({ user_id: buyer.id, uuid: offer.skin_uuid });
|
buyer_id: buyer.id,
|
||||||
|
final_price: lastBid.offer_amount,
|
||||||
//TODO: Notify users in DMs
|
status: "closed",
|
||||||
|
});
|
||||||
|
const newUserCoins = seller.coins + lastBid.offer_amount;
|
||||||
|
updateUserCoins.run({ id: seller.id, coins: newUserCoins });
|
||||||
|
//TODO: Notify users in DMs
|
||||||
|
} catch (e) {
|
||||||
|
console.error(`[Market Cron] Error processing offer ID: ${offer.id}`, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user