Made .showembed always output lowercase field names and no null values

This commit is contained in:
Kwoth
2021-12-14 19:41:07 +01:00
parent 9be8140d4d
commit 83daf3c30f
3 changed files with 27 additions and 3 deletions

View File

@@ -0,0 +1,12 @@
using System.Text.Json;
namespace SystemTextJsonSamples
{
public class LowerCaseNamingPolicy : JsonNamingPolicy
{
public static LowerCaseNamingPolicy Default = new LowerCaseNamingPolicy();
public override string ConvertName(string name) =>
name.ToLower();
}
}

View File

@@ -11,11 +11,14 @@ using System.Diagnostics;
using System.Linq;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using NadekoBot.Common.Replacements;
using NadekoBot.Services;
using Serilog;
using SystemTextJsonSamples;
using JsonSerializer = Newtonsoft.Json.JsonSerializer;
namespace NadekoBot.Modules.Utility
{
@@ -368,6 +371,13 @@ namespace NadekoBot.Modules.Utility
public Task ShowEmbed(ulong messageId)
=> ShowEmbed((ITextChannel)ctx.Channel, messageId);
private static readonly JsonSerializerOptions _showEmbedSerializerOptions = new JsonSerializerOptions()
{
WriteIndented = true,
IgnoreNullValues = true,
PropertyNamingPolicy = LowerCaseNamingPolicy.Default
};
[NadekoCommand, Aliases]
[RequireContext(ContextType.Guild)]
public async Task ShowEmbed(ITextChannel ch, ulong messageId)
@@ -394,7 +404,7 @@ namespace NadekoBot.Modules.Utility
return;
}
var json = SmartEmbedText.FromEmbed(embed, msg.Content).ToJson();
var json = SmartEmbedText.FromEmbed(embed, msg.Content).ToJson(_showEmbedSerializerOptions);
await SendConfirmAsync(Format.Sanitize(json).Replace("](", "]\\("));
}