From e15045292f9a66bc956c15218ea97c68c90a33a5 Mon Sep 17 00:00:00 2001 From: Master Kwoth Date: Fri, 7 Jul 2017 15:45:21 +0200 Subject: [PATCH] Fixed embeds --- src/NadekoBot/DataStructures/CREmbed.cs | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/NadekoBot/DataStructures/CREmbed.cs b/src/NadekoBot/DataStructures/CREmbed.cs index c0bb37f9..b7519ebc 100644 --- a/src/NadekoBot/DataStructures/CREmbed.cs +++ b/src/NadekoBot/DataStructures/CREmbed.cs @@ -1,6 +1,7 @@ using Discord; using Newtonsoft.Json; using NLog; +using System; namespace NadekoBot.DataStructures { @@ -31,19 +32,26 @@ namespace NadekoBot.DataStructures public EmbedBuilder ToEmbed() { - var embed = new EmbedBuilder() - .WithTitle(Title) - .WithDescription(Description) - .WithColor(new Discord.Color(Color)); + var embed = new EmbedBuilder(); + + if (!string.IsNullOrWhiteSpace(Title)) + embed.WithTitle(Title); + if (!string.IsNullOrWhiteSpace(Description)) + embed.WithDescription(Description); + embed.WithColor(new Discord.Color(Color)); if (Footer != null) embed.WithFooter(efb => efb.WithIconUrl(Footer.IconUrl).WithText(Footer.Text)); - embed.WithThumbnailUrl(Thumbnail) - .WithImageUrl(Image); + + if (Thumbnail != null && Uri.IsWellFormedUriString(Thumbnail, UriKind.Absolute)) + embed.WithThumbnailUrl(Thumbnail); + if(Image != null && Uri.IsWellFormedUriString(Image, UriKind.Absolute)) + embed.WithImageUrl(Image); if (Fields != null) foreach (var f in Fields) { - embed.AddField(efb => efb.WithName(f.Name).WithValue(f.Value).WithIsInline(f.Inline)); + if(!string.IsNullOrWhiteSpace(f.Name) && !string.IsNullOrWhiteSpace(f.Value)) + embed.AddField(efb => efb.WithName(f.Name).WithValue(f.Value).WithIsInline(f.Inline)); } return embed;