mirror of
https://gitlab.com/Kwoth/nadekobot.git
synced 2025-09-10 17:28:27 -04:00
Fixed plaintext-only embeds. closes #360
This commit is contained in:
@@ -1,6 +1,6 @@
|
|||||||
using SixLabors.ImageSharp.PixelFormats;
|
#nullable disable warnings
|
||||||
|
using SixLabors.ImageSharp.PixelFormats;
|
||||||
|
|
||||||
#nullable disable
|
|
||||||
namespace NadekoBot;
|
namespace NadekoBot;
|
||||||
|
|
||||||
public sealed record SmartEmbedArrayElementText : SmartEmbedTextBase
|
public sealed record SmartEmbedArrayElementText : SmartEmbedTextBase
|
||||||
@@ -37,11 +37,11 @@ public sealed record SmartEmbedText : SmartEmbedTextBase
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private SmartEmbedText(IEmbed eb, string plainText = null)
|
private SmartEmbedText(IEmbed eb, string? plainText = null)
|
||||||
: base(eb)
|
: base(eb)
|
||||||
=> (PlainText, Color) = (plainText, eb.Color?.RawValue ?? 0);
|
=> (PlainText, Color) = (plainText, eb.Color?.RawValue ?? 0);
|
||||||
|
|
||||||
public static SmartEmbedText FromEmbed(IEmbed eb, string plainText = null)
|
public static SmartEmbedText FromEmbed(IEmbed eb, string? plainText = null)
|
||||||
=> new(eb, plainText);
|
=> new(eb, plainText);
|
||||||
|
|
||||||
protected override EmbedBuilder GetEmbedInternal()
|
protected override EmbedBuilder GetEmbedInternal()
|
||||||
|
@@ -14,7 +14,10 @@ public sealed record SmartEmbedTextArray : SmartText
|
|||||||
if (Embeds is null)
|
if (Embeds is null)
|
||||||
return Array.Empty<EmbedBuilder>();
|
return Array.Empty<EmbedBuilder>();
|
||||||
|
|
||||||
return Embeds.Map(em => em.GetEmbed());
|
return Embeds
|
||||||
|
.Where(x => x.IsValid)
|
||||||
|
.Select(em => em.GetEmbed())
|
||||||
|
.ToArray();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void NormalizeFields()
|
public void NormalizeFields()
|
||||||
|
@@ -68,7 +68,7 @@ public abstract record SmartText
|
|||||||
|
|
||||||
var obj = root.ToObject<SmartEmbedText>();
|
var obj = root.ToObject<SmartEmbedText>();
|
||||||
|
|
||||||
if (obj is null)
|
if (obj is null || !(obj.IsValid || !string.IsNullOrWhiteSpace(obj.PlainText)))
|
||||||
return new SmartPlainText(input);
|
return new SmartPlainText(input);
|
||||||
|
|
||||||
obj.NormalizeFields();
|
obj.NormalizeFields();
|
||||||
|
@@ -21,7 +21,7 @@ public static class Extensions
|
|||||||
{
|
{
|
||||||
SmartEmbedText set => msg.ModifyAsync(x =>
|
SmartEmbedText set => msg.ModifyAsync(x =>
|
||||||
{
|
{
|
||||||
x.Embed = set.GetEmbed().Build();
|
x.Embed = set.IsValid ? set.GetEmbed().Build() : null;
|
||||||
x.Content = set.PlainText?.SanitizeMentions() ?? "";
|
x.Content = set.PlainText?.SanitizeMentions() ?? "";
|
||||||
}),
|
}),
|
||||||
SmartEmbedTextArray set => msg.ModifyAsync(x =>
|
SmartEmbedTextArray set => msg.ModifyAsync(x =>
|
||||||
|
@@ -54,7 +54,7 @@ public static class MessageChannelExtensions
|
|||||||
=> text switch
|
=> text switch
|
||||||
{
|
{
|
||||||
SmartEmbedText set => channel.SendAsync(set.PlainText,
|
SmartEmbedText set => channel.SendAsync(set.PlainText,
|
||||||
set.GetEmbed().Build(),
|
set.IsValid ? set.GetEmbed().Build() : null,
|
||||||
sanitizeAll: sanitizeAll),
|
sanitizeAll: sanitizeAll),
|
||||||
SmartPlainText st => channel.SendAsync(st.Text,
|
SmartPlainText st => channel.SendAsync(st.Text,
|
||||||
default(Embed),
|
default(Embed),
|
||||||
|
@@ -36,7 +36,7 @@ public static class SocketMessageComponentExtensions
|
|||||||
=> text switch
|
=> text switch
|
||||||
{
|
{
|
||||||
SmartEmbedText set => smc.RespondAsync(set.PlainText,
|
SmartEmbedText set => smc.RespondAsync(set.PlainText,
|
||||||
set.GetEmbed().Build(),
|
set.IsValid ? set.GetEmbed().Build() : null,
|
||||||
sanitizeAll: sanitizeAll,
|
sanitizeAll: sanitizeAll,
|
||||||
ephemeral: ephemeral),
|
ephemeral: ephemeral),
|
||||||
SmartPlainText st => smc.RespondAsync(st.Text,
|
SmartPlainText st => smc.RespondAsync(st.Text,
|
||||||
|
Reference in New Issue
Block a user