From c7546194f8b688ea649d5b4a41bd68f3516995be Mon Sep 17 00:00:00 2001 From: Archi Date: Wed, 29 Nov 2023 19:17:02 +0100 Subject: [PATCH] Add handling of points shop items, and skip them for announcements --- .../RemoteCommunication.cs | 4 +-- ArchiSteamFarm/Steam/Data/Asset.cs | 7 +++++ .../Steam/Data/InventoryResponse.cs | 31 ++----------------- ArchiSteamFarm/Steam/Data/TradeOffer.cs | 2 +- ArchiSteamFarm/Steam/Exchange/Trading.cs | 2 +- 5 files changed, 14 insertions(+), 32 deletions(-) diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs index a6a18f5bf..65448b08b 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs @@ -284,7 +284,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { Dictionary<(uint RealAppID, Asset.EType Type, Asset.ERarity Rarity), bool> tradableSets = new(); foreach (Asset item in inventory) { - if (item is { AssetID: > 0, Amount: > 0, ClassID: > 0, RealAppID: > 0, Type: > Asset.EType.Unknown, Rarity: > Asset.ERarity.Unknown } && acceptedMatchableTypes.Contains(item.Type)) { + if (item is { AssetID: > 0, Amount: > 0, ClassID: > 0, RealAppID: > 0, Type: > Asset.EType.Unknown, Rarity: > Asset.ERarity.Unknown, IsSteamPointsShopItem: false } && acceptedMatchableTypes.Contains(item.Type)) { // Only tradable assets matter for MatchEverything bots if (!matchEverything || item.Tradable) { assetsForListing.Add(new AssetForListing(item, index, previousAssetID)); @@ -768,7 +768,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { Dictionary ourInventory; try { - ourInventory = await Bot.ArchiWebHandler.GetInventoryAsync().Where(item => item is { AssetID: > 0, Amount: > 0, ClassID: > 0, RealAppID: > 0, Type: > Asset.EType.Unknown, Rarity: > Asset.ERarity.Unknown } && acceptedMatchableTypes.Contains(item.Type) && !Bot.BotDatabase.MatchActivelyBlacklistAppIDs.Contains(item.RealAppID)).ToDictionaryAsync(static item => item.AssetID).ConfigureAwait(false); + ourInventory = await Bot.ArchiWebHandler.GetInventoryAsync().Where(item => item is { AssetID: > 0, Amount: > 0, ClassID: > 0, RealAppID: > 0, Type: > Asset.EType.Unknown, Rarity: > Asset.ERarity.Unknown, IsSteamPointsShopItem: false } && acceptedMatchableTypes.Contains(item.Type) && !Bot.BotDatabase.MatchActivelyBlacklistAppIDs.Contains(item.RealAppID)).ToDictionaryAsync(static item => item.AssetID).ConfigureAwait(false); } catch (HttpRequestException e) { Bot.ArchiLogger.LogGenericWarningException(e); Bot.ArchiLogger.LogGenericWarning(string.Format(CultureInfo.CurrentCulture, Strings.WarningFailedWithError, nameof(ourInventory))); diff --git a/ArchiSteamFarm/Steam/Data/Asset.cs b/ArchiSteamFarm/Steam/Data/Asset.cs index c84adcf74..8d7d49687 100644 --- a/ArchiSteamFarm/Steam/Data/Asset.cs +++ b/ArchiSteamFarm/Steam/Data/Asset.cs @@ -38,10 +38,17 @@ public sealed class Asset { [PublicAPI] public const ulong SteamCommunityContextID = 6; + [PublicAPI] + public const ulong SteamPointsShopInstanceID = 3865004543; + [JsonIgnore] [PublicAPI] public IReadOnlyDictionary? AdditionalPropertiesReadOnly => AdditionalProperties; + [JsonIgnore] + [PublicAPI] + public bool IsSteamPointsShopItem => !Tradable && (InstanceID == SteamPointsShopInstanceID); + [JsonIgnore] [PublicAPI] public uint Amount { get; internal set; } diff --git a/ArchiSteamFarm/Steam/Data/InventoryResponse.cs b/ArchiSteamFarm/Steam/Data/InventoryResponse.cs index 35d771637..1bb80a589 100644 --- a/ArchiSteamFarm/Steam/Data/InventoryResponse.cs +++ b/ArchiSteamFarm/Steam/Data/InventoryResponse.cs @@ -19,7 +19,6 @@ // See the License for the specific language governing permissions and // limitations under the License. -using System; using System.Collections.Generic; using System.Collections.Immutable; using System.Diagnostics.CodeAnalysis; @@ -118,33 +117,6 @@ internal sealed class InventoryResponse : OptionalResultResponse { } } - internal uint RealAppID { - get { - foreach (Tag tag in Tags) { - switch (tag.Identifier) { - case "Game": - if (string.IsNullOrEmpty(tag.Value) || (tag.Value.Length <= 4) || !tag.Value.StartsWith("app_", StringComparison.Ordinal)) { - ASF.ArchiLogger.LogGenericError(string.Format(CultureInfo.CurrentCulture, Strings.WarningUnknownValuePleaseReport, nameof(tag.Value), tag.Value)); - - break; - } - - string appIDText = tag.Value[4..]; - - if (!uint.TryParse(appIDText, out uint appID) || (appID == 0)) { - ASF.ArchiLogger.LogNullError(appID); - - break; - } - - return appID; - } - } - - return 0; - } - } - internal Asset.EType Type { get { Asset.EType type = Asset.EType.Unknown; @@ -225,6 +197,9 @@ internal sealed class InventoryResponse : OptionalResultResponse { internal ulong InstanceID { get; set; } internal bool Marketable { get; set; } + [JsonProperty("market_fee_app", Required = Required.Always)] + internal uint RealAppID { get; set; } + [JsonProperty("tags", Required = Required.DisallowNull)] internal ImmutableHashSet Tags { get; set; } = ImmutableHashSet.Empty; diff --git a/ArchiSteamFarm/Steam/Data/TradeOffer.cs b/ArchiSteamFarm/Steam/Data/TradeOffer.cs index 02717bd8b..aad448e46 100644 --- a/ArchiSteamFarm/Steam/Data/TradeOffer.cs +++ b/ArchiSteamFarm/Steam/Data/TradeOffer.cs @@ -68,6 +68,6 @@ public sealed class TradeOffer { throw new ArgumentNullException(nameof(acceptedTypes)); } - return ItemsToGive.All(item => item is { AppID: Asset.SteamAppID, ContextID: Asset.SteamCommunityContextID, AssetID: > 0, Amount: > 0, ClassID: > 0, RealAppID: > 0, Type: > Asset.EType.Unknown, Rarity: > Asset.ERarity.Unknown } && acceptedTypes.Contains(item.Type)); + return ItemsToGive.All(item => item is { AppID: Asset.SteamAppID, ContextID: Asset.SteamCommunityContextID, AssetID: > 0, Amount: > 0, ClassID: > 0, RealAppID: > 0 and not Asset.SteamAppID, Type: > Asset.EType.Unknown, Rarity: > Asset.ERarity.Unknown } && acceptedTypes.Contains(item.Type)); } } diff --git a/ArchiSteamFarm/Steam/Exchange/Trading.cs b/ArchiSteamFarm/Steam/Exchange/Trading.cs index 9b0f0defe..0ed251192 100644 --- a/ArchiSteamFarm/Steam/Exchange/Trading.cs +++ b/ArchiSteamFarm/Steam/Exchange/Trading.cs @@ -639,7 +639,7 @@ public sealed class Trading : IDisposable { HashSet inventory; try { - inventory = await Bot.ArchiWebHandler.GetInventoryAsync().Where(item => wantedSets.Contains((item.RealAppID, item.Type, item.Rarity))).ToHashSetAsync().ConfigureAwait(false); + inventory = await Bot.ArchiWebHandler.GetInventoryAsync().Where(item => !item.IsSteamPointsShopItem && wantedSets.Contains((item.RealAppID, item.Type, item.Rarity))).ToHashSetAsync().ConfigureAwait(false); } catch (HttpRequestException e) { // If we can't check our inventory when not using MatchEverything, this is a temporary failure, try again later Bot.ArchiLogger.LogGenericWarningException(e);