Jump to content
McKay Development
PonyExpress

The bot goes offline while checking inventory

Recommended Posts

I have a function that runs on average about 2 minutes.

console.log(currentTime() + " START");
  community.getSteamUser...
    if (DATA.onlineState == "online"...
      let trade = manager.createOffer...
      manager.getUserInventoryContents...
        for (let i in BotSets.BaseSets) {.... }
        for (let i in BotSets.FoilSets) {.... }

// ----------------------------

        INV = INV.filter((ITEM) => ITEM.getTag("item_class").internal_name == "item_class_2");
console.log(currentTime() + " TEST, STEP 05-A");
        INV = INV.filter((ITEM) => ITEM.market_hash_name.indexOf("470480-Messenger") == -1);
        for (let i = 0; i < INV.length; i++) {
if (i == 5000) console.log(currentTime() + " TEST, ITEMS CHECKED: 5,000");
if (i == 40000) console.log(currentTime() + " TEST, ITEMS CHECKED: 40,000");
if (i == 50000) console.log(currentTime() + " TEST, ITEMS CHECKED: 50,000");
if (i == 60000) console.log(currentTime() + " TEST, ITEMS CHECKED: 60,000");
if (i == 70000) console.log(currentTime() + " TEST, ITEMS CHECKED: 70,000");
if (i == 80000) console.log(currentTime() + " TEST, ITEMS CHECKED: 80,000");
if (i == 90000) console.log(currentTime() + " TEST, ITEMS CHECKED: 90,000");
if (i == 100000) console.log(currentTime() + " TEST, ITEMS CHECKED: 100,000");
if (i == 110000) console.log(currentTime() + " TEST, ITEMS CHECKED: 110,000");
          if (amount < CONFIG.LIMITS.MAXTRANSFERCARDS && !idList.includes(INV[i].assetid)) {
            trade.addMyItem(INV[i]);
            amount++;
          } else if (amount == CONFIG.LIMITS.MAXTRANSFERCARDS && !idList.includes(INV[i].assetid)) {
            reachedLimit = true;
            break;
          }
        }
console.log(currentTime() + " TEST, STEP 05-B");

// ----------------------------

        trade.send((ERR) => { ....

In the end, I get:

23:24 START
23:25 TEST, STEP 05-A
23:25 TEST, ITEMS CHECKED: 5,000
23:25 TEST, ITEMS CHECKED: 40,000
23:26 TEST, ITEMS CHECKED: 50,000
23:26 TEST, ITEMS CHECKED: 60,000
23:26 TEST, ITEMS CHECKED: 70,000

// >> here I see that the bot goes offline

23:26 TEST, ITEMS CHECKED: 80,000
23:26 TEST, ITEMS CHECKED: 90,000
23:27 TEST, STEP 05-B
23:27 Error: HTTP error 401
23:27 client.steamID: null
23:27 (WAIT FOR RECONECT)
23:27 An error occurred while sending trade offer: Error: Not Logged In
23:27 (Login...)

Sometimes this function works, about 50/50%, but lately very often the bot goes offline before the trade offer is sent.

 

Are there any tips, how can I prevent the bot from shutting down while this function is running?

Share this post


Link to post
Share on other sites

So this is happening because JavaScript is single-threaded, and your loop is taking too long. While the loop is running, the rest of the code can't keep the connection to Steam alive and do other housekeeping tasks. You'll need to figure out a way to get the time that loop takes down, perhaps by limiting how many items it will process at a time, or perhaps by using setImmediate periodically so the rest of the event loop can get processed.

Share this post


Link to post
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...