|
|
@@ -2,6 +2,7 @@ using System; |
|
|
|
using System.Collections.Generic; |
|
|
|
using System.Collections.Immutable; |
|
|
|
using System.Linq; |
|
|
|
using Discord.Utils; |
|
|
|
|
|
|
|
namespace Discord |
|
|
|
{ |
|
|
@@ -401,25 +402,29 @@ namespace Discord |
|
|
|
/// The built embed object. |
|
|
|
/// </returns> |
|
|
|
/// <exception cref="InvalidOperationException">Total embed length exceeds <see cref="MaxEmbedLength"/>.</exception> |
|
|
|
/// <exception cref="InvalidOperationException">Any Url must be well formatted include its protocols (i.e http:// or https://).</exception> |
|
|
|
/// <exception cref="InvalidOperationException">Any Url must include its protocols (i.e http:// or https://).</exception> |
|
|
|
public Embed Build() |
|
|
|
{ |
|
|
|
if (Length > MaxEmbedLength) |
|
|
|
throw new InvalidOperationException($"Total embed length must be less than or equal to {MaxEmbedLength}."); |
|
|
|
if (!string.IsNullOrEmpty(Url) && !Uri.IsWellFormedUriString(Url, UriKind.Absolute)) |
|
|
|
throw new InvalidOperationException("Url must be well formatted and include its protocol (either HTTP or HTTPS)"); |
|
|
|
if (!string.IsNullOrEmpty(ThumbnailUrl) && !Uri.IsWellFormedUriString(ThumbnailUrl, UriKind.Absolute)) |
|
|
|
throw new InvalidOperationException("Thumbnail Url must be well formatted and include its protocol (either HTTP or HTTPS)"); |
|
|
|
if (!string.IsNullOrEmpty(ImageUrl) && !Uri.IsWellFormedUriString(ImageUrl, UriKind.Absolute)) |
|
|
|
throw new InvalidOperationException("Image Url must be well formatted and include its protocol (either HTTP or HTTPS)"); |
|
|
|
if (!string.IsNullOrEmpty(Url)) |
|
|
|
UrlValidation.Validate(Url); |
|
|
|
if (!string.IsNullOrEmpty(ThumbnailUrl)) |
|
|
|
UrlValidation.Validate(ThumbnailUrl); |
|
|
|
if (!string.IsNullOrEmpty(ImageUrl)) |
|
|
|
UrlValidation.Validate(ImageUrl); |
|
|
|
if (Author != null) |
|
|
|
{ |
|
|
|
if(!string.IsNullOrEmpty(Author.Url) && !Uri.IsWellFormedUriString(Author.Url, UriKind.Absolute)) |
|
|
|
throw new InvalidOperationException("Author Url must be well formatted and include its protocol (either HTTP or HTTPS)"); |
|
|
|
if (!string.IsNullOrEmpty(Author.IconUrl) && !Uri.IsWellFormedUriString(Author.IconUrl, UriKind.Absolute)) |
|
|
|
throw new InvalidOperationException("Author Icon Url must be well formatted and include its protocol (either HTTP or HTTPS)"); |
|
|
|
if (!string.IsNullOrEmpty(Author.Url)) |
|
|
|
UrlValidation.Validate(Author.Url); |
|
|
|
if (!string.IsNullOrEmpty(Author.IconUrl)) |
|
|
|
UrlValidation.Validate(Author.IconUrl); |
|
|
|
} |
|
|
|
if(Footer != null) |
|
|
|
{ |
|
|
|
if (!string.IsNullOrEmpty(Footer.IconUrl)) |
|
|
|
UrlValidation.Validate(Footer.IconUrl); |
|
|
|
} |
|
|
|
|
|
|
|
var fields = ImmutableArray.CreateBuilder<EmbedField>(Fields.Count); |
|
|
|
for (int i = 0; i < Fields.Count; i++) |
|
|
|
fields.Add(Fields[i].Build()); |
|
|
|