Skip to content

Commit

Permalink
misc ASF -> 6.0.0.3
Browse files Browse the repository at this point in the history
  • Loading branch information
chr233 committed Mar 10, 2024
1 parent 8b9d4d9 commit 5b75ea1
Show file tree
Hide file tree
Showing 53 changed files with 400 additions and 433 deletions.
31 changes: 17 additions & 14 deletions ASFEnhance/ASFEnhance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
using ArchiSteamFarm.Plugins.Interfaces;
using ArchiSteamFarm.Steam;
using ASFEnhance.Data.Plugin;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using System.ComponentModel;
using System.Composition;
using System.Text;
using System.Text.Json;
using System.Text.Json.Serialization;

namespace ASFEnhance;

Expand All @@ -17,7 +17,7 @@ internal sealed class ASFEnhance : IASF, IBotCommand2, IBotFriendRequest

public Version Version => MyVersion;

[JsonProperty]
[JsonInclude]
public static PluginConfig Config => Utils.Config;

private Timer? StatisticTimer { get; set; }
Expand All @@ -29,7 +29,7 @@ internal sealed class ASFEnhance : IASF, IBotCommand2, IBotFriendRequest
/// </summary>
/// <param name="additionalConfigProperties"></param>
/// <returns></returns>
public Task OnASFInit(IReadOnlyDictionary<string, JToken>? additionalConfigProperties = null)
public Task OnASFInit(IReadOnlyDictionary<string, JsonElement>? additionalConfigProperties = null)
{
var message = new StringBuilder("\n");
message.AppendLine(Static.Line);
Expand Down Expand Up @@ -68,11 +68,11 @@ public Task OnASFInit(IReadOnlyDictionary<string, JToken>? additionalConfigPrope
{
foreach (var (configProperty, configValue) in additionalConfigProperties)
{
if (configProperty == "ASFEnhance" && configValue.Type == JTokenType.Object)
if (configProperty == "ASFEnhance" && configValue.ValueKind == JsonValueKind.Object)
{
try
{
config = configValue.ToObject<PluginConfig>();
config = configValue.Deserialize<PluginConfig>();
if (config != null)
{
break;
Expand Down Expand Up @@ -1096,7 +1096,7 @@ public Task OnLoaded()
}
catch (Exception ex) //错误日志
{
var cfg = JsonConvert.SerializeObject(Config, Formatting.Indented);
var cfg = JsonSerializer.Serialize(Config, DebugJsonOptions);

var sb = new StringBuilder();
sb.AppendLine(Langs.ErrorLogTitle);
Expand Down Expand Up @@ -1132,14 +1132,17 @@ public Task OnLoaded()
/// <exception cref="NotImplementedException"></exception>
public Task<bool> OnBotFriendRequest(Bot bot, ulong steamId)
{
var bots = Bot.GetBots("ASF")?.Select(static b => b.SteamID).ToList();
bool approve = bots?.Contains(steamId) ?? false;

if (approve)
if (Bot.BotsReadOnly != null)
{
ASFLogger.LogGenericInfo(string.Format(Langs.AcceptFriendRequest, bot.BotName, steamId));
foreach (var (_, b) in Bot.BotsReadOnly)
{
if (b.SteamID == steamId)
{
ASFLogger.LogGenericInfo(string.Format(Langs.AcceptFriendRequest, bot.BotName, steamId));
return Task.FromResult(true);
}
}
}

return Task.FromResult(approve);
return Task.FromResult(false);
}
}
5 changes: 4 additions & 1 deletion ASFEnhance/ASFEnhance.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
<ItemGroup>
<PackageReference Include="AngleSharp.XPath" />
<PackageReference Include="ConfigureAwaitChecker.Analyzer" PrivateAssets="all" />
<PackageReference Include="Newtonsoft.Json" IncludeAssets="compile" />
<PackageReference Include="SteamKit2" IncludeAssets="compile" />
<PackageReference Include="Swashbuckle.AspNetCore.Annotations" />
<PackageReference Include="System.Composition.AttributedModel" />
Expand Down Expand Up @@ -50,6 +49,10 @@
<Static>True</Static>
</Using>
</ItemGroup>

<ItemGroup>
<Folder Include="Data\新文件夹\" />
</ItemGroup>

<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Copy SourceFiles="$(TargetPath)" DestinationFolder="..\ArchiSteamFarm\ArchiSteamFarm\bin\$(Configuration)\$(TargetFramework)\plugins\" SkipUnchangedFiles="true" />
Expand Down
6 changes: 3 additions & 3 deletions ASFEnhance/Account/HtmlParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@
using ArchiSteamFarm.Web.Responses;
using ASFEnhance.Data;
using ASFEnhance.Data.Plugin;
using Newtonsoft.Json;
using System.Globalization;
using System.Text;
using System.Text.Json;
using static ASFEnhance.Account.CurrencyHelper;

namespace ASFEnhance.Account;
Expand Down Expand Up @@ -34,7 +34,7 @@ internal static class HtmlParser
content = match.Groups[1].Value;
try
{
var cursorData = JsonConvert.DeserializeObject<AccountHistoryResponse.CursorData>(content);
var cursorData = JsonSerializer.Deserialize<AccountHistoryResponse.CursorData>(content, JsonOptions);
return cursorData;
}
catch
Expand Down Expand Up @@ -423,7 +423,7 @@ decimal ParseMoneyString(string strMoney)
}
try
{
var optionsList = JsonConvert.DeserializeObject<List<NotificationPayload>>(payload);
var optionsList = JsonSerializer.Deserialize<List<NotificationPayload>>(payload, JsonOptions);
if (optionsList == null)
{
return null;
Expand Down
4 changes: 2 additions & 2 deletions ASFEnhance/Account/WebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
using ArchiSteamFarm.Web.Responses;
using ASFEnhance.Data;
using ASFEnhance.Data.Plugin;
using Newtonsoft.Json;
using System.Net;
using System.Text;
using System.Text.Json;
using static ASFEnhance.Account.CurrencyHelper;

namespace ASFEnhance.Account;
Expand Down Expand Up @@ -300,7 +300,7 @@ internal static async Task<bool> RemoveLicense(Bot bot, uint subId)
new(NotificationType.SteamTurnNotification,option.SteamTurnNotification),
};

var json = JsonConvert.SerializeObject(optionList, JsonOptions);
var json = JsonSerializer.Serialize(optionList, JsonOptions);

var data = new Dictionary<string, string>(11) {
{ "notificationpreferences", json },
Expand Down
6 changes: 3 additions & 3 deletions ASFEnhance/Cart/Command.cs
Original file line number Diff line number Diff line change
Expand Up @@ -750,7 +750,7 @@ internal static class Command
return bot.FormatBotResponse(Langs.PurchaseCartTransIDIsNull);
}

var response3 = await WebRequest.GetFinalPrice(bot, transId, false).ConfigureAwait(false);
var response3 = await WebRequest.GetFinalPrice(bot, transId).ConfigureAwait(false);

if (response3 == null || response2?.TransId == null)
{
Expand Down Expand Up @@ -843,7 +843,7 @@ internal static class Command
return bot.FormatBotResponse(Langs.PurchaseCartTransIDIsNull);
}

var response3 = await WebRequest.GetFinalPrice(bot, transId, false).ConfigureAwait(false);
var response3 = await WebRequest.GetFinalPrice(bot, transId).ConfigureAwait(false);

if (response3 == null || response2?.TransId == null)
{
Expand Down Expand Up @@ -1006,7 +1006,7 @@ internal static class Command
return botA.FormatBotResponse(Langs.PurchaseCartTransIDIsNull);
}

var __ = await WebRequest.GetFinalPrice(botA, transId, true).ConfigureAwait(false);
var __ = await WebRequest.GetFinalPrice(botA, transId).ConfigureAwait(false);

var response4 = await WebRequest.GetExternalPaymentUrl(botA, transId).ConfigureAwait(false);

Expand Down
11 changes: 5 additions & 6 deletions ASFEnhance/Cart/WebRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,7 @@
using ASFEnhance.Data.Common;
using ASFEnhance.Data.IAccountCartService;
using ASFEnhance.Data.Plugin;
using Newtonsoft.Json;

using System.Text.Json;
namespace ASFEnhance.Cart;

internal static class WebRequest
Expand Down Expand Up @@ -73,7 +72,7 @@ internal static class WebRequest
},
};

var json = JsonConvert.SerializeObject(payload, JsonOptions);
var json = JsonSerializer.Serialize(payload, JsonOptions);
var token = bot.AccessToken ?? throw new AccessTokenNullException();
var request = new Uri(SteamApiURL, $"/IAccountCartService/AddItemsToCart/v1/?access_token={token}");
var data = new Dictionary<string, string>
Expand Down Expand Up @@ -118,7 +117,7 @@ internal static class WebRequest
},
};

var json = JsonConvert.SerializeObject(payload, JsonOptions);
var json = JsonSerializer.Serialize(payload, JsonOptions);
var token = bot.AccessToken ?? throw new AccessTokenNullException();
var request = new Uri(SteamApiURL, $"/IAccountCartService/AddItemsToCart/v1/?access_token={token}");
var data = new Dictionary<string, string>
Expand Down Expand Up @@ -154,7 +153,7 @@ internal static class WebRequest
},
};

