waylaidwanderer / SteamTradeOffersBot

SteamBot fork that provides an easy-to-use Trade Offer library and a true generic inventory interface.
MIT License
48 stars 17 forks source link

Update inventory code to use new endpoint #23

Closed Zexuz closed 7 years ago

Zexuz commented 7 years ago

Since the API for fetching CSGO items has been removed, I removed it and updated the other API (I was told that that was also an old one) with the new one.

This is a draft of what I came up with tonight. ATM there are missing some "descriptions" attributes and I don't know how to fetch the float value.

Don't know if this is something that you might be interesting in. But here it is.

Usage:


  var inventory = NewGenercInventoy.GetInventory(bot.SteamClient.SteamID,bot.SteamWeb,440);
   if(!inventory.IsGood){
       //handel error 
}
// inventory.items array of appId 440 (TF2) items 
waylaidwanderer commented 7 years ago

I'd rather you replace the old GenericInventory class instead, but use it as a base-line for implementation/code-style.

Zexuz commented 7 years ago

So replace the old inventory class with my new one and tighty up the code?

This will mean that all FetchInventory (http://api.steampowered.com/IEconItems_<appid>/GetPlayerItems/) will get removed and that

Inventory GetInventory will be the only way to fetch inventories?

Zexuz commented 7 years ago

Facepalm... I don't know what I was doing last night. I now see that you have a class named GenericInventory and that I was looking at the wrong Inventory.

I will fix this PR ASAP.

waylaidwanderer commented 7 years ago

I now see that you have a class named GenericInventory and that I was looking at the wrong Inventory.

That's correct. I meant you should update this class to use the new endpoint for your pull request.

Zexuz commented 7 years ago

The GenericInventory.cs now uses the new api for fetching players inventories.

Most of the things is the same. Some of the changes are

Usage example

var bot = StartAndConfigBot();

var inventory = new GenericInventory(new SteamID(steamid), bot.SteamWeb, new Dictionary<int, int>
{
    {730, 2},
    {(int) GenericInventory.AppId.PUBG, (int) GenericInventory.ContextId.PUBG},
}, true);

inventory.InventoriesLoaded += (sender, args1) =>
{
    var inv = sender as GenericInventory;
    Console.WriteLine($"success : {inv.Success}");
    Console.WriteLine($"Inventories loaded: {string.Join(",",inv.Inventories.Keys)}"); // prints: Inventories loaded: 578080,730
};

var csInv = inventory.Inventories[730][2];

I also believe that AddForeignInventory and FetchForeignInventory should be removed and if you want to fetch another persons inventory, create a new GenericInventory instance.

waylaidwanderer commented 7 years ago

Pull request looks great. Left some code review comments if you wanna take a look.

Zexuz commented 7 years ago

How/where can I see these "comments"? Never used this feature before.

waylaidwanderer commented 7 years ago

You'll probably have to visit the desktop version of GitHub website. It's in-line with all these comments here on this pull request.

Zexuz commented 7 years ago

In your inventory. (look at this link http://steamcommunity.com/inventory/76561198045552709/570/2?l=english&count=5000 in browser)

you have two items with "classid":"848466467","instanceid":"1507031039", diffrent AssetId but same classId and instanceid. Is this a bug on steams end? I was told that instaceid + classid was unique.

this code breaks beacuse of it

 public ItemDescription GetItemDescription(Item item)
            {
                if (item == null) return null;

                return Descriptions.SingleOrDefault(itemDesc =>
                    itemDesc.AppId.ToString() == item.Appid &&
                    itemDesc.ClassId.ToString() == item.ClassId &&
                    itemDesc.InstanceId.ToString() == item.InstanceId
                );
            }

since they refer to the same ItemDescription i will change the SingelOrDefault to FirstOrDefault.

That said, this seams like a bug to me.

waylaidwanderer commented 7 years ago

Only assetid is unique.

Zexuz commented 7 years ago

Okej, well. The new code will fix that also. Since both Assets are referring to the same ItemDescription.

If there is no more problems, this should be good to be merged in.

waylaidwanderer commented 7 years ago

@Zexuz there is one way you can implement tradableOnly - the items descriptions have a tradable property. You could perhaps filter out anything with tradable: 0 if tradableOnly is set to true?

Zexuz commented 7 years ago

Yes, but then we already have made the HTTP call. My plan was to save time and space in the HTTP call. Now the end user can filter those out by them self. Kinda how then need to pair Item with ItemDescription. All they have to do is inv.Item.where(item => item.tradeableOnly == true). Just my 2 cents

waylaidwanderer commented 7 years ago

Yeah I mean it's not really a big deal, just a "nice-to-have" kind of thing.

Zexuz commented 7 years ago

Okey, I hear you. I might do it in the feature, but then I will create a new PR and implement some other nice things.

waylaidwanderer commented 7 years ago

Thanks, merged.