Jump to content
McKay Development

Recommended Posts

Posted

Hello,

I noticed that some offers are sometimes skipped (possibly due to steam lags or smthing like that) in the newOffer event. My bot sees those offers only when it re-logins.
My question would be: Is there a way to tell the bot to check for pending offers and let manager.on('newOffer'); handle them every x seconds? I saw the getOffers function, that might work, but how do I make manager.on('newOffer') handle those offers?

Posted (edited)
// Get all active offers
manager.getOffers(TradeOfferManager.EOfferFilter.ActiveOnly, (err, sent, received) => {
    // Loop through recieved trade offers and execute the processOffer function on each. 
    if (received) {
        for (var i = 0; i < received.length; i++) {
                processOffer(received[i]);
        }
    }
});

You could put the above in a setInterval.

The processOffer function is the same thing that you do when you get the newOffer event.

So if you have a large function like:

manager.on('newOffer', offer => {
	// code 
});

You can change it to:

manager.on('newOffer', offer => processOffer(offer));

function processOffer(offer) {
	// code
}

And so then you can process an offer from elsewhere. 

Edited by vrtgn
Posted (edited)
1 hour ago, vrtgn said:

// Get all active offers
manager.getOffers(TradeOfferManager.EOfferFilter.ActiveOnly, (err, sent, received) => {
    // Loop through recieved trade offers and execute the processOffer function on each. 
    if (received) {
        for (var i = 0; i < received.length; i++) {
                processOffer(received[i]);
        }
    }
});

You could put the above in a setInterval.

The processOffer function is the same thing that you do when you get the newOffer event.

So if you have a large function like:


manager.on('newOffer', offer => {
	// code 
});

You can change it to:


manager.on('newOffer', offer => processOffer(offer));

function processOffer(offer) {
	// code
}

And so then you can process an offer from elsewhere. 

What if my setInterval executes at the same time as newOffer?
(Won't the duplication be a problem?)

Edited by Op1x3r

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...