var json = JsonConvert.SerializeObject(payload, JsonOptions);
var json = JsonSerializer.Serialize(payload, JsonOptions);
var token = bot.AccessToken ?? throw new AccessTokenNullException();
var request = new Uri(SteamApiURL, $"/IAccountCartService/ModifyLineItem/v1/?access_token={token}");
var data = new Dictionary<string, string>
Expand Down Expand Up @@ -357,7 +356,7 @@ internal static async Task<bool> CartSetCountry(this Bot bot, string countryCode
/// <param name="TransId"></param>
/// <param name="asGift"></param>
/// <returns></returns>
internal static async Task<FinalPriceResponse?> GetFinalPrice(this Bot bot, string TransId, bool asGift = false)
internal static async Task<FinalPriceResponse?> GetFinalPrice(this Bot bot, string TransId)
{
var request = new Uri(SteamCheckoutURL, $"/checkout/getfinalprice/?count=1&transid={TransId}&purchasetype=self&microtxnid=-1&cart=-1&gidReplayOfTransID=-1");
var referer = new Uri(SteamCheckoutURL, "/checkout/");
Expand Down
4 changes: 2 additions & 2 deletions ASFEnhance/Curator/HtmlParser.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using ASFEnhance.Data;
using Newtonsoft.Json;
using System.Text.Json;
using System.Text.RegularExpressions;

namespace ASFEnhance.Curator;
Expand All @@ -25,7 +25,7 @@ internal static class HtmlParser
try
{
string jsonStr = match.Groups[1].Value;
var data = JsonConvert.DeserializeObject<HashSet<CuratorItem>>(jsonStr);
var data = JsonSerializer.Deserialize<HashSet<CuratorItem>>(jsonStr, JsonOptions);
return data;
}
catch (Exception ex)
Expand Down
4 changes: 2 additions & 2 deletions ASFEnhance/Data/AbstractResponse.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace ASFEnhance.Data;
/// <summary>
Expand All @@ -10,7 +10,7 @@ public record AbstractResponse<T> where T : notnull
/// <summary>
/// 响应
/// </summary>
[JsonProperty("response")]
[JsonPropertyName("response")]
public T? Response { get; set; }
}

Expand Down
14 changes: 7 additions & 7 deletions ASFEnhance/Data/AccountHistoryResponse.cs
Original file line number Diff line number Diff line change
@@ -1,27 +1,27 @@
using Newtonsoft.Json;
using System.Text.Json.Serialization;

namespace ASFEnhance.Data;

internal sealed record AccountHistoryResponse
{
[JsonProperty(PropertyName = "html", Required = Required.Always)]
[JsonPropertyName("html")]
public string HtmlContent { get; set; } = "";

[JsonProperty(PropertyName = "cursor", Required = Required.DisallowNull)]
[JsonPropertyName("cursor")]
public CursorData Cursor { get; set; } = new();

internal sealed record CursorData
{
[JsonProperty("wallet_txnid", Required = Required.Always)]
[JsonPropertyName("wallet_txnid")]
public string WalletTxnid { get; set; } = "";

[JsonProperty("timestamp_newest", Required = Required.Always)]
[JsonPropertyName("timestamp_newest")]
public long TimestampNewest { get; set; }

[JsonProperty("balance", Required = Required.Always)]
[JsonPropertyName("balance")]
public string Balance { get; set; } = "";

[JsonProperty("currency", Required = Required.Always)]
[JsonPropertyName("currency")]
public int Currency { get; set; }
}
}

0 comments on commit 5b75ea1

Please sign in to comment.