Skip to content

Commit

Permalink
update to net6.0 and tasks
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudokhvist committed Dec 14, 2021
1 parent 5c194d8 commit 996f06c
Show file tree
Hide file tree
Showing 8 changed files with 35 additions and 36 deletions.
2 changes: 1 addition & 1 deletion ArchiSteamFarm
Submodule ArchiSteamFarm updated 297 files
7 changes: 5 additions & 2 deletions BoosterCreator/BoosterCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string?> 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<string, JToken>? additionalConfigProperties = null) {
public async Task OnBotInitModules(Bot bot, IReadOnlyDictionary<string, JToken>? additionalConfigProperties = null) {
if (additionalConfigProperties == null) {
return;
}
Expand Down
9 changes: 2 additions & 7 deletions BoosterCreator/BoosterCreator.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFrameworks>net5.0;net48</TargetFrameworks>
<TargetFrameworks>net6.0;net48</TargetFrameworks>
<Authors>Out</Authors>
<AssemblyVersion>1.2.0.0</AssemblyVersion>
<AssemblyVersion>1.2.1.0</AssemblyVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand All @@ -12,11 +12,6 @@
<PackageReference Include="System.Composition.AttributedModel" Version="*" />
</ItemGroup>

<ItemGroup>
<Reference Include="SteamKit2">
<HintPath>..\ArchiSteamFarm\ArchiSteamFarm\lib\SteamKit2.dll</HintPath>
</Reference>
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\ArchiSteamFarm\ArchiSteamFarm\ArchiSteamFarm.csproj" />
</ItemGroup>
Expand Down
24 changes: 14 additions & 10 deletions BoosterCreator/BoosterHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@
namespace BoosterCreator {
internal sealed class BoosterHandler : IDisposable {
private readonly Bot Bot;
private readonly ConcurrentDictionary<uint, DateTime?> GameIDs = new ConcurrentDictionary<uint, DateTime?>();
private readonly ConcurrentDictionary<uint, DateTime?> GameIDs = new();
private readonly Timer BoosterTimer;

internal static ConcurrentDictionary<string, BoosterHandler?> BoosterHandlers = new ConcurrentDictionary<string, BoosterHandler?>();
internal static ConcurrentDictionary<string, BoosterHandler?> BoosterHandlers = new();

internal const int DelayBetweenBots = 5; //5 minutes between bots

Expand All @@ -32,12 +32,13 @@ internal sealed class BoosterHandler : IDisposable {
return 1 + (index >= 0 ? index : botnames.Count);
}

internal BoosterHandler([NotNull] Bot bot, IReadOnlyCollection<uint> gameIDs) {
internal BoosterHandler(Bot bot, IReadOnlyCollection<uint> 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");
}
}
Expand Down Expand Up @@ -84,13 +85,13 @@ internal sealed class BoosterHandler : IDisposable {
uint unTradableGooAmount = uint.Parse(gooAmounts[2].Value);

IEnumerable<Steam.BoosterInfo>? enumerableBoosters = JsonConvert.DeserializeObject<IEnumerable<Steam.BoosterInfo>>(info.Value);
if (enumerableBoosters==null) {
if (enumerableBoosters == null) {
bot.ArchiLogger.LogNullError(nameof(enumerableBoosters));
return Commands.FormatBotResponse(bot, string.Format(Strings.ErrorParsingObject, nameof(enumerableBoosters)));
}

Dictionary<uint, Steam.BoosterInfo> boosterInfos = enumerableBoosters.ToDictionary(boosterInfo => boosterInfo.AppID);
StringBuilder response = new StringBuilder();
StringBuilder response = new();

foreach (KeyValuePair<uint, DateTime?> gameID in gameIDs) {
if (!gameID.Value.HasValue || DateTime.Compare(gameID.Value.Value, DateTime.Now) <= 0) {
Expand Down Expand Up @@ -123,15 +124,17 @@ 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";
}

response.AppendLine(Commands.FormatBotResponse(bot, "Crafting booster from " + gameID.Key.ToString() + " will be available at time: " + bi.AvailableAtTime));
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
}
Expand All @@ -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);
Expand Down
18 changes: 9 additions & 9 deletions BoosterCreator/Commands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@
namespace BoosterCreator {
internal static class Commands {
internal static async Task<string?> 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<string?> ResponseBooster(Bot bot, ulong steamID, string targetGameIDs) {
Expand All @@ -43,7 +43,7 @@ internal static class Commands {
}


ConcurrentDictionary<uint, DateTime?> gamesToBooster = new ConcurrentDictionary<uint, DateTime?>();
ConcurrentDictionary<uint, DateTime?> gamesToBooster = new();
//HashSet<uint> gamesToBooster = new HashSet<uint>();

foreach (string game in gameIDs) {
Expand Down Expand Up @@ -72,7 +72,7 @@ internal static class Commands {

IList<string?> results = await Utilities.InParallel(bots.Select(bot => ResponseBooster(bot, steamID, targetGameIDs))).ConfigureAwait(false);

List<string?> responses = new List<string?>(results.Where(result => !string.IsNullOrEmpty(result)));
List<string?> responses = new(results.Where(result => !string.IsNullOrEmpty(result)));

return responses.Count > 0 ? string.Join(Environment.NewLine, responses) : null;
}
Expand Down
7 changes: 2 additions & 5 deletions BoosterCreator/Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -54,9 +53,7 @@ internal sealed class BoostersResponse {
internal readonly EResultResponse Result;

[JsonConstructor]
private BoostersResponse() {
Result = new EResultResponse();
}
private BoostersResponse() => Result = new EResultResponse();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion BoosterCreator/WebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ internal static class WebRequest {
Uri request = new(ArchiWebHandler.SteamCommunityURL, "/tradingcards/ajaxcreatebooster");

// Extra entry for sessionID
Dictionary<string, string> data = new Dictionary<string, string>(4) {
Dictionary<string, string> data = new(4) {
{ "appid", appID.ToString() },
{ "series", series.ToString() },
{ "tradability_preference", nTradabilityPreference.ToString() }
Expand Down
2 changes: 1 addition & 1 deletion build.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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%
Expand Down

0 comments on commit 996f06c

Please sign in to comment.