mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-13 10:48:26 -04:00
Made .showembed always output lowercase field names and no null values
This commit is contained in:
@@ -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();
|
||||||
|
}
|
||||||
|
}
|
@@ -11,11 +11,14 @@ using System.Diagnostics;
|
|||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Threading;
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NadekoBot.Common.Replacements;
|
using NadekoBot.Common.Replacements;
|
||||||
using NadekoBot.Services;
|
using NadekoBot.Services;
|
||||||
using Serilog;
|
using Serilog;
|
||||||
|
using SystemTextJsonSamples;
|
||||||
|
using JsonSerializer = Newtonsoft.Json.JsonSerializer;
|
||||||
|
|
||||||
namespace NadekoBot.Modules.Utility
|
namespace NadekoBot.Modules.Utility
|
||||||
{
|
{
|
||||||
@@ -368,6 +371,13 @@ namespace NadekoBot.Modules.Utility
|
|||||||
public Task ShowEmbed(ulong messageId)
|
public Task ShowEmbed(ulong messageId)
|
||||||
=> ShowEmbed((ITextChannel)ctx.Channel, messageId);
|
=> ShowEmbed((ITextChannel)ctx.Channel, messageId);
|
||||||
|
|
||||||
|
private static readonly JsonSerializerOptions _showEmbedSerializerOptions = new JsonSerializerOptions()
|
||||||
|
{
|
||||||
|
WriteIndented = true,
|
||||||
|
IgnoreNullValues = true,
|
||||||
|
PropertyNamingPolicy = LowerCaseNamingPolicy.Default
|
||||||
|
};
|
||||||
|
|
||||||
[NadekoCommand, Aliases]
|
[NadekoCommand, Aliases]
|
||||||
[RequireContext(ContextType.Guild)]
|
[RequireContext(ContextType.Guild)]
|
||||||
public async Task ShowEmbed(ITextChannel ch, ulong messageId)
|
public async Task ShowEmbed(ITextChannel ch, ulong messageId)
|
||||||
@@ -394,7 +404,7 @@ namespace NadekoBot.Modules.Utility
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var json = SmartEmbedText.FromEmbed(embed, msg.Content).ToJson();
|
var json = SmartEmbedText.FromEmbed(embed, msg.Content).ToJson(_showEmbedSerializerOptions);
|
||||||
await SendConfirmAsync(Format.Sanitize(json).Replace("](", "]\\("));
|
await SendConfirmAsync(Format.Sanitize(json).Replace("](", "]\\("));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -22,10 +22,12 @@ using System.Linq;
|
|||||||
using System.Net.Http;
|
using System.Net.Http;
|
||||||
using System.Net.Http.Headers;
|
using System.Net.Http.Headers;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.Json;
|
||||||
using System.Text.RegularExpressions;
|
using System.Text.RegularExpressions;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using NadekoBot.Common.Attributes;
|
using NadekoBot.Common.Attributes;
|
||||||
using Color = Discord.Color;
|
using Color = Discord.Color;
|
||||||
|
using JsonSerializer = System.Text.Json.JsonSerializer;
|
||||||
|
|
||||||
namespace NadekoBot.Extensions
|
namespace NadekoBot.Extensions
|
||||||
{
|
{
|
||||||
@@ -286,8 +288,8 @@ namespace NadekoBot.Extensions
|
|||||||
public static async Task<IEnumerable<IGuildUser>> GetMembersAsync(this IRole role) =>
|
public static async Task<IEnumerable<IGuildUser>> GetMembersAsync(this IRole role) =>
|
||||||
(await role.Guild.GetUsersAsync(CacheMode.CacheOnly).ConfigureAwait(false)).Where(u => u.RoleIds.Contains(role.Id)) ?? Enumerable.Empty<IGuildUser>();
|
(await role.Guild.GetUsersAsync(CacheMode.CacheOnly).ConfigureAwait(false)).Where(u => u.RoleIds.Contains(role.Id)) ?? Enumerable.Empty<IGuildUser>();
|
||||||
|
|
||||||
public static string ToJson<T>(this T any, Formatting formatting = Formatting.Indented) =>
|
public static string ToJson<T>(this T any, JsonSerializerOptions options = null) =>
|
||||||
JsonConvert.SerializeObject(any, formatting);
|
JsonSerializer.Serialize(any, options);
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Adds fallback fonts to <see cref="TextOptions"/>
|
/// Adds fallback fonts to <see cref="TextOptions"/>
|
||||||
|
Reference in New Issue
Block a user