Jump to content
McKay Development

sludgefudge

Member
  • Posts

    4
  • Joined

  • Last visited

Everything posted by sludgefudge

  1. let buyOffertf2 = 0; for (let i = 0; i < offer.itemsToReceive.length; i++) { if ( offer.itemsToReceive[i]["market_hash_name"] === "Mann Co. Supply Crate Key" ) { buyOffertf2++; } else { client.chat.sendFriendMessage( offer.partner, `I have to cancel your trade offer because it has unsupported items (${offer.itemsToReceive[i]["market_hash_name"]}). I currently only accept 'Mann Co. Supply Crate Key'` ); offer.cancel((err) => { if (err != null) { console.log( red, `${time} Error in cancelling invalid item trade offer. Offer id: ${offer.id}` ); } }); break; } } if (buyOffertf2 === offer.itemsToReceive.length) { mongo.users.findOne( { steamid: offer.partner.getSteamID64() }, (err, data) => { if (err) { console.log(red, `${time} MongoDB buy offer user find error`); } else { if (data == null) { client.chat.sendFriendMessage( offer.partner, `You have not yet added me and I cannot accept your offer. Please add me before a trade. I have cancelled your offer.` ); } else { client.chat.sendFriendTyping(offer.partner); client.chat.sendFriendMessage( offer.partner, `Please wait while I process your order` ); offer.accept((err, status) => { client.chat.sendFriendTyping(offer.partner); client.chat.sendFriendMessage( offer.partner, `I have accepted your offer. Steam usually transfers items during this time. Please be patient while the trade is complete.` ); if (err) { client.chat.sendFriendTyping(offer.partner); client.chat.sendFriendMessage( offer.partner, `There was an error while accepting your offer` ); } else { switch (status) { case "accepted": offer.getExchangeDetails( ( err, status, tradeInitTime, receivedItems, sentItems ) => { if (err) { console.log( red, `${time} Trade has failed. Status: ${status}` ); } else if (status === 3) { let acceptOfferTf2Qty = 0; for (let i = 0; i < receivedItems.length; i++) { if ( receivedItems[i]["market_hash_name"] === "Mann Co. Supply Crate Key" ) { acceptOfferTf2Qty++; } } if (acceptOfferTf2Qty === buyOffertf2) { let buyOfferTf2CostUSD = pricing.buy * acceptOfferTf2Qty; let buyOfferTf2CostBTC = getBTC(buyOfferTf2CostUSD); mongo.users.findOne( { steamid: offer.partner.getSteamID64() }, (err, data) => { if (err) { console.log( red, `${time} Error finding user in MongoDB` ); } else { const updatedBTC = parseFloat( bigDecimal.add( data["btcbalance"], buyOfferTf2CostBTC ) ); mongo.users.findOneAndUpdate( { steamid: offer.partner.getSteamID64(), }, { btcbalance: updatedBTC }, { new: true }, (err, data) => { if (err) { console.log( red, `${time} Error in writing btc balance to mongoDB.` ); } else { client.chat.sendFriendMessage( offer.partner, `I have added ${buyOfferTf2CostBTC} BTC ($${buyOfferTf2CostUSD}) to your bitcoin balance at the current bitcoin price of $${usdbtc}. Your updated bitcoin balance is ${data["btcbalance"]}\n\nPlease use the 'withdraw' command to withdraw your bitcoin balance.\n\nThank you for trading with me. If you enjoyed my service please comment a +rep on my profile. ` ); } } ); } } ); } } else { console.log( red, `${time} Status is not Confirmed. Balance has not been added. Status: ${status}` ); } } ); } } }); } } } ); } Sorry for this huge code with only small parts of your modules. But if you can confirm if the way in which I've handled this trade can there be a chance for error? Thank you for your help
  2. What would be the best way to confirm a trade has 100% completed if there is no margin for error?
  3. manager.on("sentOfferChanged", (offer, oldstate) => { let oldState = TradeOfferManager.ETradeOfferState[oldstate]; let currentState = TradeOfferManager.ETradeOfferState[offer.state]; //console.log(offer.partner.getSteamID64()); console.log( green, `Sent offer state changed from ${oldState} to ${currentState}` )}; Output: Sent offer state changed from CreatedNeedsConfirmation to InvalidItems Sent offer state changed from CreatedNeedsConfirmation to InvalidItems Sent offer state changed from CreatedNeedsConfirmation to Accepted So basically, I sent 2 trades from my BOT Account to 2 different accounts. The problem is both the trades changed their current State to InvalidItems when one of the offers was accepted and then later on that trade was confirmed. Why did both the trades emit InvalidItems? I am not able to replicate this issue again. Is this common? and is there any way to avoid this? Thanks
×
×
  • Create New...