Add missing parsing of descriptions in active trade offers

@Vital7 you completely broke that part, since you've removed parsing of tags without adding any new logic for them, good thing R# started suggesting me to convert those 3 tags-generated properties to const :bite:
This commit is contained in:
JustArchi 2020-03-05 21:28:10 +01:00
parent 847c78b650
commit 0ed5092e97
3 changed files with 31 additions and 23 deletions

View file

@ -367,6 +367,6 @@ namespace ArchiSteamFarm.Tests {
}
[NotNull]
private static Steam.Asset CreateItem(ulong classID, ulong instanceID = 0, uint amount = 1, bool marketable = true, uint realAppID = Steam.Asset.SteamAppID, Steam.Asset.EType type = Steam.Asset.EType.TradingCard, Steam.Asset.ERarity rarity = Steam.Asset.ERarity.Common) => new Steam.Asset(Steam.Asset.SteamAppID, Steam.Asset.SteamCommunityContextID, classID, instanceID, amount, marketable, realAppID, type, rarity);
private static Steam.Asset CreateItem(ulong classID, ulong instanceID = 0, uint amount = 1, bool marketable = true, bool tradable = true, uint realAppID = Steam.Asset.SteamAppID, Steam.Asset.EType type = Steam.Asset.EType.TradingCard, Steam.Asset.ERarity rarity = Steam.Asset.ERarity.Common) => new Steam.Asset(Steam.Asset.SteamAppID, Steam.Asset.SteamCommunityContextID, classID, instanceID, amount, marketable, tradable, realAppID, type, rarity);
}
}

View file

