Jump to content
McKay Development

Need some clarifications and advices


Recommended Posts

I'm almost done with my bot but I have a few questions

Which one would be the best and optimized way

A:

1. Store bot's inventory in a variable for the first time loading the bot
2. Every time a user request for cards sets stock, access stored inventory to minimize request to steam
3. This will also be true in creating trade-offers and adding bot's items
3. Only update variable with the latest inventory contents it after successfully done a trade

B:

1. For every request that needs to access bot's inventory, always fetch latest bot's data via getInventoryContents()
2. Will not do an update to the variable.

 

My first choice is A but my concern is,
this is a steam card bot(level up) with lot's of cards in inventory(up to 50000 at minimum)
when someone orders enough sets that it will take a few minutes for sentOfferChanged() to emit and between that time another user orders, since bot's inventory was cached, it will still use that inventory contents since sentOfferChanged() has not fired yet. What will happen to that trade assuming it was successfully sent by the bot?
Is using the option B more reliable? or even if using option B, fetching bot's inventory contents while an offer was sent and being accepted by the user, will receive a not updated inventory contents?

I encountered some card bots when i try to buy for 400+ sets(not less than 20000 cards, 5 is the least number of cards per set), eventhough I already accepted the trade, after waiting more than a 20 minutes, the trade has not gone thru and it becomes "trade offer cancelled" and sometimes "items unavailable".

Link to post
Share on other sites

I think the first method is better because you only get the inventory from steam when you know it was changed i.e through a trade offer. Second method could get tedious and take long for very large inventories. 

For your concern of the late sentOfferChanged emit, you could "reserve" those items for the user, so you don't offer them to another user. If the user doesn't accept the offer after a specific amount of time, you tell the user, cancel the offer and unlock those items to offer to somebody else. 

Link to post
Share on other sites

You could create a reserve.json file with this sort of structure:

{
    "items": [694868548, 798238548], // asset ids in here,
    "steamIDToItems": {
        "7656.......": [694868548], // the users asset ids you have reserved for them,
        "7656.......": [798238548]
    }
}

So when offering items you filter the inventory:

inventory.filter(item => !reserve.items.includes(item.assetid));

to get items that are not reserved.

And when you need to cancel because someone hasn't accepted the offer in a long time, you get the items you reserved for them from steamIDToItems and remove them as well as removing the IDs from the main items variable:

let itemsToRemove = reserve.steamIDToItems[steamID];

reserve.items = reserve.items.filter(item => !itemsToRemove.includes(item)); // remove those items with filter

delete reserve.steamIDToItems[steamID]; // delete the reserve items from the file

 

You may want to update the file using fs' writeFile/writeFileSync as these changes are occurring only in memory and will only reflect in the file once you write to the file. 

Edited by vrtgn
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...