Jump to content
McKay Development

Recommended Posts

Hello!

I'm trying to send automatic offers. I have two functions for doing this: One for the ones I want to send and other to send counter offers.

 

The first one works perfect (Thanks again for helping me with that), then I decided to copy-paste that for the second and change it a little. But here's what is strange: the couner function can send offers, but can't confirm them because the offer id is always null.

 

Here are the 2 offers objects:

TradeOffer {
  partner: censored,
  id: '2192436500',
  message: 'Here's your trade',
  state: 9,
  itemsToGive:
   [ ... ],
  itemsToReceive: [ ... ],
  isOurOffer: true,
  created: 2018-01-21T11:03:44.021Z,
  updated: 2018-01-21T11:03:44.021Z,
  expires: 2018-02-04T11:03:44.021Z,
  tradeID: null,
  fromRealTimeTrade: false,
  confirmationMethod: 2,
  escrowEnds: null,
  rawJson: '' }

And this is the wrong one:

TradeOffer {
  partner: censored,
  id: null,
  message: 'That was not the correct price. Here's what I wanted.',
  state: 1,
  itemsToGive: [ ... ],
  itemsToReceive:
   [ ... ],
  isOurOffer: true,
  created: null,
  updated: null,
  expires: null,
  tradeID: null,
  fromRealTimeTrade: false,
  confirmationMethod: null,
  escrowEnds: null,
  rawJson: '' }

Here is the working one:

var offer = manager.createOffer(item.trade_route);
          offer.addMyItems(items_to_send);
          offer.addTheirItem({"appid": 440, "contextid": 2, "assetid": item.currentID});
          offer.setMessage("Here's your trade");
          offer.send(function(err, status) {
          if (err) {
            console.log(err);
            return;
          }
          console.log(offer); //here's the one I posted above 
          if (status == 'pending') {
            console.log(`Offer #${offer.id} sent, but requires confirmation`);
            setTimeout( function(){
              community.acceptConfirmationForObject(key, offer.id, function(err) {
                if (err) {
                  console.log(err);
                } else {
                  console.log("Offer " + offer.id +" confirmed");
                }
              });
            }, 2000 );
          } else {
            console.log(`Offer #${offer.id} sent successfully`);
          }
        });

Here's the worng one (counter offer):

var offer = manager.createOffer(trade_url);
            manager.loadUserInventory(user_id, 440, 2, false, function (err, inventory, currencies) {
                if ('code for validating other things') {
                    offer.addMyItem(...);
                    offer.addTheirItems(items_to_send);
                    offer.setMessage("That was not the correct price. Here's what I wanted.");
                    offer.send(function (err, status) {
                        if (err) {
                            console.log(err);
                        }
                        if (status == 'pending') {
                            console.log(offer) // Here's the one I posted above
                            setTimeout(function () {
                                community.acceptConfirmationForObject(key, offer.id, function (err) {
                                    if (err) {
                                        console.log(err);
                                    } else {
                                        console.log("Offer " + offer.id + " confirmed");
                                    }
                                });
                            }, 4000);
                        } else {
                            console.log(`Offer #${offer.id} sent successfully`);
                        }
                    });
                } else {
                    console.log("Validation failed")
                    ... non related code
                }
                });
            });

Why the second one can't have the offer.id? Any kinf of help would be aprreciated :)

 

Note: I had to remove the non-related code and coments... sorry if you test it and fails.

Edited by Mr Game and Watch
Link to comment
Share on other sites

Ups, sorry about that. I deleted that line, but in my code there's a return there (I guess I deleted that line by mistake).

 

This is what happens in the second function (the "non-working" one): It loads the offer (with a null id in that moment), loads the items and set the message. Then, it sends correctly the offer. It checks if the status is "pending" (it is). But it goes to error, saying that it can't confirm an offer with null id.

 

I'm working with the solution Vanilla told, but... I wanted to know why that happened. It's just curious.

 

Thanks Dr. McKay :)

Link to comment
Share on other sites

Has this error happened to you before? I mean, get null info of your offers.

 

Nope, never happened to me.

If incoming trade offer didn't match with my "rules", my bot successfully counter the trade.

The code above is pretty much how I counter the incoming trade offer.

 

Oh by the way, I'm using newOffer event to get incomming trade offer.

Link to comment
Share on other sites

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...