From 40ab1d848c1c1eb3ad3e0d8057ac01b35890922c Mon Sep 17 00:00:00 2001 From: Archi Date: Mon, 11 Dec 2023 23:55:13 +0100 Subject: [PATCH] .NET 8 code enhancements --- .editorconfig | 19 +- .../BotCache.cs | 2 +- .../Commands.cs | 2 +- .../RemoteCommunication.cs | 20 +- .../Commands.cs | 6 +- .../SteamTokenDumperPlugin.cs | 4 +- ArchiSteamFarm.Tests/Bot.cs | 78 +++---- ArchiSteamFarm.Tests/SteamChatMessage.cs | 108 ++++----- ArchiSteamFarm.Tests/Trading.cs | 220 +++++++++--------- ArchiSteamFarm.sln.DotSettings | 4 +- .../Collections/ConcurrentHashSet.cs | 2 +- ArchiSteamFarm/Collections/ConcurrentList.cs | 2 +- ArchiSteamFarm/Core/Utilities.cs | 2 +- .../SwaggerValidValuesAttribute.cs | 2 +- ...actorAuthenticationConfirmationsRequest.cs | 2 +- ArchiSteamFarm/NLog/Logging.cs | 2 +- ArchiSteamFarm/Plugins/PluginsCore.cs | 4 +- ArchiSteamFarm/Steam/Bot.cs | 14 +- ArchiSteamFarm/Steam/Cards/CardsFarmer.cs | 10 +- ArchiSteamFarm/Steam/Data/TradeOffer.cs | 4 +- .../Steam/Data/TradeOfferSendRequest.cs | 2 +- ArchiSteamFarm/Steam/Exchange/Trading.cs | 6 +- .../Steam/Integration/ArchiWebHandler.cs | 16 +- ArchiSteamFarm/Steam/Interaction/Actions.cs | 2 +- ArchiSteamFarm/Steam/Interaction/Commands.cs | 106 ++++----- .../SteamKit2/InMemoryServerListProvider.cs | 2 +- ArchiSteamFarm/Steam/Storage/BotDatabase.cs | 10 +- ArchiSteamFarm/Storage/GenericDatabase.cs | 3 +- ArchiSteamFarm/Storage/GlobalDatabase.cs | 4 +- ArchiSteamFarm/Web/GitHub.cs | 2 +- 30 files changed, 333 insertions(+), 327 deletions(-) diff --git a/.editorconfig b/.editorconfig index 50d8eec8d..bd312014d 100644 --- a/.editorconfig +++ b/.editorconfig @@ -36,7 +36,7 @@ csharp_prefer_simple_default_expression = true:warning csharp_prefer_simple_using_statement = true:warning csharp_prefer_static_local_function = true:warning -csharp_preferred_modifier_order = public, protected, internal, private, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, volatile, async:warning +csharp_preferred_modifier_order = public, protected, internal, private, file, static, extern, new, virtual, abstract, sealed, override, readonly, unsafe, required, volatile, async:warning csharp_preserve_single_line_blocks = true csharp_preserve_single_line_statements = false @@ -79,15 +79,27 @@ csharp_style_expression_bodied_properties = true:warning csharp_style_implicit_object_creation_when_type_is_apparent = true:warning csharp_style_inlined_variable_declaration = true:warning -csharp_style_pattern_local_over_anonymous_function = true:warning +csharp_style_namespace_declarations = file_scoped:warning + csharp_style_pattern_matching_over_as_with_null_check = true:warning csharp_style_pattern_matching_over_is_with_cast_check = true:warning +csharp_style_prefer_extended_property_pattern = true:warning +dotnet_style_prefer_foreach_explicit_cast_in_source = always:warning csharp_style_prefer_index_operator = true:warning +csharp_style_prefer_local_over_anonymous_function = true:warning +csharp_style_prefer_method_group_conversion = true:warning csharp_style_prefer_not_pattern = true:warning +csharp_style_prefer_null_check_over_type_check = true:warning csharp_style_prefer_pattern_matching = true:warning +csharp_style_prefer_primary_constructors = true:warning csharp_style_prefer_range_operator = true:warning +csharp_style_prefer_readonly_struct = true:warning +csharp_style_prefer_readonly_struct_member = true:warning csharp_style_prefer_switch_expression = true:warning +csharp_style_prefer_top_level_statements = false:warning +csharp_style_prefer_tuple_swap = true:warning +csharp_style_prefer_utf8_string_literals = true:warning csharp_style_throw_expression = true:warning @@ -98,7 +110,7 @@ csharp_style_var_elsewhere = false:warning csharp_style_var_for_built_in_types = false:warning csharp_style_var_when_type_is_apparent = false:warning -csharp_using_directive_placement = outside_namespace +csharp_using_directive_placement = outside_namespace:warning ############################### # .NET Coding Conventions # @@ -186,6 +198,7 @@ dotnet_sort_system_directives_first = true dotnet_style_coalesce_expression = true:warning dotnet_style_collection_initializer = true:warning dotnet_style_explicit_tuple_names = true:warning +dotnet_style_namespace_match_folder = true:warning dotnet_style_null_propagation = true:warning dotnet_style_object_initializer = true:warning diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/BotCache.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/BotCache.cs index f29c633fb..c92447236 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/BotCache.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/BotCache.cs @@ -35,7 +35,7 @@ namespace ArchiSteamFarm.OfficialPlugins.ItemsMatcher; internal sealed class BotCache : SerializableFile { [JsonProperty(Required = Required.DisallowNull)] - internal readonly ConcurrentList LastAnnouncedAssetsForListing = new(); + internal readonly ConcurrentList LastAnnouncedAssetsForListing = []; internal string? LastAnnouncedTradeToken { get => BackingLastAnnouncedTradeToken; diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Commands.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Commands.cs index 1c8e99682..8807684b4 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Commands.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/Commands.cs @@ -112,7 +112,7 @@ internal static class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => ResponseMatch(Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID), bot)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } diff --git a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs index fc3ec17f5..42feb3bcb 100644 --- a/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs +++ b/ArchiSteamFarm.OfficialPlugins.ItemsMatcher/RemoteCommunication.cs @@ -278,7 +278,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { uint index = 0; ulong previousAssetID = 0; - List assetsForListing = new(); + List assetsForListing = []; Dictionary<(uint RealAppID, Asset.EType Type, Asset.ERarity Rarity), bool> tradableSets = new(); @@ -372,7 +372,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { if (!matchEverything) { // We should deduplicate our sets before sending them to the server, for doing that we'll use ASFB set parts data - HashSet realAppIDs = new(); + HashSet realAppIDs = []; Dictionary<(uint RealAppID, Asset.EType Type, Asset.ERarity Rarity), Dictionary> state = new(); foreach (AssetForListing asset in assetsForListing) { @@ -446,7 +446,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { Dictionary<(uint RealAppID, Asset.EType Type, Asset.ERarity Rarity), HashSet> databaseSets = setPartsResponse.Content.Result.GroupBy(static setPart => (setPart.RealAppID, setPart.Type, setPart.Rarity)).ToDictionary(static group => group.Key, static group => group.Select(static setPart => setPart.ClassID).ToHashSet()); - HashSet<(ulong ClassID, uint Amount)> setCopy = new(); + HashSet<(ulong ClassID, uint Amount)> setCopy = []; foreach (((uint RealAppID, Asset.EType Type, Asset.ERarity Rarity) key, Dictionary set) in state) { if (!databaseSets.TryGetValue(key, out HashSet? databaseSet)) { @@ -483,7 +483,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { } } - HashSet assetsForListingFiltered = new(); + HashSet assetsForListingFiltered = []; foreach (AssetForListing asset in assetsForListing.Where(asset => state.TryGetValue((asset.RealAppID, asset.Type, asset.Rarity), out Dictionary? setState) && setState.TryGetValue(asset.ClassID, out uint targetAmount) && (targetAmount > 0)).OrderByDescending(static asset => asset.Tradable).ThenByDescending(static asset => asset.Index)) { (uint RealAppID, Asset.EType Type, Asset.ERarity Rarity) key = (asset.RealAppID, asset.Type, asset.Rarity); @@ -1031,16 +1031,16 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { } } - matchActivelyTradeOfferIDs ??= new HashSet(); + matchActivelyTradeOfferIDs ??= []; - HashSet deprioritizedSteamIDs = new(); + HashSet deprioritizedSteamIDs = []; if (matchActivelyTradeOfferIDs.Count > 0) { // This is not a mandatory step, we allow it to fail HashSet? sentTradeOffers = await Bot.ArchiWebHandler.GetTradeOffers(true, false, true, false).ConfigureAwait(false); if (sentTradeOffers != null) { - HashSet activeTradeOfferIDs = new(); + HashSet activeTradeOfferIDs = []; foreach (TradeOffer tradeOffer in sentTradeOffers.Where(tradeOffer => (tradeOffer.State == ETradeOfferState.Active) && matchActivelyTradeOfferIDs.Contains(tradeOffer.TradeOfferID))) { deprioritizedSteamIDs.Add(tradeOffer.OtherSteamID64); @@ -1062,7 +1062,7 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { } } - HashSet pendingMobileTradeOfferIDs = new(); + HashSet pendingMobileTradeOfferIDs = []; byte maxTradeHoldDuration = ASF.GlobalConfig?.MaxTradeHoldDuration ?? GlobalConfig.DefaultMaxTradeHoldDuration; @@ -1109,13 +1109,13 @@ internal sealed class RemoteCommunication : IAsyncDisposable, IDisposable { continue; } - HashSet<(uint RealAppID, Asset.EType Type, Asset.ERarity Rarity)> skippedSetsThisUser = new(); + HashSet<(uint RealAppID, Asset.EType Type, Asset.ERarity Rarity)> skippedSetsThisUser = []; Dictionary<(uint RealAppID, Asset.EType Type, Asset.ERarity Rarity), Dictionary> theirTradableState = Trading.GetTradableInventoryState(theirInventory); for (byte i = 0; i < Trading.MaxTradesPerAccount; i++) { byte itemsInTrade = 0; - HashSet<(uint RealAppID, Asset.EType Type, Asset.ERarity Rarity)> skippedSetsThisTrade = new(); + HashSet<(uint RealAppID, Asset.EType Type, Asset.ERarity Rarity)> skippedSetsThisTrade = []; Dictionary classIDsToGive = new(); Dictionary classIDsToReceive = new(); diff --git a/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/Commands.cs b/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/Commands.cs index 97d22c305..ae84ca130 100644 --- a/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/Commands.cs +++ b/ArchiSteamFarm.OfficialPlugins.MobileAuthenticator/Commands.cs @@ -220,7 +220,7 @@ internal static class Commands { IList results = await Utilities.InParallel(bots.Select(bot => ResponseTwoFactorFinalize(Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID), bot, activationCode))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -313,7 +313,7 @@ internal static class Commands { IList results = await Utilities.InParallel(bots.Select(bot => ResponseTwoFactorFinalized(Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID), bot, activationCode))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -392,7 +392,7 @@ internal static class Commands { IList results = await Utilities.InParallel(bots.Select(bot => ResponseTwoFactorInit(Steam.Interaction.Commands.GetProxyAccess(bot, access, steamID), bot))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } diff --git a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs index 1535db3ee..13a2abc94 100644 --- a/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs +++ b/ArchiSteamFarm.OfficialPlugins.SteamTokenDumper/SteamTokenDumperPlugin.cs @@ -324,7 +324,7 @@ internal sealed class SteamTokenDumperPlugin : OfficialPlugin, IASF, IBot, IBotC packageIDs ??= bot.OwnedPackageIDs.Where(static package => (Config?.SecretPackageIDs.Contains(package.Key) != true) && ((package.Value.PaymentMethod != EPaymentMethod.AutoGrant) || (Config?.SkipAutoGrantPackages == false))).Select(static package => package.Key).ToHashSet(); - HashSet appIDsToRefresh = new(); + HashSet appIDsToRefresh = []; foreach (uint packageID in packageIDs.Where(static packageID => Config?.SecretPackageIDs.Contains(packageID) != true)) { if (!ASF.GlobalDatabase.PackagesDataReadOnly.TryGetValue(packageID, out PackageData? packageData) || (packageData.AppIDs == null)) { @@ -576,7 +576,7 @@ internal sealed class SteamTokenDumperPlugin : OfficialPlugin, IASF, IBot, IBotC Utilities.InBackground(static () => SubmitData()); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } diff --git a/ArchiSteamFarm.Tests/Bot.cs b/ArchiSteamFarm.Tests/Bot.cs index 07b48e837..7ddf02745 100644 --- a/ArchiSteamFarm.Tests/Bot.cs +++ b/ArchiSteamFarm.Tests/Bot.cs @@ -39,7 +39,7 @@ public sealed class Bot { { 43, MinCardsPerBadge + 1 } }; - HashSet items = new(); + HashSet items = []; foreach ((uint appID, byte cards) in itemsPerSet) { for (byte i = 1; i <= cards; i++) { @@ -59,10 +59,10 @@ public sealed class Bot { public void MaxItemsTooSmall() { const uint appID = 42; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID), CreateCard(2, appID) - }; + ]; GetItemsForFullBadge(items, 2, appID, MinCardsPerBadge - 1); @@ -73,12 +73,12 @@ public sealed class Bot { public void MoreCardsThanNeeded() { const uint appID = 42; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID), CreateCard(1, appID), CreateCard(2, appID), CreateCard(3, appID) - }; + ]; HashSet itemsToSend = GetItemsForFullBadge(items, 3, appID); @@ -95,12 +95,12 @@ public sealed class Bot { public void MultipleSets() { const uint appID = 42; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID), CreateCard(1, appID), CreateCard(2, appID), CreateCard(2, appID) - }; + ]; HashSet itemsToSend = GetItemsForFullBadge(items, 2, appID); @@ -116,11 +116,11 @@ public sealed class Bot { public void MultipleSetsDifferentAmount() { const uint appID = 42; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID, 2), CreateCard(2, appID), CreateCard(2, appID) - }; + ]; HashSet itemsToSend = GetItemsForFullBadge(items, 2, appID); @@ -136,7 +136,7 @@ public sealed class Bot { public void MutliRarityAndType() { const uint appID = 42; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID, type: Asset.EType.TradingCard, rarity: Asset.ERarity.Common), CreateCard(2, appID, type: Asset.EType.TradingCard, rarity: Asset.ERarity.Common), @@ -158,7 +158,7 @@ public sealed class Bot { CreateCard(2, appID, type: Asset.EType.Unknown, rarity: Asset.ERarity.Rare), CreateCard(3, appID, type: Asset.EType.Unknown, rarity: Asset.ERarity.Rare), CreateCard(4, appID, type: Asset.EType.Unknown, rarity: Asset.ERarity.Rare) - }; + ]; HashSet itemsToSend = GetItemsForFullBadge(items, 3, appID); @@ -177,10 +177,10 @@ public sealed class Bot { public void NotAllCardsPresent() { const uint appID = 42; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID), CreateCard(2, appID) - }; + ]; HashSet itemsToSend = GetItemsForFullBadge(items, 3, appID); @@ -192,10 +192,10 @@ public sealed class Bot { public void OneSet() { const uint appID = 42; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID), CreateCard(2, appID) - }; + ]; HashSet itemsToSend = GetItemsForFullBadge(items, 2, appID); @@ -212,10 +212,10 @@ public sealed class Bot { const uint appID0 = 42; const uint appID1 = 43; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID0), CreateCard(1, appID1) - }; + ]; HashSet itemsToSend = GetItemsForFullBadge( items, new Dictionary { @@ -237,10 +237,10 @@ public sealed class Bot { const uint appID0 = 42; const uint appID1 = 43; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID0), CreateCard(1, appID1) - }; + ]; HashSet itemsToSend = GetItemsForFullBadge( items, new Dictionary { @@ -260,14 +260,14 @@ public sealed class Bot { const uint appID1 = 43; const uint appID2 = 44; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID0), CreateCard(2, appID0), CreateCard(1, appID1), CreateCard(2, appID1), CreateCard(3, appID1) - }; + ]; HashSet itemsToSend = GetItemsForFullBadge( items, new Dictionary { @@ -290,10 +290,10 @@ public sealed class Bot { public void OtherRarityFullSets() { const uint appID = 42; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID, rarity: Asset.ERarity.Common), CreateCard(1, appID, rarity: Asset.ERarity.Rare) - }; + ]; HashSet itemsToSend = GetItemsForFullBadge(items, 1, appID); @@ -308,10 +308,10 @@ public sealed class Bot { public void OtherRarityNoSets() { const uint appID = 42; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID, rarity: Asset.ERarity.Common), CreateCard(1, appID, rarity: Asset.ERarity.Rare) - }; + ]; HashSet itemsToSend = GetItemsForFullBadge(items, 2, appID); @@ -324,13 +324,13 @@ public sealed class Bot { public void OtherRarityOneSet() { const uint appID = 42; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID, rarity: Asset.ERarity.Common), CreateCard(2, appID, rarity: Asset.ERarity.Common), CreateCard(1, appID, rarity: Asset.ERarity.Uncommon), CreateCard(2, appID, rarity: Asset.ERarity.Uncommon), CreateCard(3, appID, rarity: Asset.ERarity.Uncommon) - }; + ]; HashSet itemsToSend = GetItemsForFullBadge(items, 3, appID); @@ -347,10 +347,10 @@ public sealed class Bot { public void OtherTypeFullSets() { const uint appID = 42; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID, type: Asset.EType.TradingCard), CreateCard(1, appID, type: Asset.EType.FoilTradingCard) - }; + ]; HashSet itemsToSend = GetItemsForFullBadge(items, 1, appID); @@ -365,10 +365,10 @@ public sealed class Bot { public void OtherTypeNoSets() { const uint appID = 42; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID, type: Asset.EType.TradingCard), CreateCard(1, appID, type: Asset.EType.FoilTradingCard) - }; + ]; HashSet itemsToSend = GetItemsForFullBadge(items, 2, appID); @@ -381,13 +381,13 @@ public sealed class Bot { public void OtherTypeOneSet() { const uint appID = 42; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID, type: Asset.EType.TradingCard), CreateCard(2, appID, type: Asset.EType.TradingCard), CreateCard(1, appID, type: Asset.EType.FoilTradingCard), CreateCard(2, appID, type: Asset.EType.FoilTradingCard), CreateCard(3, appID, type: Asset.EType.FoilTradingCard) - }; + ]; HashSet itemsToSend = GetItemsForFullBadge(items, 3, appID); @@ -404,10 +404,10 @@ public sealed class Bot { public void TooHighAmount() { const uint appID0 = 42; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID0, 2), CreateCard(2, appID0) - }; + ]; HashSet itemsToSend = GetItemsForFullBadge(items, 2, appID0); @@ -423,7 +423,7 @@ public sealed class Bot { public void TooManyCardsForSingleTrade() { const uint appID = 42; - HashSet items = new(); + HashSet items = []; for (byte i = 0; i < Steam.Exchange.Trading.MaxItemsPerTrade; i++) { items.Add(CreateCard(1, appID)); @@ -440,7 +440,7 @@ public sealed class Bot { const uint appID0 = 42; const uint appID1 = 43; - HashSet items = new(); + HashSet items = []; for (byte i = 0; i < 100; i++) { items.Add(CreateCard(1, appID0)); @@ -466,12 +466,12 @@ public sealed class Bot { const uint appID1 = 43; const uint appID2 = 44; - HashSet items = new() { + HashSet items = [ CreateCard(1, appID0), CreateCard(2, appID0), CreateCard(3, appID0), CreateCard(4, appID0) - }; + ]; GetItemsForFullBadge( items, new Dictionary { diff --git a/ArchiSteamFarm.Tests/SteamChatMessage.cs b/ArchiSteamFarm.Tests/SteamChatMessage.cs index a86bb7692..2ee4d3617 100644 --- a/ArchiSteamFarm.Tests/SteamChatMessage.cs +++ b/ArchiSteamFarm.Tests/SteamChatMessage.cs @@ -200,60 +200,62 @@ public sealed class SteamChatMessage { public async Task RyzhehvostInitialTestForSplitting() { const string prefix = "/me "; - const string message = @" Уже имеет: app/1493800 | Aircraft Carrier Survival: Prolouge - Уже имеет: app/349520 | Armillo - Уже имеет: app/346330 | BrainBread 2 - Уже имеет: app/1086690 | C-War 2 - Уже имеет: app/730 | Counter-Strike: Global Offensive - Уже имеет: app/838380 | DEAD OR ALIVE 6 - Уже имеет: app/582890 | Estranged: The Departure - Уже имеет: app/331470 | Everlasting Summer - Уже имеет: app/1078000 | Gamecraft - Уже имеет: app/266310 | GameGuru - Уже имеет: app/275390 | Guacamelee! Super Turbo Championship Edition - Уже имеет: app/627690 | Idle Champions of the Forgotten Realms - Уже имеет: app/1048540 | Kao the Kangaroo: Round 2 - Уже имеет: app/370910 | Kathy Rain - Уже имеет: app/343710 | KHOLAT - Уже имеет: app/253900 | Knights and Merchants - Уже имеет: app/224260 | No More Room in Hell - Уже имеет: app/343360 | Particula - Уже имеет: app/237870 | Planet Explorers - Уже имеет: app/684680 | Polygoneer - Уже имеет: app/1089130 | Quake II RTX - Уже имеет: app/755790 | Ring of Elysium - Уже имеет: app/1258080 | Shop Titans - Уже имеет: app/759530 | Struckd - 3D Game Creator - Уже имеет: app/269710 | Tumblestone - Уже имеет: app/304930 | Unturned - Уже имеет: app/1019250 | WWII TCG - World War 2: The Card Game + const string message = """ + Уже имеет: app/1493800 | Aircraft Carrier Survival: Prolouge + Уже имеет: app/349520 | Armillo + Уже имеет: app/346330 | BrainBread 2 + Уже имеет: app/1086690 | C-War 2 + Уже имеет: app/730 | Counter-Strike: Global Offensive + Уже имеет: app/838380 | DEAD OR ALIVE 6 + Уже имеет: app/582890 | Estranged: The Departure + Уже имеет: app/331470 | Everlasting Summer + Уже имеет: app/1078000 | Gamecraft + Уже имеет: app/266310 | GameGuru + Уже имеет: app/275390 | Guacamelee! Super Turbo Championship Edition + Уже имеет: app/627690 | Idle Champions of the Forgotten Realms + Уже имеет: app/1048540 | Kao the Kangaroo: Round 2 + Уже имеет: app/370910 | Kathy Rain + Уже имеет: app/343710 | KHOLAT + Уже имеет: app/253900 | Knights and Merchants + Уже имеет: app/224260 | No More Room in Hell + Уже имеет: app/343360 | Particula + Уже имеет: app/237870 | Planet Explorers + Уже имеет: app/684680 | Polygoneer + Уже имеет: app/1089130 | Quake II RTX + Уже имеет: app/755790 | Ring of Elysium + Уже имеет: app/1258080 | Shop Titans + Уже имеет: app/759530 | Struckd - 3D Game Creator + Уже имеет: app/269710 | Tumblestone + Уже имеет: app/304930 | Unturned + Уже имеет: app/1019250 | WWII TCG - World War 2: The Card Game - 1/1 ботов уже имеют игру app/1493800 | Aircraft Carrier Survival: Prolouge. - 1/1 ботов уже имеют игру app/349520 | Armillo. - 1/1 ботов уже имеют игру app/346330 | BrainBread 2. - 1/1 ботов уже имеют игру app/1086690 | C-War 2. - 1/1 ботов уже имеют игру app/730 | Counter-Strike: Global Offensive. - 1/1 ботов уже имеют игру app/838380 | DEAD OR ALIVE 6. - 1/1 ботов уже имеют игру app/582890 | Estranged: The Departure. - 1/1 ботов уже имеют игру app/331470 | Everlasting Summer. - 1/1 ботов уже имеют игру app/1078000 | Gamecraft. - 1/1 ботов уже имеют игру app/266310 | GameGuru. - 1/1 ботов уже имеют игру app/275390 | Guacamelee! Super Turbo Championship Edition. - 1/1 ботов уже имеют игру app/627690 | Idle Champions of the Forgotten Realms. - 1/1 ботов уже имеют игру app/1048540 | Kao the Kangaroo: Round 2. - 1/1 ботов уже имеют игру app/370910 | Kathy Rain. - 1/1 ботов уже имеют игру app/343710 | KHOLAT. - 1/1 ботов уже имеют игру app/253900 | Knights and Merchants. - 1/1 ботов уже имеют игру app/224260 | No More Room in Hell. - 1/1 ботов уже имеют игру app/343360 | Particula. - 1/1 ботов уже имеют игру app/237870 | Planet Explorers. - 1/1 ботов уже имеют игру app/684680 | Polygoneer. - 1/1 ботов уже имеют игру app/1089130 | Quake II RTX. - 1/1 ботов уже имеют игру app/755790 | Ring of Elysium. - 1/1 ботов уже имеют игру app/1258080 | Shop Titans. - 1/1 ботов уже имеют игру app/759530 | Struckd - 3D Game Creator. - 1/1 ботов уже имеют игру app/269710 | Tumblestone. - 1/1 ботов уже имеют игру app/304930 | Unturned."; + 1/1 ботов уже имеют игру app/1493800 | Aircraft Carrier Survival: Prolouge. + 1/1 ботов уже имеют игру app/349520 | Armillo. + 1/1 ботов уже имеют игру app/346330 | BrainBread 2. + 1/1 ботов уже имеют игру app/1086690 | C-War 2. + 1/1 ботов уже имеют игру app/730 | Counter-Strike: Global Offensive. + 1/1 ботов уже имеют игру app/838380 | DEAD OR ALIVE 6. + 1/1 ботов уже имеют игру app/582890 | Estranged: The Departure. + 1/1 ботов уже имеют игру app/331470 | Everlasting Summer. + 1/1 ботов уже имеют игру app/1078000 | Gamecraft. + 1/1 ботов уже имеют игру app/266310 | GameGuru. + 1/1 ботов уже имеют игру app/275390 | Guacamelee! Super Turbo Championship Edition. + 1/1 ботов уже имеют игру app/627690 | Idle Champions of the Forgotten Realms. + 1/1 ботов уже имеют игру app/1048540 | Kao the Kangaroo: Round 2. + 1/1 ботов уже имеют игру app/370910 | Kathy Rain. + 1/1 ботов уже имеют игру app/343710 | KHOLAT. + 1/1 ботов уже имеют игру app/253900 | Knights and Merchants. + 1/1 ботов уже имеют игру app/224260 | No More Room in Hell. + 1/1 ботов уже имеют игру app/343360 | Particula. + 1/1 ботов уже имеют игру app/237870 | Planet Explorers. + 1/1 ботов уже имеют игру app/684680 | Polygoneer. + 1/1 ботов уже имеют игру app/1089130 | Quake II RTX. + 1/1 ботов уже имеют игру app/755790 | Ring of Elysium. + 1/1 ботов уже имеют игру app/1258080 | Shop Titans. + 1/1 ботов уже имеют игру app/759530 | Struckd - 3D Game Creator. + 1/1 ботов уже имеют игру app/269710 | Tumblestone. + 1/1 ботов уже имеют игру app/304930 | Unturned. + """; List output = await GetMessageParts(message, prefix).ToListAsync().ConfigureAwait(false); diff --git a/ArchiSteamFarm.Tests/Trading.cs b/ArchiSteamFarm.Tests/Trading.cs index 038f446e4..5a4fab82d 100644 --- a/ArchiSteamFarm.Tests/Trading.cs +++ b/ArchiSteamFarm.Tests/Trading.cs @@ -30,21 +30,21 @@ namespace ArchiSteamFarm.Tests; public sealed class Trading { [TestMethod] public void ExploitingNewSetsIsFairButNotNeutral() { - HashSet inventory = new() { + HashSet inventory = [ CreateItem(1, 40), CreateItem(2, 10), CreateItem(3, 10) - }; + ]; - HashSet itemsToGive = new() { + HashSet itemsToGive = [ CreateItem(2, 5), CreateItem(3, 5) - }; + ]; - HashSet itemsToReceive = new() { + HashSet itemsToReceive = [ CreateItem(1, 9), CreateItem(4) - }; + ]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -52,45 +52,45 @@ public sealed class Trading { [TestMethod] public void MismatchRarityIsNotFair() { - HashSet itemsToGive = new() { CreateItem(1, rarity: Asset.ERarity.Rare) }; - HashSet itemsToReceive = new() { CreateItem(2) }; + HashSet itemsToGive = [CreateItem(1, rarity: Asset.ERarity.Rare)]; + HashSet itemsToReceive = [CreateItem(2)]; Assert.IsFalse(IsFairExchange(itemsToGive, itemsToReceive)); } [TestMethod] public void MismatchRealAppIDsIsNotFair() { - HashSet itemsToGive = new() { CreateItem(1, realAppID: 570) }; - HashSet itemsToReceive = new() { CreateItem(2) }; + HashSet itemsToGive = [CreateItem(1, realAppID: 570)]; + HashSet itemsToReceive = [CreateItem(2)]; Assert.IsFalse(IsFairExchange(itemsToGive, itemsToReceive)); } [TestMethod] public void MismatchTypesIsNotFair() { - HashSet itemsToGive = new() { CreateItem(1, type: Asset.EType.Emoticon) }; - HashSet itemsToReceive = new() { CreateItem(2) }; + HashSet itemsToGive = [CreateItem(1, type: Asset.EType.Emoticon)]; + HashSet itemsToReceive = [CreateItem(2)]; Assert.IsFalse(IsFairExchange(itemsToGive, itemsToReceive)); } [TestMethod] public void MultiGameMultiTypeBadReject() { - HashSet inventory = new() { + HashSet inventory = [ CreateItem(1, 9), CreateItem(3, 9, 730, Asset.EType.Emoticon), CreateItem(4, realAppID: 730, type: Asset.EType.Emoticon) - }; + ]; - HashSet itemsToGive = new() { + HashSet itemsToGive = [ CreateItem(1), CreateItem(4, realAppID: 730, type: Asset.EType.Emoticon) - }; + ]; - HashSet itemsToReceive = new() { + HashSet itemsToReceive = [ CreateItem(2), CreateItem(3, realAppID: 730, type: Asset.EType.Emoticon) - }; + ]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -98,20 +98,20 @@ public sealed class Trading { [TestMethod] public void MultiGameMultiTypeNeutralAccept() { - HashSet inventory = new() { + HashSet inventory = [ CreateItem(1, 9), CreateItem(3, realAppID: 730, type: Asset.EType.Emoticon) - }; + ]; - HashSet itemsToGive = new() { + HashSet itemsToGive = [ CreateItem(1), CreateItem(3, realAppID: 730, type: Asset.EType.Emoticon) - }; + ]; - HashSet itemsToReceive = new() { + HashSet itemsToReceive = [ CreateItem(2), CreateItem(4, realAppID: 730, type: Asset.EType.Emoticon) - }; + ]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -119,21 +119,21 @@ public sealed class Trading { [TestMethod] public void MultiGameSingleTypeBadReject() { - HashSet inventory = new() { + HashSet inventory = [ CreateItem(1, 9), CreateItem(3, realAppID: 730), CreateItem(4, realAppID: 730) - }; + ]; - HashSet itemsToGive = new() { + HashSet itemsToGive = [ CreateItem(1), CreateItem(3, realAppID: 730) - }; + ]; - HashSet itemsToReceive = new() { + HashSet itemsToReceive = [ CreateItem(2), CreateItem(4, realAppID: 730) - }; + ]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -141,20 +141,20 @@ public sealed class Trading { [TestMethod] public void MultiGameSingleTypeNeutralAccept() { - HashSet inventory = new() { + HashSet inventory = [ CreateItem(1, 2), CreateItem(3, realAppID: 730) - }; + ]; - HashSet itemsToGive = new() { + HashSet itemsToGive = [ CreateItem(1), CreateItem(3, realAppID: 730) - }; + ]; - HashSet itemsToReceive = new() { + HashSet itemsToReceive = [ CreateItem(2), CreateItem(4, realAppID: 730) - }; + ]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -162,21 +162,17 @@ public sealed class Trading { [TestMethod] public void SingleGameAbrynosWasWrongNeutralAccept() { - HashSet inventory = new() { + HashSet inventory = [ CreateItem(1), CreateItem(2, 2), CreateItem(3), CreateItem(4), CreateItem(5) - }; + ]; - HashSet itemsToGive = new() { - CreateItem(2) - }; + HashSet itemsToGive = [CreateItem(2)]; - HashSet itemsToReceive = new() { - CreateItem(3) - }; + HashSet itemsToReceive = [CreateItem(3)]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -184,18 +180,14 @@ public sealed class Trading { [TestMethod] public void SingleGameDonationAccept() { - HashSet inventory = new() { - CreateItem(1) - }; + HashSet inventory = [CreateItem(1)]; - HashSet itemsToGive = new() { - CreateItem(1) - }; + HashSet itemsToGive = [CreateItem(1)]; - HashSet itemsToReceive = new() { + HashSet itemsToReceive = [ CreateItem(2), CreateItem(3, type: Asset.EType.SteamGems) - }; + ]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -203,21 +195,21 @@ public sealed class Trading { [TestMethod] public void SingleGameMultiTypeBadReject() { - HashSet inventory = new() { + HashSet inventory = [ CreateItem(1, 9), CreateItem(3, 9, type: Asset.EType.Emoticon), CreateItem(4, type: Asset.EType.Emoticon) - }; + ]; - HashSet itemsToGive = new() { + HashSet itemsToGive = [ CreateItem(1), CreateItem(4, type: Asset.EType.Emoticon) - }; + ]; - HashSet itemsToReceive = new() { + HashSet itemsToReceive = [ CreateItem(2), CreateItem(3, type: Asset.EType.Emoticon) - }; + ]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -225,20 +217,20 @@ public sealed class Trading { [TestMethod] public void SingleGameMultiTypeNeutralAccept() { - HashSet inventory = new() { + HashSet inventory = [ CreateItem(1, 9), CreateItem(3, type: Asset.EType.Emoticon) - }; + ]; - HashSet itemsToGive = new() { + HashSet itemsToGive = [ CreateItem(1), CreateItem(3, type: Asset.EType.Emoticon) - }; + ]; - HashSet itemsToReceive = new() { + HashSet itemsToReceive = [ CreateItem(2), CreateItem(4, type: Asset.EType.Emoticon) - }; + ]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -246,19 +238,19 @@ public sealed class Trading { [TestMethod] public void SingleGameQuantityBadReject() { - HashSet inventory = new() { + HashSet inventory = [ CreateItem(1), CreateItem(2), CreateItem(3) - }; + ]; - HashSet itemsToGive = new() { + HashSet itemsToGive = [ CreateItem(1), CreateItem(2), CreateItem(3) - }; + ]; - HashSet itemsToReceive = new() { CreateItem(4, 3) }; + HashSet itemsToReceive = [CreateItem(4, 3)]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -266,17 +258,17 @@ public sealed class Trading { [TestMethod] public void SingleGameQuantityBadReject2() { - HashSet inventory = new() { + HashSet inventory = [ CreateItem(1), CreateItem(2, 2) - }; + ]; - HashSet itemsToGive = new() { + HashSet itemsToGive = [ CreateItem(1), CreateItem(2, 2) - }; + ]; - HashSet itemsToReceive = new() { CreateItem(3, 3) }; + HashSet itemsToReceive = [CreateItem(3, 3)]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -284,17 +276,17 @@ public sealed class Trading { [TestMethod] public void SingleGameQuantityNeutralAccept() { - HashSet inventory = new() { + HashSet inventory = [ CreateItem(1, 2), CreateItem(2) - }; + ]; - HashSet itemsToGive = new() { + HashSet itemsToGive = [ CreateItem(1), CreateItem(2) - }; + ]; - HashSet itemsToReceive = new() { CreateItem(3, 2) }; + HashSet itemsToReceive = [CreateItem(3, 2)]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -302,13 +294,13 @@ public sealed class Trading { [TestMethod] public void SingleGameSingleTypeBadReject() { - HashSet inventory = new() { + HashSet inventory = [ CreateItem(1), CreateItem(2) - }; + ]; - HashSet itemsToGive = new() { CreateItem(1) }; - HashSet itemsToReceive = new() { CreateItem(2) }; + HashSet itemsToGive = [CreateItem(1)]; + HashSet itemsToReceive = [CreateItem(2)]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -316,18 +308,18 @@ public sealed class Trading { [TestMethod] public void SingleGameSingleTypeBadWithOverpayingReject() { - HashSet inventory = new() { + HashSet inventory = [ CreateItem(1, 2), CreateItem(2, 2), CreateItem(3, 2) - }; + ]; - HashSet itemsToGive = new() { CreateItem(2) }; + HashSet itemsToGive = [CreateItem(2)]; - HashSet itemsToReceive = new() { + HashSet itemsToReceive = [ CreateItem(1), CreateItem(3) - }; + ]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -335,14 +327,14 @@ public sealed class Trading { [TestMethod] public void SingleGameSingleTypeBigDifferenceAccept() { - HashSet inventory = new() { + HashSet inventory = [ CreateItem(1), CreateItem(2, 5), CreateItem(3) - }; + ]; - HashSet itemsToGive = new() { CreateItem(2) }; - HashSet itemsToReceive = new() { CreateItem(3) }; + HashSet itemsToGive = [CreateItem(2)]; + HashSet itemsToReceive = [CreateItem(3)]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -350,23 +342,23 @@ public sealed class Trading { [TestMethod] public void SingleGameSingleTypeBigDifferenceReject() { - HashSet inventory = new() { + HashSet inventory = [ CreateItem(1), CreateItem(2, 2), CreateItem(3, 2), CreateItem(4, 3), CreateItem(5, 10) - }; + ]; - HashSet itemsToGive = new() { + HashSet itemsToGive = [ CreateItem(2), CreateItem(5) - }; + ]; - HashSet itemsToReceive = new() { + HashSet itemsToReceive = [ CreateItem(3), CreateItem(4) - }; + ]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsFalse(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -374,9 +366,9 @@ public sealed class Trading { [TestMethod] public void SingleGameSingleTypeGoodAccept() { - HashSet inventory = new() { CreateItem(1, 2) }; - HashSet itemsToGive = new() { CreateItem(1) }; - HashSet itemsToReceive = new() { CreateItem(2) }; + HashSet inventory = [CreateItem(1, 2)]; + HashSet itemsToGive = [CreateItem(1)]; + HashSet itemsToReceive = [CreateItem(2)]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -384,9 +376,9 @@ public sealed class Trading { [TestMethod] public void SingleGameSingleTypeNeutralAccept() { - HashSet inventory = new() { CreateItem(1) }; - HashSet itemsToGive = new() { CreateItem(1) }; - HashSet itemsToReceive = new() { CreateItem(2) }; + HashSet inventory = [CreateItem(1)]; + HashSet itemsToGive = [CreateItem(1)]; + HashSet itemsToReceive = [CreateItem(2)]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -394,17 +386,17 @@ public sealed class Trading { [TestMethod] public void SingleGameSingleTypeNeutralWithOverpayingAccept() { - HashSet inventory = new() { + HashSet inventory = [ CreateItem(1, 2), CreateItem(2, 2) - }; + ]; - HashSet itemsToGive = new() { CreateItem(2) }; + HashSet itemsToGive = [CreateItem(2)]; - HashSet itemsToReceive = new() { + HashSet itemsToReceive = [ CreateItem(1), CreateItem(3) - }; + ]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); @@ -412,23 +404,23 @@ public sealed class Trading { [TestMethod] public void TakingExcessiveAmountOfSingleCardCanStillBeFairAndNeutral() { - HashSet inventory = new() { + HashSet inventory = [ CreateItem(1, 52), CreateItem(2, 73), CreateItem(3, 52), CreateItem(4, 47), CreateItem(5) - }; + ]; - HashSet itemsToGive = new() { CreateItem(2, 73) }; + HashSet itemsToGive = [CreateItem(2, 73)]; - HashSet itemsToReceive = new() { + HashSet itemsToReceive = [ CreateItem(1, 9), CreateItem(3, 9), CreateItem(4, 8), CreateItem(5, 24), CreateItem(6, 23) - }; + ]; Assert.IsTrue(IsFairExchange(itemsToGive, itemsToReceive)); Assert.IsTrue(IsTradeNeutralOrBetter(inventory, itemsToGive, itemsToReceive)); diff --git a/ArchiSteamFarm.sln.DotSettings b/ArchiSteamFarm.sln.DotSettings index 6a7ef2aa4..b6a5b0dc5 100644 --- a/ArchiSteamFarm.sln.DotSettings +++ b/ArchiSteamFarm.sln.DotSettings @@ -189,6 +189,7 @@ WARNING WARNING WARNING + SUGGESTION SUGGESTION SUGGESTION SUGGESTION @@ -317,8 +318,9 @@ SUGGESTION SUGGESTION SUGGESTION - DO_NOT_SHOW + SUGGESTION SUGGESTION + SUGGESTION WARNING SUGGESTION SUGGESTION diff --git a/ArchiSteamFarm/Collections/ConcurrentHashSet.cs b/ArchiSteamFarm/Collections/ConcurrentHashSet.cs index 44799f417..b47271d4c 100644 --- a/ArchiSteamFarm/Collections/ConcurrentHashSet.cs +++ b/ArchiSteamFarm/Collections/ConcurrentHashSet.cs @@ -135,7 +135,7 @@ public sealed class ConcurrentHashSet : IReadOnlyCollection, ISet where public void SymmetricExceptWith(IEnumerable other) { ISet otherSet = other as ISet ?? other.ToHashSet(); - HashSet removed = new(); + HashSet removed = []; foreach (T item in otherSet.Where(Contains)) { removed.Add(item); diff --git a/ArchiSteamFarm/Collections/ConcurrentList.cs b/ArchiSteamFarm/Collections/ConcurrentList.cs index fad186756..c40a66f5e 100644 --- a/ArchiSteamFarm/Collections/ConcurrentList.cs +++ b/ArchiSteamFarm/Collections/ConcurrentList.cs @@ -41,7 +41,7 @@ internal sealed class ConcurrentList : IList, IReadOnlyList { } } - private readonly List BackingCollection = new(); + private readonly List BackingCollection = []; private readonly AsyncReaderWriterLock Lock = new(); int ICollection.Count => Count; diff --git a/ArchiSteamFarm/Core/Utilities.cs b/ArchiSteamFarm/Core/Utilities.cs index 95c617622..dbc70dd4e 100644 --- a/ArchiSteamFarm/Core/Utilities.cs +++ b/ArchiSteamFarm/Core/Utilities.cs @@ -123,7 +123,7 @@ public static class Utilities { switch (ASF.GlobalConfig?.OptimizationMode) { case GlobalConfig.EOptimizationMode.MinMemoryUsage: - List results = new(); + List results = []; foreach (Task task in tasks) { results.Add(await task.ConfigureAwait(false)); diff --git a/ArchiSteamFarm/IPC/Integration/SwaggerValidValuesAttribute.cs b/ArchiSteamFarm/IPC/Integration/SwaggerValidValuesAttribute.cs index 6c67d3c7f..16acc38b2 100644 --- a/ArchiSteamFarm/IPC/Integration/SwaggerValidValuesAttribute.cs +++ b/ArchiSteamFarm/IPC/Integration/SwaggerValidValuesAttribute.cs @@ -36,7 +36,7 @@ public sealed class SwaggerValidValuesAttribute : CustomSwaggerAttribute { public override void Apply(OpenApiSchema schema) { ArgumentNullException.ThrowIfNull(schema); - OpenApiArray validValues = new(); + OpenApiArray validValues = []; if (ValidIntValues != null) { validValues.AddRange(ValidIntValues.Select(static type => new OpenApiInteger(type))); diff --git a/ArchiSteamFarm/IPC/Requests/TwoFactorAuthenticationConfirmationsRequest.cs b/ArchiSteamFarm/IPC/Requests/TwoFactorAuthenticationConfirmationsRequest.cs index b0ee48946..911de3d7d 100644 --- a/ArchiSteamFarm/IPC/Requests/TwoFactorAuthenticationConfirmationsRequest.cs +++ b/ArchiSteamFarm/IPC/Requests/TwoFactorAuthenticationConfirmationsRequest.cs @@ -62,7 +62,7 @@ public sealed class TwoFactorAuthenticationConfirmationsRequest { private set { ArgumentNullException.ThrowIfNull(value); - HashSet acceptedCreatorIDs = new(); + HashSet acceptedCreatorIDs = []; foreach (string creatorIDText in value) { if (!ulong.TryParse(creatorIDText, out ulong creatorID) || (creatorID == 0)) { diff --git a/ArchiSteamFarm/NLog/Logging.cs b/ArchiSteamFarm/NLog/Logging.cs index 806882ed4..887d4d3da 100644 --- a/ArchiSteamFarm/NLog/Logging.cs +++ b/ArchiSteamFarm/NLog/Logging.cs @@ -49,7 +49,7 @@ internal static class Logging { internal static bool LogFileExists => File.Exists(SharedInfo.LogFile); - private static readonly ConcurrentHashSet ConsoleLoggingRules = new(); + private static readonly ConcurrentHashSet ConsoleLoggingRules = []; private static readonly SemaphoreSlim ConsoleSemaphore = new(1, 1); private static string Backspace => "\b \b"; diff --git a/ArchiSteamFarm/Plugins/PluginsCore.cs b/ArchiSteamFarm/Plugins/PluginsCore.cs index bdb7b465c..3a716984e 100644 --- a/ArchiSteamFarm/Plugins/PluginsCore.cs +++ b/ArchiSteamFarm/Plugins/PluginsCore.cs @@ -207,7 +207,7 @@ public static class PluginsCore { return true; } - HashSet invalidPlugins = new(); + HashSet invalidPlugins = []; foreach (IPlugin plugin in activePlugins) { try { @@ -649,7 +649,7 @@ public static class PluginsCore { return null; } - HashSet assemblies = new(); + HashSet assemblies = []; try { foreach (string assemblyPath in Directory.EnumerateFiles(path, "*.dll", SearchOption.AllDirectories)) { diff --git a/ArchiSteamFarm/Steam/Bot.cs b/ArchiSteamFarm/Steam/Bot.cs index a7ba09575..f971c55cb 100644 --- a/ArchiSteamFarm/Steam/Bot.cs +++ b/ArchiSteamFarm/Steam/Bot.cs @@ -165,7 +165,7 @@ public sealed class Bot : IAsyncDisposable, IDisposable { private readonly SemaphoreSlim RefreshWebSessionSemaphore = new(1, 1); private readonly SemaphoreSlim SendCompleteTypesSemaphore = new(1, 1); private readonly SteamClient SteamClient; - private readonly ConcurrentHashSet SteamFamilySharingIDs = new(); + private readonly ConcurrentHashSet SteamFamilySharingIDs = []; private readonly SteamUser SteamUser; private readonly Trading Trading; @@ -524,7 +524,7 @@ public sealed class Bot : IAsyncDisposable, IDisposable { string[] botNames = args.Split(SharedInfo.ListElementSeparators, StringSplitOptions.RemoveEmptyEntries); - HashSet result = new(); + HashSet result = []; foreach (string botName in botNames) { if (botName.Equals(SharedInfo.ASF, StringComparison.OrdinalIgnoreCase)) { @@ -659,7 +659,7 @@ public sealed class Bot : IAsyncDisposable, IDisposable { ArgumentOutOfRangeException.ThrowIfLessThan(maxItems, MinCardsPerBadge); - HashSet result = new(); + HashSet result = []; Dictionary<(uint RealAppID, Asset.EType Type, Asset.ERarity Rarity), Dictionary>> itemsPerClassIDPerSet = inventory.GroupBy(static item => (item.RealAppID, item.Type, item.Rarity)).ToDictionary(static grouping => grouping.Key, static grouping => grouping.GroupBy(static item => item.ClassID).ToDictionary(static group => group.Key, static group => group.ToHashSet())); foreach (((uint RealAppID, Asset.EType Type, Asset.ERarity Rarity) set, (uint setsToExtract, byte itemsPerSet)) in amountsToExtract.OrderBy(static kv => kv.Value.ItemsPerSet)) { @@ -1281,7 +1281,7 @@ public sealed class Bot : IAsyncDisposable, IDisposable { throw new InvalidOperationException(nameof(ASF.GlobalDatabase)); } - HashSet packageRequests = new(); + HashSet packageRequests = []; foreach (uint packageID in packageIDs) { if (!ASF.GlobalDatabase.PackageAccessTokensReadOnly.TryGetValue(packageID, out ulong packageAccessToken)) { @@ -1936,7 +1936,7 @@ public sealed class Bot : IAsyncDisposable, IDisposable { throw new ArgumentNullException(nameof(gamesToRedeemInBackground)); } - HashSet invalidKeys = new(); + HashSet invalidKeys = []; foreach (DictionaryEntry game in gamesToRedeemInBackground) { bool invalid = false; @@ -2084,7 +2084,7 @@ public sealed class Bot : IAsyncDisposable, IDisposable { // Level 5 is maximum level for card badges according to https://steamcommunity.com/tradingcards/faq IEnumerable linkElements = badgePage.SelectNodes("//a[@class='badge_craft_button']/@href | //div[@class='badges_sheet']/div[contains(@class, 'badge_row') and .//div[@class='badge_info_description']/div[contains(text(), 'Level 5')]]/a[@class='badge_row_overlay']/@href"); - HashSet result = new(); + HashSet result = []; foreach (string badgeUri in linkElements.Select(static htmlNode => htmlNode.Value)) { if (string.IsNullOrEmpty(badgeUri)) { @@ -3353,7 +3353,7 @@ public sealed class Bot : IAsyncDisposable, IDisposable { return; } - HashSet newPluginNotifications = new(); + HashSet newPluginNotifications = []; foreach ((UserNotificationsCallback.EUserNotification notification, uint count) in callback.Notifications) { bool newNotification; diff --git a/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs b/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs index 9bf9be0f3..4b0657be7 100644 --- a/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs +++ b/ArchiSteamFarm/Steam/Cards/CardsFarmer.cs @@ -86,7 +86,7 @@ public sealed class CardsFarmer : IAsyncDisposable, IDisposable { // More advanced calculation, the above AND hours required for bumps uint cardsRemaining = 0; - List totalHoursClocked = new(); + List totalHoursClocked = []; foreach (Game gameToFarm in GamesToFarm) { cardsRemaining += gameToFarm.CardsRemaining; @@ -119,11 +119,11 @@ public sealed class CardsFarmer : IAsyncDisposable, IDisposable { } private readonly Bot Bot; - private readonly ConcurrentHashSet CurrentGamesFarming = new(); + private readonly ConcurrentHashSet CurrentGamesFarming = []; private readonly SemaphoreSlim EventSemaphore = new(1, 1); private readonly SemaphoreSlim FarmingInitializationSemaphore = new(1, 1); private readonly SemaphoreSlim FarmingResetSemaphore = new(0, 1); - private readonly ConcurrentList GamesToFarm = new(); + private readonly ConcurrentList GamesToFarm = []; private readonly Timer? IdleFarmingTimer; private readonly ConcurrentDictionary LocallyIgnoredAppIDs = new(); @@ -723,7 +723,7 @@ public sealed class CardsFarmer : IAsyncDisposable, IDisposable { break; default: - backgroundTasks ??= new HashSet(); + backgroundTasks ??= []; backgroundTasks.Add(task); @@ -1141,7 +1141,7 @@ public sealed class CardsFarmer : IAsyncDisposable, IDisposable { GamesToFarm.Clear(); - ConcurrentHashSet parsedAppIDs = new(); + ConcurrentHashSet parsedAppIDs = []; Task mainTask = CheckPage(htmlDocument, parsedAppIDs); diff --git a/ArchiSteamFarm/Steam/Data/TradeOffer.cs b/ArchiSteamFarm/Steam/Data/TradeOffer.cs index aad448e46..8f70ddf71 100644 --- a/ArchiSteamFarm/Steam/Data/TradeOffer.cs +++ b/ArchiSteamFarm/Steam/Data/TradeOffer.cs @@ -36,8 +36,8 @@ public sealed class TradeOffer { [PublicAPI] public IReadOnlyCollection ItemsToReceiveReadOnly => ItemsToReceive; - internal readonly HashSet ItemsToGive = new(); - internal readonly HashSet ItemsToReceive = new(); + internal readonly HashSet ItemsToGive = []; + internal readonly HashSet ItemsToReceive = []; [PublicAPI] public ulong OtherSteamID64 { get; private set; } diff --git a/ArchiSteamFarm/Steam/Data/TradeOfferSendRequest.cs b/ArchiSteamFarm/Steam/Data/TradeOfferSendRequest.cs index 71b9ca29d..3399d6676 100644 --- a/ArchiSteamFarm/Steam/Data/TradeOfferSendRequest.cs +++ b/ArchiSteamFarm/Steam/Data/TradeOfferSendRequest.cs @@ -33,6 +33,6 @@ internal sealed class TradeOfferSendRequest { internal sealed class ItemList { [JsonProperty("assets", Required = Required.Always)] - internal readonly HashSet Assets = new(); + internal readonly HashSet Assets = []; } } diff --git a/ArchiSteamFarm/Steam/Exchange/Trading.cs b/ArchiSteamFarm/Steam/Exchange/Trading.cs index 0ed251192..c451d60e5 100644 --- a/ArchiSteamFarm/Steam/Exchange/Trading.cs +++ b/ArchiSteamFarm/Steam/Exchange/Trading.cs @@ -44,7 +44,7 @@ public sealed class Trading : IDisposable { internal const byte MaxTradesPerAccount = 5; // This is limit introduced by Valve private readonly Bot Bot; - private readonly ConcurrentHashSet HandledTradeOfferIDs = new(); + private readonly ConcurrentHashSet HandledTradeOfferIDs = []; private readonly SemaphoreSlim TradesSemaphore = new(1, 1); private bool ParsingScheduled; @@ -128,7 +128,7 @@ public sealed class Trading : IDisposable { // This loop is a bit more complex due to the fact that we might have a mix of the same item splitted into different amounts foreach (Asset itemToGive in itemsToGive) { uint amountToGive = itemToGive.Amount; - HashSet itemsToRemove = new(); + HashSet itemsToRemove = []; // Keep in mind that ClassID is unique only within appID scope - we can do it like this because we're not dealing with non-Steam items here (otherwise we'd need to check appID too) foreach (Asset item in inventory.Where(item => item.ClassID == itemToGive.ClassID)) { @@ -258,7 +258,7 @@ public sealed class Trading : IDisposable { throw new ArgumentNullException(nameof(classIDs)); } - HashSet result = new(); + HashSet result = []; IEnumerable items = inventory.Where(static item => item.Tradable); diff --git a/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs b/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs index 33b2e6ebe..b5b36bd63 100644 --- a/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs +++ b/ArchiSteamFarm/Steam/Integration/ArchiWebHandler.cs @@ -197,7 +197,7 @@ public sealed class ArchiWebHandler : IDisposable { return null; } - HashSet result = new(); + HashSet result = []; IEnumerable linkNodes = response.Content.SelectNodes("//li[@class='booster_eligibility_game']/a/@href"); @@ -353,11 +353,7 @@ public sealed class ArchiWebHandler : IDisposable { (ulong ClassID, ulong InstanceID) key = (description.ClassID, description.InstanceID); - if (descriptions.ContainsKey(key)) { - continue; - } - - descriptions[key] = description; + descriptions.TryAdd(key, description); } foreach (Asset asset in response.Content.Assets) { @@ -593,7 +589,7 @@ public sealed class ArchiWebHandler : IDisposable { trades = trades.Concat(response["trade_offers_sent"].Children); } - HashSet result = new(); + HashSet result = []; foreach (KeyValue trade in trades) { ETradeOfferState state = trade["trade_offer_state"].AsEnum(); @@ -679,7 +675,7 @@ public sealed class ArchiWebHandler : IDisposable { ArgumentOutOfRangeException.ThrowIfZero(itemsPerTrade); TradeOfferSendRequest singleTrade = new(); - HashSet trades = new() { singleTrade }; + HashSet trades = [singleTrade]; if (itemsToGive != null) { foreach (Asset itemToGive in itemsToGive) { @@ -1906,7 +1902,7 @@ public sealed class ArchiWebHandler : IDisposable { IEnumerable htmlNodes = response.Content.SelectNodes("//div[@class='pending_gift']/div[starts-with(@id, 'pending_gift_')][count(div[@class='pending_giftcard_leftcol']) > 0]/@id"); - HashSet results = new(); + HashSet results = []; foreach (string giftCardIDText in htmlNodes.Select(static htmlNode => htmlNode.Value)) { if (string.IsNullOrEmpty(giftCardIDText)) { @@ -1952,7 +1948,7 @@ public sealed class ArchiWebHandler : IDisposable { IEnumerable htmlNodes = response.Content.SelectNodes("(//table[@class='accountTable'])[2]//a/@data-miniprofile"); - HashSet result = new(); + HashSet result = []; foreach (string miniProfile in htmlNodes.Select(static htmlNode => htmlNode.Value)) { if (string.IsNullOrEmpty(miniProfile)) { diff --git a/ArchiSteamFarm/Steam/Interaction/Actions.cs b/ArchiSteamFarm/Steam/Interaction/Actions.cs index ba972b80c..5cfe285f2 100644 --- a/ArchiSteamFarm/Steam/Interaction/Actions.cs +++ b/ArchiSteamFarm/Steam/Interaction/Actions.cs @@ -47,7 +47,7 @@ public sealed class Actions : IAsyncDisposable, IDisposable { private static readonly SemaphoreSlim GiftCardsSemaphore = new(1, 1); private readonly Bot Bot; - private readonly ConcurrentHashSet HandledGifts = new(); + private readonly ConcurrentHashSet HandledGifts = []; private readonly SemaphoreSlim TradingSemaphore = new(1, 1); private Timer? CardsFarmerResumeTimer; diff --git a/ArchiSteamFarm/Steam/Interaction/Commands.cs b/ArchiSteamFarm/Steam/Interaction/Commands.cs index 52b03ac87..b2dd843a1 100644 --- a/ArchiSteamFarm/Steam/Interaction/Commands.cs +++ b/ArchiSteamFarm/Steam/Interaction/Commands.cs @@ -532,7 +532,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.Response2FA(GetProxyAccess(bot, access, steamID)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -574,7 +574,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.Response2FAConfirm(GetProxyAccess(bot, access, steamID), confirm))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -678,7 +678,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseAddLicense(GetProxyAccess(bot, access, steamID), query))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -729,7 +729,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseAdvancedLoot(GetProxyAccess(bot, access, steamID), appID, contextID))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -821,7 +821,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseAdvancedRedeem(GetProxyAccess(bot, access, steamID), options, keys, steamID))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -910,7 +910,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseAdvancedTransfer(GetProxyAccess(bot, access, steamID), appID, contextID, targetBot))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -944,7 +944,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseBackgroundGamesRedeemer(GetProxyAccess(bot, access, steamID))))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -1021,7 +1021,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseFarm(GetProxyAccess(bot, access, steamID)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -1049,7 +1049,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingBlacklist(GetProxyAccess(bot, access, steamID))))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -1071,7 +1071,7 @@ public sealed class Commands { return FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(targets))); } - HashSet appIDs = new(); + HashSet appIDs = []; foreach (string target in targets) { if (!uint.TryParse(target, out uint appID) || (appID == 0)) { @@ -1113,7 +1113,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingBlacklistAdd(GetProxyAccess(bot, access, steamID), targetAppIDs)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -1135,7 +1135,7 @@ public sealed class Commands { return FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(targets))); } - HashSet appIDs = new(); + HashSet appIDs = []; foreach (string target in targets) { if (!uint.TryParse(target, out uint appID) || (appID == 0)) { @@ -1172,7 +1172,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingBlacklistRemove(GetProxyAccess(bot, access, steamID), targetAppIDs)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -1200,7 +1200,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingQueue(GetProxyAccess(bot, access, steamID))))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -1222,7 +1222,7 @@ public sealed class Commands { return FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(targets))); } - HashSet appIDs = new(); + HashSet appIDs = []; foreach (string target in targets) { if (!uint.TryParse(target, out uint appID) || (appID == 0)) { @@ -1271,7 +1271,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingQueueAdd(GetProxyAccess(bot, access, steamID), targetAppIDs)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -1293,7 +1293,7 @@ public sealed class Commands { return FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(targets))); } - HashSet appIDs = new(); + HashSet appIDs = []; foreach (string target in targets) { if (!uint.TryParse(target, out uint appID) || (appID == 0)) { @@ -1335,7 +1335,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseFarmingQueueRemove(GetProxyAccess(bot, access, steamID), targetAppIDs)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -1413,7 +1413,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseInput(GetProxyAccess(bot, access, steamID), propertyName, inputValue)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -1451,7 +1451,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseLevel(GetProxyAccess(bot, access, steamID)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -1493,7 +1493,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseLoot(GetProxyAccess(bot, access, steamID)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -1523,7 +1523,7 @@ public sealed class Commands { return FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(appIDTexts))); } - HashSet realAppIDs = new(); + HashSet realAppIDs = []; foreach (string appIDText in appIDTexts) { if (!uint.TryParse(appIDText, out uint appID) || (appID == 0)) { @@ -1554,7 +1554,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseLootByRealAppIDs(GetProxyAccess(bot, access, steamID), realAppIDsText, exclude))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -1582,7 +1582,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseMatchActivelyBlacklist(GetProxyAccess(bot, access, steamID))))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -1604,7 +1604,7 @@ public sealed class Commands { return FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(targets))); } - HashSet appIDs = new(); + HashSet appIDs = []; foreach (string target in targets) { if (!uint.TryParse(target, out uint appID) || (appID == 0)) { @@ -1633,7 +1633,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseMatchActivelyBlacklistAdd(GetProxyAccess(bot, access, steamID), targetAppIDs)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -1655,7 +1655,7 @@ public sealed class Commands { return FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(targets))); } - HashSet appIDs = new(); + HashSet appIDs = []; foreach (string target in targets) { if (!uint.TryParse(target, out uint appID) || (appID == 0)) { @@ -1684,7 +1684,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseMatchActivelyBlacklistRemove(GetProxyAccess(bot, access, steamID), targetAppIDs)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -1728,7 +1728,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseNickname(GetProxyAccess(bot, access, steamID), nickname)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -1896,7 +1896,7 @@ public sealed class Commands { IList<(string? Response, Dictionary? OwnedGames)> results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseOwns(GetProxyAccess(bot, access, steamID), query))).ConfigureAwait(false); - List<(string Response, Dictionary OwnedGames)> validResults = new(results.Where(static result => !string.IsNullOrEmpty(result.Response) && (result.OwnedGames != null))!); + List<(string Response, Dictionary OwnedGames)> validResults = [..results.Where(static result => !string.IsNullOrEmpty(result.Response) && (result.OwnedGames != null))]; if (validResults.Count == 0) { return null; @@ -1962,7 +1962,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponsePause(GetProxyAccess(bot, access, steamID), permanent, resumeInSecondsText))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -2052,7 +2052,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponsePlay(GetProxyAccess(bot, access, steamID), targetGameIDs))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -2090,7 +2090,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponsePointsBalance(GetProxyAccess(bot, access, steamID)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -2243,7 +2243,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponsePrivacy(GetProxyAccess(bot, access, steamID), privacySettingsText))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -2285,8 +2285,8 @@ public sealed class Commands { HashSet pendingKeys = keys.ToHashSet(StringComparer.Ordinal); HashSet unusedKeys = pendingKeys.ToHashSet(StringComparer.Ordinal); - HashSet rateLimitedBots = new(); - HashSet triedBots = new(); + HashSet rateLimitedBots = []; + HashSet triedBots = []; StringBuilder response = new(); @@ -2523,7 +2523,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseRedeem(GetProxyAccess(bot, access, steamID), keysText, steamID, redeemFlags))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -2561,7 +2561,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseReset(GetProxyAccess(bot, access, steamID)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -2609,7 +2609,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseResume(GetProxyAccess(bot, access, steamID))))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -2643,7 +2643,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseStart(GetProxyAccess(bot, access, steamID))))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -2720,7 +2720,7 @@ public sealed class Commands { IList<(string? Response, Bot Bot)> results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseStatus(GetProxyAccess(bot, access, steamID))))).ConfigureAwait(false); - List<(string Response, Bot Bot)> validResults = new(results.Where(static result => !string.IsNullOrEmpty(result.Response))!); + List<(string Response, Bot Bot)> validResults = [..results.Where(static result => !string.IsNullOrEmpty(result.Response))]; if (validResults.Count == 0) { return null; @@ -2762,7 +2762,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseStop(GetProxyAccess(bot, access, steamID))))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -2790,7 +2790,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseTradingBlacklist(GetProxyAccess(bot, access, steamID))))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -2812,7 +2812,7 @@ public sealed class Commands { return FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(targets))); } - HashSet targetIDs = new(); + HashSet targetIDs = []; foreach (string target in targets) { if (!ulong.TryParse(target, out ulong targetID) || (targetID == 0) || !new SteamID(targetID).IsIndividualAccount) { @@ -2841,7 +2841,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseTradingBlacklistAdd(GetProxyAccess(bot, access, steamID), targetSteamIDs)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -2863,7 +2863,7 @@ public sealed class Commands { return FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(targets))); } - HashSet targetIDs = new(); + HashSet targetIDs = []; foreach (string target in targets) { if (!ulong.TryParse(target, out ulong targetID) || (targetID == 0) || !new SteamID(targetID).IsIndividualAccount) { @@ -2892,7 +2892,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseTradingBlacklistRemove(GetProxyAccess(bot, access, steamID), targetSteamIDs)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -2951,7 +2951,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseTransfer(GetProxyAccess(bot, access, steamID), botNameTo))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -3016,7 +3016,7 @@ public sealed class Commands { return FormatBotResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(appIDTexts))); } - HashSet realAppIDs = new(); + HashSet realAppIDs = []; foreach (string appIDText in appIDTexts) { if (!uint.TryParse(appIDText, out uint appID) || (appID == 0)) { @@ -3050,7 +3050,7 @@ public sealed class Commands { return FormatStaticResponse(string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsEmpty, nameof(appIDTexts))); } - HashSet realAppIDs = new(); + HashSet realAppIDs = []; foreach (string appIDText in appIDTexts) { if (!uint.TryParse(appIDText, out uint appID) || (appID == 0)) { @@ -3068,7 +3068,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseTransferByRealAppIDs(GetProxyAccess(bot, access, steamID), realAppIDs, targetBot, exclude))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -3132,7 +3132,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => bot.Commands.ResponseUnpackBoosters(GetProxyAccess(bot, access, steamID)))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } @@ -3194,7 +3194,7 @@ public sealed class Commands { IList results = await Utilities.InParallel(bots.Select(bot => Task.Run(() => bot.Commands.ResponseWalletBalance(GetProxyAccess(bot, access, steamID))))).ConfigureAwait(false); - List responses = new(results.Where(static result => !string.IsNullOrEmpty(result))!); + List responses = [..results.Where(static result => !string.IsNullOrEmpty(result))]; return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } diff --git a/ArchiSteamFarm/Steam/SteamKit2/InMemoryServerListProvider.cs b/ArchiSteamFarm/Steam/SteamKit2/InMemoryServerListProvider.cs index 7fa05d92e..252db76c1 100644 --- a/ArchiSteamFarm/Steam/SteamKit2/InMemoryServerListProvider.cs +++ b/ArchiSteamFarm/Steam/SteamKit2/InMemoryServerListProvider.cs @@ -31,7 +31,7 @@ namespace ArchiSteamFarm.Steam.SteamKit2; internal sealed class InMemoryServerListProvider : IServerListProvider { [JsonProperty(Required = Required.DisallowNull)] - private readonly ConcurrentHashSet ServerRecords = new(); + private readonly ConcurrentHashSet ServerRecords = []; public Task> FetchServerListAsync() => Task.FromResult(ServerRecords.Where(static server => !string.IsNullOrEmpty(server.Host) && server is { Port: > 0, ProtocolTypes: > 0 }).Select(static server => ServerRecord.CreateServer(server.Host, server.Port, server.ProtocolTypes))); diff --git a/ArchiSteamFarm/Steam/Storage/BotDatabase.cs b/ArchiSteamFarm/Steam/Storage/BotDatabase.cs index 0e2eacaf5..28491cbe4 100644 --- a/ArchiSteamFarm/Steam/Storage/BotDatabase.cs +++ b/ArchiSteamFarm/Steam/Storage/BotDatabase.cs @@ -38,22 +38,22 @@ namespace ArchiSteamFarm.Steam.Storage; public sealed class BotDatabase : GenericDatabase { [JsonProperty(Required = Required.DisallowNull)] - internal readonly ConcurrentHashSet FarmingBlacklistAppIDs = new(); + internal readonly ConcurrentHashSet FarmingBlacklistAppIDs = []; [JsonProperty(Required = Required.DisallowNull)] - internal readonly ConcurrentHashSet FarmingPriorityQueueAppIDs = new(); + internal readonly ConcurrentHashSet FarmingPriorityQueueAppIDs = []; [JsonProperty(Required = Required.DisallowNull)] internal readonly ObservableConcurrentDictionary FarmingRiskyIgnoredAppIDs = new(); [JsonProperty(Required = Required.DisallowNull)] - internal readonly ConcurrentHashSet FarmingRiskyPrioritizedAppIDs = new(); + internal readonly ConcurrentHashSet FarmingRiskyPrioritizedAppIDs = []; [JsonProperty(Required = Required.DisallowNull)] - internal readonly ConcurrentHashSet MatchActivelyBlacklistAppIDs = new(); + internal readonly ConcurrentHashSet MatchActivelyBlacklistAppIDs = []; [JsonProperty(Required = Required.DisallowNull)] - internal readonly ConcurrentHashSet TradingBlacklistSteamIDs = new(); + internal readonly ConcurrentHashSet TradingBlacklistSteamIDs = []; internal uint GamesToRedeemInBackgroundCount { get { diff --git a/ArchiSteamFarm/Storage/GenericDatabase.cs b/ArchiSteamFarm/Storage/GenericDatabase.cs index b0724b39a..7429657ca 100644 --- a/ArchiSteamFarm/Storage/GenericDatabase.cs +++ b/ArchiSteamFarm/Storage/GenericDatabase.cs @@ -21,6 +21,7 @@ using System; using System.Collections.Concurrent; +using System.Collections.Generic; using ArchiSteamFarm.Core; using ArchiSteamFarm.Helpers; using JetBrains.Annotations; @@ -48,7 +49,7 @@ public abstract class GenericDatabase : SerializableFile { public JToken? LoadFromJsonStorage(string key) { ArgumentException.ThrowIfNullOrEmpty(key); - return KeyValueJsonStorage.TryGetValue(key, out JToken? value) ? value : null; + return KeyValueJsonStorage.GetValueOrDefault(key); } [PublicAPI] diff --git a/ArchiSteamFarm/Storage/GlobalDatabase.cs b/ArchiSteamFarm/Storage/GlobalDatabase.cs index 7a3c4d09e..b87c880a7 100644 --- a/ArchiSteamFarm/Storage/GlobalDatabase.cs +++ b/ArchiSteamFarm/Storage/GlobalDatabase.cs @@ -47,7 +47,7 @@ public sealed class GlobalDatabase : GenericDatabase { public IReadOnlyDictionary PackagesDataReadOnly => PackagesData; [JsonProperty(Required = Required.DisallowNull)] - internal readonly ConcurrentHashSet CachedBadBots = new(); + internal readonly ConcurrentHashSet CachedBadBots = []; [JsonProperty(Required = Required.DisallowNull)] internal readonly ObservableConcurrentDictionary CardCountsPerGame = new(); @@ -192,7 +192,7 @@ public sealed class GlobalDatabase : GenericDatabase { ArgumentOutOfRangeException.ThrowIfZero(appID); ArgumentNullException.ThrowIfNull(packageIDs); - HashSet result = new(); + HashSet result = []; foreach (uint packageID in packageIDs.Where(static packageID => packageID != 0)) { if (!PackagesData.TryGetValue(packageID, out PackageData? packageEntry) || (packageEntry.AppIDs?.Contains(appID) != true)) { diff --git a/ArchiSteamFarm/Web/GitHub.cs b/ArchiSteamFarm/Web/GitHub.cs index 87df42ede..32ae7a708 100644 --- a/ArchiSteamFarm/Web/GitHub.cs +++ b/ArchiSteamFarm/Web/GitHub.cs @@ -156,7 +156,7 @@ internal static class GitHub { ArgumentException.ThrowIfNullOrEmpty(markdownText); MarkdownDocument markdownDocument = Markdown.Parse(markdownText); - MarkdownDocument result = new(); + MarkdownDocument result = []; foreach (Block block in markdownDocument.SkipWhile(static block => block is not HeadingBlock { Inline.FirstChild: LiteralInline literalInline } || (literalInline.Content.ToString()?.Equals("Changelog", StringComparison.OrdinalIgnoreCase) != true)).Skip(1).TakeWhile(static block => block is not ThematicBreakBlock).ToList()) { // All blocks that we're interested in must be removed from original markdownDocument firstly