@ -1464,7 +1464,7 @@ namespace ArchiSteamFarm {
return null;
}
Dictionary<(uint AppID, ulong ClassID, ulong InstanceID), (bool Marketable, uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity)> descriptions = new Dictionary<(uint AppID, ulong ClassID, ulong InstanceID), (bool Marketable, uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity)>();
Dictionary<(uint AppID, ulong ClassID, ulong InstanceID), Steam.InventoryResponse.Description> descriptions = new Dictionary<(uint AppID, ulong ClassID, ulong InstanceID), Steam.InventoryResponse.Description>();
foreach (KeyValue description in response["descriptions"].Children) {
uint appID = description["appid"].AsUnsignedInteger();
@ -1491,11 +1491,13 @@ namespace ArchiSteamFarm {
continue;
}
bool marketable = description["marketable"].AsBoolean();
Steam.Asset.EType type = Steam.Asset.EType.Unknown;
Steam.Asset.ERarity rarity = Steam.Asset.ERarity.Unknown;
uint realAppID = 0;
Steam.InventoryResponse.Description parsedDescription = new Steam.InventoryResponse.Description {
AppID = appID,
ClassID = classID,
InstanceID = instanceID,
Marketable = description["marketable"].AsBoolean(),
Tradable = true // We're parsing active trade offers, we can assume as much
};
List<KeyValue> tags = description["tags"].Children;
@ -1521,9 +1523,11 @@ namespace ArchiSteamFarm {
parsedTags.Add(new Steam.InventoryResponse.Description.Tag(identifier, value));
}
parsedDescription.Tags = parsedTags.ToImmutableHashSet();
}
descriptions[key] = (marketable, realAppID, type, rarity);
descriptions[key] = parsedDescription;
}
HashSet<Steam.TradeOffer> result = new HashSet<Steam.TradeOffer>();
@ -2437,7 +2441,7 @@ namespace ArchiSteamFarm {
return uri.AbsolutePath.StartsWith("/login", StringComparison.Ordinal) || uri.Host.Equals("lostauth");
}
private static bool ParseItems(IReadOnlyDictionary<(uint AppID, ulong ClassID, ulong InstanceID), (bool Marketable, uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity)> descriptions, IReadOnlyCollection<KeyValue> input, ICollection<Steam.Asset> output) {
private static bool ParseItems(IReadOnlyDictionary<(uint AppID, ulong ClassID, ulong InstanceID), Steam.InventoryResponse.Description> descriptions, IReadOnlyCollection<KeyValue> input, ICollection<Steam.Asset> output) {
if ((descriptions == null) || (input == null) || (input.Count == 0) || (output == null)) {
ASF.ArchiLogger.LogNullError(nameof(descriptions) + " || " + nameof(input) + " || " + nameof(output));
@ -2482,18 +2486,20 @@ namespace ArchiSteamFarm {
}
bool marketable = true;
bool tradable = true;
uint realAppID = 0;
Steam.Asset.EType type = Steam.Asset.EType.Unknown;
Steam.Asset.ERarity rarity = Steam.Asset.ERarity.Unknown;
if (descriptions.TryGetValue(key, out (bool Marketable, uint RealAppID, Steam.Asset.EType Type, Steam.Asset.ERarity Rarity) description)) {
if (descriptions.TryGetValue(key, out Steam.InventoryResponse.Description description)) {
marketable = description.Marketable;
tradable = description.Tradable;
realAppID = description.RealAppID;
type = description.Type;
rarity = description.Rarity;
}
Steam.Asset steamAsset = new Steam.Asset(appID, contextID, classID, instanceID, amount, marketable, realAppID, type, rarity);
Steam.Asset steamAsset = new Steam.Asset(appID, contextID, classID, instanceID, amount, marketable, tradable, realAppID, type, rarity);
output.Add(steamAsset);
}

View file

@ -198,7 +198,7 @@ namespace ArchiSteamFarm.Json {
#pragma warning restore IDE0051
// Constructed from trades being received or plugins
public Asset(uint appID, ulong contextID, ulong classID, ulong instanceID, uint amount, bool marketable = true, uint realAppID = 0, EType type = EType.Unknown, ERarity rarity = ERarity.Unknown) {
public Asset(uint appID, ulong contextID, ulong classID, ulong instanceID, uint amount, bool marketable = true, bool tradable = true, uint realAppID = 0, EType type = EType.Unknown, ERarity rarity = ERarity.Unknown) {
if ((appID == 0) || (contextID == 0) || (classID == 0) || (amount == 0)) {
throw new ArgumentNullException(nameof(appID) + " || " + nameof(contextID) + " || " + nameof(classID) + " || " + nameof(amount));
}
@ -209,6 +209,7 @@ namespace ArchiSteamFarm.Json {
InstanceID = instanceID;
Amount = amount;
Marketable = marketable;
Tradable = tradable;
RealAppID = realAppID;
Type = type;
Rarity = rarity;
@ -485,12 +486,6 @@ namespace ArchiSteamFarm.Json {
internal readonly ImmutableDictionary<string, JToken> AdditionalProperties;
#pragma warning restore 649
[JsonProperty(PropertyName = "appid", Required = Required.Always)]
internal readonly uint AppID;
[JsonProperty(PropertyName = "tags", Required = Required.DisallowNull)]
internal readonly ImmutableHashSet<Tag> Tags;
internal Asset.ERarity Rarity {
get {
foreach (Tag tag in Tags) {
@ -606,10 +601,17 @@ namespace ArchiSteamFarm.Json {
}
}
internal ulong ClassID { get; private set; }
internal ulong InstanceID { get; private set; }
internal bool Marketable { get; private set; }
internal bool Tradable { get; private set; }
[JsonProperty(PropertyName = "appid", Required = Required.Always)]
internal uint AppID { get; set; }
internal ulong ClassID { get; set; }
internal ulong InstanceID { get; set; }
internal bool Marketable { get; set; }
[JsonProperty(PropertyName = "tags", Required = Required.DisallowNull)]
internal ImmutableHashSet<Tag> Tags { get; set; }
internal bool Tradable { get; set; }
#pragma warning disable IDE0051
[JsonProperty(PropertyName = "classid", Required = Required.Always)]
@ -666,7 +668,7 @@ namespace ArchiSteamFarm.Json {
#pragma warning restore IDE0051
[JsonConstructor]
private Description() { }
internal Description() { }
internal sealed class Tag {
[JsonProperty(PropertyName = "category", Required = Required.Always)]