From 996f06c71f4c12baec68d07638d08b59295fb13e Mon Sep 17 00:00:00 2001 From: Ryzhehvost Date: Tue, 14 Dec 2021 13:52:09 +0200 Subject: [PATCH] update to net6.0 and tasks --- ArchiSteamFarm | 2 +- BoosterCreator/BoosterCreator.cs | 7 +++++-- BoosterCreator/BoosterCreator.csproj | 9 ++------- BoosterCreator/BoosterHandler.cs | 24 ++++++++++++++---------- BoosterCreator/Commands.cs | 18 +++++++++--------- BoosterCreator/Json.cs | 7 ++----- BoosterCreator/WebRequest.cs | 2 +- build.bat | 2 +- 8 files changed, 35 insertions(+), 36 deletions(-) diff --git a/ArchiSteamFarm b/ArchiSteamFarm index 2d96975..944df1c 160000 --- a/ArchiSteamFarm +++ b/ArchiSteamFarm @@ -1 +1 @@ -Subproject commit 2d969758f6ad5089669d4d9baa7fba9e1638746b +Subproject commit 944df1cfc87ab2cf31278cb7dde846062251d6b7 diff --git a/BoosterCreator/BoosterCreator.cs b/BoosterCreator/BoosterCreator.cs index 7df53c6..4be25d7 100644 --- a/BoosterCreator/BoosterCreator.cs +++ b/BoosterCreator/BoosterCreator.cs @@ -14,11 +14,14 @@ public sealed class BoosterCreator : IBotModules, IBotCommand { public string Name => nameof(BoosterCreator); public Version Version => typeof(BoosterCreator).Assembly.GetName().Version ?? new Version("0"); - public void OnLoaded() => ASF.ArchiLogger.LogGenericInfo("BoosterCreator ASF Plugin by Out (https://steamcommunity.com/id/outzzz) | fork by Ryzhehvost"); + public Task OnLoaded() { + ASF.ArchiLogger.LogGenericInfo("BoosterCreator ASF Plugin by Out (https://steamcommunity.com/id/outzzz) | fork by Ryzhehvost"); + return Task.CompletedTask; + } public async Task OnBotCommand(Bot bot, ulong steamID, string message, string[] args) => await Commands.Response(bot, steamID, message, args).ConfigureAwait(false); - public async void OnBotInitModules(Bot bot, IReadOnlyDictionary? additionalConfigProperties = null) { + public async Task OnBotInitModules(Bot bot, IReadOnlyDictionary? additionalConfigProperties = null) { if (additionalConfigProperties == null) { return; } diff --git a/BoosterCreator/BoosterCreator.csproj b/BoosterCreator/BoosterCreator.csproj index 874458c..653e93e 100644 --- a/BoosterCreator/BoosterCreator.csproj +++ b/BoosterCreator/BoosterCreator.csproj @@ -1,9 +1,9 @@  - net5.0;net48 + net6.0;net48 Out - 1.2.0.0 + 1.2.1.0 enable latest @@ -12,11 +12,6 @@ - - - ..\ArchiSteamFarm\ArchiSteamFarm\lib\SteamKit2.dll - - diff --git a/BoosterCreator/BoosterHandler.cs b/BoosterCreator/BoosterHandler.cs index 5843c13..4993d15 100644 --- a/BoosterCreator/BoosterHandler.cs +++ b/BoosterCreator/BoosterHandler.cs @@ -17,10 +17,10 @@ namespace BoosterCreator { internal sealed class BoosterHandler : IDisposable { private readonly Bot Bot; - private readonly ConcurrentDictionary GameIDs = new ConcurrentDictionary(); + private readonly ConcurrentDictionary GameIDs = new(); private readonly Timer BoosterTimer; - internal static ConcurrentDictionary BoosterHandlers = new ConcurrentDictionary(); + internal static ConcurrentDictionary BoosterHandlers = new(); internal const int DelayBetweenBots = 5; //5 minutes between bots @@ -32,12 +32,13 @@ internal sealed class BoosterHandler : IDisposable { return 1 + (index >= 0 ? index : botnames.Count); } - internal BoosterHandler([NotNull] Bot bot, IReadOnlyCollection gameIDs) { + internal BoosterHandler(Bot bot, IReadOnlyCollection gameIDs) { Bot = bot ?? throw new ArgumentNullException(nameof(bot)); foreach (uint gameID in gameIDs) { if (GameIDs.TryAdd(gameID, DateTime.Now.AddMinutes(GetBotIndex(bot) * DelayBetweenBots))) { bot.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Auto-attempt to make booster from " + gameID.ToString() + " is planned at " + GameIDs[gameID]!.Value.ToShortDateString() + " " + GameIDs[gameID]!.Value.ToShortTimeString())); - } else { + } + else { bot.ArchiLogger.LogGenericError("Unable to schedule next auto-attempt"); } } @@ -84,13 +85,13 @@ internal sealed class BoosterHandler : IDisposable { uint unTradableGooAmount = uint.Parse(gooAmounts[2].Value); IEnumerable? enumerableBoosters = JsonConvert.DeserializeObject>(info.Value); - if (enumerableBoosters==null) { + if (enumerableBoosters == null) { bot.ArchiLogger.LogNullError(nameof(enumerableBoosters)); return Commands.FormatBotResponse(bot, string.Format(Strings.ErrorParsingObject, nameof(enumerableBoosters))); } Dictionary boosterInfos = enumerableBoosters.ToDictionary(boosterInfo => boosterInfo.AppID); - StringBuilder response = new StringBuilder(); + StringBuilder response = new(); foreach (KeyValuePair gameID in gameIDs) { if (!gameID.Value.HasValue || DateTime.Compare(gameID.Value.Value, DateTime.Now) <= 0) { @@ -123,7 +124,8 @@ internal sealed class BoosterHandler : IDisposable { string timeFormat; if (!string.IsNullOrWhiteSpace(bi.AvailableAtTime) && char.IsDigit(bi.AvailableAtTime.Trim()[0])) { timeFormat = "d MMM @ h:mmtt"; - } else { + } + else { timeFormat = "MMM d @ h:mmtt"; } @@ -131,7 +133,8 @@ internal sealed class BoosterHandler : IDisposable { bot.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Crafting booster from " + gameID.Key.ToString() + " is not available now")); //Wait until specified time if (DateTime.TryParseExact(bi.AvailableAtTime, timeFormat, new CultureInfo("en-US"), DateTimeStyles.None, out DateTime availableAtTime)) { - } else { + } + else { bot.ArchiLogger.LogGenericInfo("Unable to parse time \"" + bi.AvailableAtTime + "\", please report this."); availableAtTime = DateTime.Now.AddHours(8); //fallback to 8 hours in case of error } @@ -145,8 +148,9 @@ internal sealed class BoosterHandler : IDisposable { uint nTp; if (unTradableGooAmount > 0) { - nTp = tradableGooAmount > bi.Price ? (uint) 1 : 3; - } else { + nTp = tradableGooAmount > bi.Price ? (uint)1 : 3; + } + else { nTp = 2; } Steam.BoostersResponse? result = await WebRequest.CreateBooster(bot, bi.AppID, bi.Series, nTp).ConfigureAwait(false); diff --git a/BoosterCreator/Commands.cs b/BoosterCreator/Commands.cs index 9b0f040..460be0c 100644 --- a/BoosterCreator/Commands.cs +++ b/BoosterCreator/Commands.cs @@ -11,14 +11,14 @@ namespace BoosterCreator { internal static class Commands { internal static async Task Response(Bot bot, ulong steamID, string message, string[] args) { - switch (args[0].ToUpperInvariant()) { - case "BOOSTER" when args.Length > 2: - return await ResponseBooster(steamID, args[1], args[2]).ConfigureAwait(false); - case "BOOSTER": - return await ResponseBooster(bot, steamID, args[1]).ConfigureAwait(false); - default: - return null; + if (string.IsNullOrEmpty(message)) { + return null; } + return args[0].ToUpperInvariant() switch { + "BOOSTER" when args.Length > 2 => await ResponseBooster(steamID, args[1], args[2]).ConfigureAwait(false), + "BOOSTER" => await ResponseBooster(bot, steamID, args[1]).ConfigureAwait(false), + _ => null, + }; } private static async Task ResponseBooster(Bot bot, ulong steamID, string targetGameIDs) { @@ -43,7 +43,7 @@ internal static class Commands { } - ConcurrentDictionary gamesToBooster = new ConcurrentDictionary(); + ConcurrentDictionary gamesToBooster = new(); //HashSet gamesToBooster = new HashSet(); foreach (string game in gameIDs) { @@ -72,7 +72,7 @@ internal static class Commands { IList results = await Utilities.InParallel(bots.Select(bot => ResponseBooster(bot, steamID, targetGameIDs))).ConfigureAwait(false); - List responses = new List(results.Where(result => !string.IsNullOrEmpty(result))); + List responses = new(results.Where(result => !string.IsNullOrEmpty(result))); return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null; } diff --git a/BoosterCreator/Json.cs b/BoosterCreator/Json.cs index 8d6c78d..48491c6 100644 --- a/BoosterCreator/Json.cs +++ b/BoosterCreator/Json.cs @@ -12,7 +12,6 @@ internal class EResultResponse { public EResultResponse() { } } - [SuppressMessage("ReSharper", "ClassCannotBeInstantiated")] internal sealed class BoosterInfo { [JsonProperty(PropertyName = "appid", Required = Required.Always)] internal readonly uint AppID; @@ -39,7 +38,7 @@ internal sealed class BoosterInfo { } } - [SuppressMessage("ReSharper", "ClassCannotBeInstantiated")] + internal sealed class BoostersResponse { [JsonProperty(PropertyName = "goo_amount", Required = Required.Always)] internal readonly uint GooAmount; @@ -54,9 +53,7 @@ internal sealed class BoostersResponse { internal readonly EResultResponse Result; [JsonConstructor] - private BoostersResponse() { - Result = new EResultResponse(); - } + private BoostersResponse() => Result = new EResultResponse(); } } } diff --git a/BoosterCreator/WebRequest.cs b/BoosterCreator/WebRequest.cs index 6801986..5b8276e 100644 --- a/BoosterCreator/WebRequest.cs +++ b/BoosterCreator/WebRequest.cs @@ -24,7 +24,7 @@ internal static class WebRequest { Uri request = new(ArchiWebHandler.SteamCommunityURL, "/tradingcards/ajaxcreatebooster"); // Extra entry for sessionID - Dictionary data = new Dictionary(4) { + Dictionary data = new(4) { { "appid", appID.ToString() }, { "series", series.ToString() }, { "tradability_preference", nTradabilityPreference.ToString() } diff --git a/build.bat b/build.bat index 64289d1..c723881 100644 --- a/build.bat +++ b/build.bat @@ -21,7 +21,7 @@ if exist out rmdir /Q /S out rem release generic version -dotnet publish -c "Release" -f "net5.0" -o "out/generic" "/p:LinkDuringPublish=false" +dotnet publish -c "Release" -f "net6.0" -o "out/generic" "/p:LinkDuringPublish=false" mkdir .\out\%CurrDirName% copy .\out\generic\%CurrDirName%.dll .\out\%CurrDirName% copy .\README.md .\out\%CurrDirName%