Skip to content

Commit

Permalink
fix incorrect json objects. Hopefully I didn't miss anything.
Browse files Browse the repository at this point in the history
  • Loading branch information
Rudokhvist committed Mar 11, 2024
1 parent 4095f96 commit aab65b7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 13 deletions.
2 changes: 1 addition & 1 deletion BoosterCreator/BoosterCreator.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<Authors>Out</Authors>
<AssemblyVersion>2.0.0.0</AssemblyVersion>
<AssemblyVersion>2.0.0.1</AssemblyVersion>
<Nullable>enable</Nullable>
<LangVersion>latest</LangVersion>
</PropertyGroup>
Expand Down
19 changes: 14 additions & 5 deletions BoosterCreator/BoosterHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
using System.Text.Json.Serialization;
using System.Text.Json;
using ArchiSteamFarm.Helpers.Json;
using System.Collections.ObjectModel;

namespace BoosterCreator {
internal sealed class BoosterHandler : IDisposable {
Expand Down Expand Up @@ -85,7 +86,7 @@ internal sealed class BoosterHandler : IDisposable {
uint tradableGooAmount = uint.Parse(gooAmounts[1].Value);
uint unTradableGooAmount = uint.Parse(gooAmounts[2].Value);

IEnumerable<Steam.BoosterInfo>? enumerableBoosters = info.Value.ToJsonObject<IEnumerable<Steam.BoosterInfo>>();
IEnumerable<Steam.BoosterInfo>? enumerableBoosters = info.Value.ToJsonObject<Collection<Steam.BoosterInfo>>();
if (enumerableBoosters == null) {
bot.ArchiLogger.LogNullError(enumerableBoosters);
return Commands.FormatBotResponse(bot, string.Format(Strings.ErrorParsingObject, nameof(enumerableBoosters)));
Expand All @@ -108,7 +109,13 @@ internal sealed class BoosterHandler : IDisposable {
continue;
}
Steam.BoosterInfo bi = boosterInfos[gameID.Key];
if (gooAmount < bi.Price) {

if (!uint.TryParse(bi.Price, out uint gemPrice)) {
response.AppendLine(Commands.FormatBotResponse(bot, "Failed to create booster from " + gameID.Key.ToString()));
continue;
}

if (gooAmount < gemPrice) {
response.AppendLine(Commands.FormatBotResponse(bot, "Not enough gems to create booster from " + gameID.Key.ToString()));
//If we have not enough gems - wait 8 hours, just in case gems will be added to account later
bot.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Not enough gems to create booster from " + gameID.Key.ToString()));
Expand Down Expand Up @@ -154,10 +161,11 @@ internal sealed class BoosterHandler : IDisposable {
uint nTp;

if (unTradableGooAmount > 0) {
nTp = tradableGooAmount > bi.Price ? (uint) 1 : 3;
nTp = tradableGooAmount > gemPrice ? (uint) 1 : 3;
} else {
nTp = 2;
}

Steam.BoostersResponse? result = await WebRequest.CreateBooster(bot, bi.AppID, bi.Series, nTp).ConfigureAwait(false);
if (result?.Result?.Result != EResult.OK) {
response.AppendLine(Commands.FormatBotResponse(bot, "Failed to create booster from " + gameID.Key.ToString()));
Expand All @@ -169,8 +177,9 @@ internal sealed class BoosterHandler : IDisposable {
}
continue;
}
gooAmount = result.GooAmount;
tradableGooAmount = result.TradableGooAmount;

gooAmount = uint.Parse(result.GooAmount!);
tradableGooAmount = uint.Parse(result.TradableGooAmount!);
unTradableGooAmount = result.UntradableGooAmount;
response.AppendLine(Commands.FormatBotResponse(bot, "Successfuly created booster from " + gameID.Key.ToString()));
bot.ArchiLogger.LogGenericInfo(Commands.FormatBotResponse(bot, "Successfuly created booster from " + gameID.Key.ToString()));
Expand Down
13 changes: 6 additions & 7 deletions BoosterCreator/Json.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
using System.Text.Json.Serialization;
using ArchiSteamFarm.Helpers.Json;
using SteamKit2;
#pragma warning disable 649

namespace BoosterCreator {
internal static class Steam {
internal class Steam {
internal class EResultResponse {
[JsonInclude]
[JsonPropertyName("success")]
Expand Down Expand Up @@ -34,20 +34,19 @@ internal sealed class BoosterInfo {
[JsonInclude]
[JsonPropertyName("price")]
[JsonRequired]
internal uint Price { get; private init; }
internal string Price { get; private init; }

[JsonInclude]
[JsonPropertyName("unavailable")]
[JsonRequired]
internal bool Unavailable { get; private init; }

[JsonInclude]
[JsonPropertyName("available_at_time")]
[JsonRequired]
internal string AvailableAtTime { get; private init; }

[JsonConstructor]
private BoosterInfo() {
Price = "";
Name = "";
AvailableAtTime = "";
}
Expand All @@ -58,12 +57,12 @@ internal sealed class BoostersResponse {
[JsonInclude]
[JsonPropertyName("goo_amount")]
[JsonRequired]
internal uint GooAmount { get; private init; }
internal string? GooAmount { get; private init; }

[JsonInclude]
[JsonPropertyName("tradable_goo_amount")]
[JsonRequired]
internal uint TradableGooAmount { get; private init; }
internal string? TradableGooAmount { get; private init; }

[JsonInclude]
[JsonPropertyName("untradable_goo_amount")]
Expand Down

0 comments on commit aab65b7

Please sign in to comment.