Reverted smarttext to newtonsoft to relax the allowed json rules. Upped version to 4.1.3

This commit is contained in:
Kwoth
2022-05-05 05:00:47 +02:00
parent 5b5bc278ff
commit 9a96ef76ba
2 changed files with 9 additions and 14 deletions

View File

@@ -1,5 +1,6 @@
#nullable disable
using System.Text.Json;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
namespace NadekoBot;
@@ -13,12 +14,6 @@ public abstract record SmartText
public bool IsEmbedArray
=> this is SmartEmbedTextArray;
private static readonly JsonSerializerOptions _opts = new JsonSerializerOptions()
{
PropertyNameCaseInsensitive = true,
PropertyNamingPolicy = JsonNamingPolicy.CamelCase
};
public static SmartText operator +(SmartText text, string input)
=> text switch
@@ -58,13 +53,13 @@ public abstract record SmartText
try
{
var doc = JsonDocument.Parse(input);
var root = doc.RootElement;
if (root.ValueKind == JsonValueKind.Object)
var doc = JObject.Parse(input);
var root = doc.Root;
if (root.Type == JTokenType.Object)
{
if (root.TryGetProperty("embeds", out _))
if (((JObject)root).TryGetValue("embeds", out _))
{
var arr = root.Deserialize<SmartEmbedTextArray>(_opts);
var arr = root.ToObject<SmartEmbedTextArray>();
if (arr is null)
return new SmartPlainText(input);
@@ -73,7 +68,7 @@ public abstract record SmartText
return arr;
}
var obj = root.Deserialize<SmartEmbedText>(_opts);
var obj = root.ToObject<SmartEmbedText>();
if (obj is null)
return new SmartPlainText(input);

View File

@@ -7,7 +7,7 @@ namespace NadekoBot.Services;
public sealed class StatsService : IStatsService, IReadyExecutor, INService
{
public const string BOT_VERSION = "4.1.2";
public const string BOT_VERSION = "4.1.3";
public string Author
=> "Kwoth#2452";