mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 09:18:27 -04:00
Fixed .showembed, closes #410
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
#nullable disable warnings
|
||||
using SixLabors.ImageSharp.PixelFormats;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace NadekoBot;
|
||||
|
||||
@@ -7,14 +8,14 @@ public sealed record SmartEmbedArrayElementText : SmartEmbedTextBase
|
||||
{
|
||||
public string Color { get; init; } = string.Empty;
|
||||
|
||||
public SmartEmbedArrayElementText() : base()
|
||||
public SmartEmbedArrayElementText()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public SmartEmbedArrayElementText(IEmbed eb) : base(eb)
|
||||
{
|
||||
|
||||
Color = eb.Color is { } c ? new Rgba32(c.R, c.G, c.B).ToHex() : string.Empty;
|
||||
}
|
||||
|
||||
protected override EmbedBuilder GetEmbedInternal()
|
||||
@@ -63,6 +64,7 @@ public abstract record SmartEmbedTextBase : SmartText
|
||||
public SmartTextEmbedFooter Footer { get; init; }
|
||||
public SmartTextEmbedField[] Fields { get; init; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool IsValid
|
||||
=> !string.IsNullOrWhiteSpace(Title)
|
||||
|| !string.IsNullOrWhiteSpace(Description)
|
||||
@@ -100,7 +102,7 @@ public abstract record SmartEmbedTextBase : SmartText
|
||||
IconUrl = ef.IconUrl
|
||||
}
|
||||
: null;
|
||||
|
||||
|
||||
if (eb.Fields.Length > 0)
|
||||
{
|
||||
Fields = eb.Fields.Select(field
|
||||
|
@@ -1,4 +1,6 @@
|
||||
#nullable disable
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace NadekoBot;
|
||||
|
||||
public sealed record SmartEmbedTextArray : SmartText
|
||||
@@ -6,6 +8,7 @@ public sealed record SmartEmbedTextArray : SmartText
|
||||
public string Content { get; set; }
|
||||
public SmartEmbedArrayElementText[] Embeds { get; set; }
|
||||
|
||||
[JsonIgnore]
|
||||
public bool IsValid
|
||||
=> Embeds?.All(x => x.IsValid) ?? false;
|
||||
|
||||
|
@@ -1,16 +1,20 @@
|
||||
#nullable disable
|
||||
using Newtonsoft.Json.Linq;
|
||||
using System.Text.Json.Serialization;
|
||||
|
||||
namespace NadekoBot;
|
||||
|
||||
public abstract record SmartText
|
||||
{
|
||||
[JsonIgnore]
|
||||
public bool IsEmbed
|
||||
=> this is SmartEmbedText;
|
||||
|
||||
[JsonIgnore]
|
||||
public bool IsPlainText
|
||||
=> this is SmartPlainText;
|
||||
|
||||
[JsonIgnore]
|
||||
public bool IsEmbedArray
|
||||
=> this is SmartEmbedTextArray;
|
||||
|
||||
|
@@ -550,15 +550,20 @@ public partial class Utility : NadekoModule
|
||||
return;
|
||||
}
|
||||
|
||||
var embed = msg.Embeds.FirstOrDefault();
|
||||
if (embed is null)
|
||||
if (!msg.Embeds.Any())
|
||||
{
|
||||
await ReplyErrorLocalizedAsync(strs.not_found);
|
||||
return;
|
||||
}
|
||||
|
||||
var json = SmartEmbedText.FromEmbed(embed, msg.Content).ToJson(_showEmbedSerializerOptions);
|
||||
await SendConfirmAsync(Format.Sanitize(json).Replace("](", "]\\("));
|
||||
var json = new SmartEmbedTextArray()
|
||||
{
|
||||
Content = msg.Content,
|
||||
Embeds = msg.Embeds
|
||||
.Map(x => new SmartEmbedArrayElementText(x))
|
||||
}.ToJson(_showEmbedSerializerOptions);
|
||||
|
||||
await SendConfirmAsync(Format.Code(json, "json").Replace("](", "]\\("));
|
||||
}
|
||||
|
||||
[Cmd]
|
||||
|
Reference in New Issue
Block a user