Add various property validation in EmbedBuilder (#711)

* Add various property validation in EmbedBuilder

* Embed URI changes

Changes property types for any URLs in Embeds to System.URI.
Adding field name/value null/empty checks.

* including property names in argumentexceptions

* Adds overall embed length check
This commit is contained in:
Pat Murphy
2017-06-23 07:29:55 -07:00
committed by RogueException
parent 5f04e2beba
commit 5601d00285
16 changed files with 163 additions and 69 deletions

View File

@@ -1,6 +1,7 @@
using System;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
namespace Discord
{
@@ -10,7 +11,7 @@ namespace Discord
public string Type { get; }
public string Description { get; internal set; }
public string Url { get; internal set; }
public Uri Url { get; internal set; }
public string Title { get; internal set; }
public DateTimeOffset? Timestamp { get; internal set; }
public Color? Color { get; internal set; }
@@ -30,7 +31,7 @@ namespace Discord
internal Embed(string type,
string title,
string description,
string url,
Uri url,
DateTimeOffset? timestamp,
Color? color,
EmbedImage? image,
@@ -56,6 +57,8 @@ namespace Discord
Fields = fields;
}
public int Length => Title?.Length + Author?.Name?.Length + Description?.Length + Footer?.Text?.Length + Fields.Sum(f => f.Name.Length + f.Value.ToString().Length) ?? 0;
public override string ToString() => Title;
private string DebuggerDisplay => $"{Title} ({Type})";
}

View File

@@ -1,4 +1,5 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
namespace Discord
{
@@ -6,11 +7,11 @@ namespace Discord
public struct EmbedAuthor
{
public string Name { get; internal set; }
public string Url { get; internal set; }
public string IconUrl { get; internal set; }
public string ProxyIconUrl { get; internal set; }
public Uri Url { get; internal set; }
public Uri IconUrl { get; internal set; }
public Uri ProxyIconUrl { get; internal set; }
internal EmbedAuthor(string name, string url, string iconUrl, string proxyIconUrl)
internal EmbedAuthor(string name, Uri url, Uri iconUrl, Uri proxyIconUrl)
{
Name = name;
Url = url;

View File

@@ -1,4 +1,5 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
namespace Discord
{
@@ -6,10 +7,10 @@ namespace Discord
public struct EmbedFooter
{
public string Text { get; internal set; }
public string IconUrl { get; internal set; }
public string ProxyUrl { get; internal set; }
public Uri IconUrl { get; internal set; }
public Uri ProxyUrl { get; internal set; }
internal EmbedFooter(string text, string iconUrl, string proxyUrl)
internal EmbedFooter(string text, Uri iconUrl, Uri proxyUrl)
{
Text = text;
IconUrl = iconUrl;

View File

@@ -1,16 +1,17 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
namespace Discord
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public struct EmbedImage
{
public string Url { get; }
public string ProxyUrl { get; }
public Uri Url { get; }
public Uri ProxyUrl { get; }
public int? Height { get; }
public int? Width { get; }
internal EmbedImage(string url, string proxyUrl, int? height, int? width)
internal EmbedImage(Uri url, Uri proxyUrl, int? height, int? width)
{
Url = url;
ProxyUrl = proxyUrl;
@@ -19,6 +20,6 @@ namespace Discord
}
private string DebuggerDisplay => $"{Url} ({(Width != null && Height != null ? $"{Width}x{Height}" : "0x0")})";
public override string ToString() => Url;
public override string ToString() => Url.ToString();
}
}

View File

@@ -1,4 +1,5 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
namespace Discord
{
@@ -6,9 +7,9 @@ namespace Discord
public struct EmbedProvider
{
public string Name { get; }
public string Url { get; }
public Uri Url { get; }
internal EmbedProvider(string name, string url)
internal EmbedProvider(string name, Uri url)
{
Name = name;
Url = url;

View File

@@ -1,16 +1,17 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
namespace Discord
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public struct EmbedThumbnail
{
public string Url { get; }
public string ProxyUrl { get; }
public Uri Url { get; }
public Uri ProxyUrl { get; }
public int? Height { get; }
public int? Width { get; }
internal EmbedThumbnail(string url, string proxyUrl, int? height, int? width)
internal EmbedThumbnail(Uri url, Uri proxyUrl, int? height, int? width)
{
Url = url;
ProxyUrl = proxyUrl;
@@ -19,6 +20,6 @@ namespace Discord
}
private string DebuggerDisplay => $"{Url} ({(Width != null && Height != null ? $"{Width}x{Height}" : "0x0")})";
public override string ToString() => Url;
public override string ToString() => Url.ToString();
}
}

View File

@@ -1,15 +1,16 @@
using System.Diagnostics;
using System;
using System.Diagnostics;
namespace Discord
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public struct EmbedVideo
{
public string Url { get; }
public Uri Url { get; }
public int? Height { get; }
public int? Width { get; }
internal EmbedVideo(string url, int? height, int? width)
internal EmbedVideo(Uri url, int? height, int? width)
{
Url = url;
Height = height;
@@ -17,6 +18,6 @@ namespace Discord
}
private string DebuggerDisplay => $"{Url} ({(Width != null && Height != null ? $"{Width}x{Height}" : "0x0")})";
public override string ToString() => Url;
public override string ToString() => Url.ToString();
}
}

View File

@@ -5,7 +5,7 @@ namespace Discord
{
public interface IEmbed
{
string Url { get; }
Uri Url { get; }
string Type { get; }
string Title { get; }
string Description { get; }