Changes property types for any URLs in Embeds to System.URI. Adding field name/value null/empty checks.pull/711/head
| @@ -10,7 +10,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 +30,7 @@ namespace Discord | |||
| internal Embed(string type, | |||
| string title, | |||
| string description, | |||
| string url, | |||
| Uri url, | |||
| DateTimeOffset? timestamp, | |||
| Color? color, | |||
| EmbedImage? image, | |||
| @@ -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; | |||
| @@ -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; | |||
| @@ -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(); | |||
| } | |||
| } | |||
| @@ -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; | |||
| @@ -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(); | |||
| } | |||
| } | |||
| @@ -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(); | |||
| } | |||
| } | |||
| @@ -5,7 +5,7 @@ namespace Discord | |||
| { | |||
| public interface IEmbed | |||
| { | |||
| string Url { get; } | |||
| Uri Url { get; } | |||
| string Type { get; } | |||
| string Title { get; } | |||
| string Description { get; } | |||
| @@ -13,7 +13,7 @@ namespace Discord.API | |||
| [JsonProperty("description")] | |||
| public string Description { get; set; } | |||
| [JsonProperty("url")] | |||
| public string Url { get; set; } | |||
| public Uri Url { get; set; } | |||
| [JsonProperty("color")] | |||
| public uint? Color { get; set; } | |||
| [JsonProperty("timestamp")] | |||
| @@ -1,4 +1,5 @@ | |||
| using Newtonsoft.Json; | |||
| using System; | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API | |||
| { | |||
| @@ -7,10 +8,10 @@ namespace Discord.API | |||
| [JsonProperty("name")] | |||
| public string Name { get; set; } | |||
| [JsonProperty("url")] | |||
| public string Url { get; set; } | |||
| public Uri Url { get; set; } | |||
| [JsonProperty("icon_url")] | |||
| public string IconUrl { get; set; } | |||
| public Uri IconUrl { get; set; } | |||
| [JsonProperty("proxy_icon_url")] | |||
| public string ProxyIconUrl { get; set; } | |||
| public Uri ProxyIconUrl { get; set; } | |||
| } | |||
| } | |||
| @@ -1,4 +1,5 @@ | |||
| using Newtonsoft.Json; | |||
| using System; | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API | |||
| { | |||
| @@ -7,8 +8,8 @@ namespace Discord.API | |||
| [JsonProperty("text")] | |||
| public string Text { get; set; } | |||
| [JsonProperty("icon_url")] | |||
| public string IconUrl { get; set; } | |||
| public Uri IconUrl { get; set; } | |||
| [JsonProperty("proxy_icon_url")] | |||
| public string ProxyIconUrl { get; set; } | |||
| public Uri ProxyIconUrl { get; set; } | |||
| } | |||
| } | |||
| @@ -1,4 +1,5 @@ | |||
| #pragma warning disable CS1591 | |||
| using System; | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API | |||
| @@ -6,9 +7,9 @@ namespace Discord.API | |||
| internal class EmbedImage | |||
| { | |||
| [JsonProperty("url")] | |||
| public string Url { get; set; } | |||
| public Uri Url { get; set; } | |||
| [JsonProperty("proxy_url")] | |||
| public string ProxyUrl { get; set; } | |||
| public Uri ProxyUrl { get; set; } | |||
| [JsonProperty("height")] | |||
| public Optional<int> Height { get; set; } | |||
| [JsonProperty("width")] | |||
| @@ -1,4 +1,5 @@ | |||
| #pragma warning disable CS1591 | |||
| using System; | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API | |||
| @@ -8,6 +9,6 @@ namespace Discord.API | |||
| [JsonProperty("name")] | |||
| public string Name { get; set; } | |||
| [JsonProperty("url")] | |||
| public string Url { get; set; } | |||
| public Uri Url { get; set; } | |||
| } | |||
| } | |||
| @@ -1,4 +1,5 @@ | |||
| #pragma warning disable CS1591 | |||
| using System; | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API | |||
| @@ -6,9 +7,9 @@ namespace Discord.API | |||
| internal class EmbedThumbnail | |||
| { | |||
| [JsonProperty("url")] | |||
| public string Url { get; set; } | |||
| public Uri Url { get; set; } | |||
| [JsonProperty("proxy_url")] | |||
| public string ProxyUrl { get; set; } | |||
| public Uri ProxyUrl { get; set; } | |||
| [JsonProperty("height")] | |||
| public Optional<int> Height { get; set; } | |||
| [JsonProperty("width")] | |||
| @@ -1,4 +1,5 @@ | |||
| #pragma warning disable CS1591 | |||
| using System; | |||
| using Newtonsoft.Json; | |||
| namespace Discord.API | |||
| @@ -6,7 +7,7 @@ namespace Discord.API | |||
| internal class EmbedVideo | |||
| { | |||
| [JsonProperty("url")] | |||
| public string Url { get; set; } | |||
| public Uri Url { get; set; } | |||
| [JsonProperty("height")] | |||
| public Optional<int> Height { get; set; } | |||
| [JsonProperty("width")] | |||
| @@ -38,11 +38,11 @@ namespace Discord | |||
| } | |||
| } | |||
| public string Url { get { return _embed.Url; } set { _embed.Url = value; } } | |||
| public string ThumbnailUrl { get { return _embed.Thumbnail?.Url; } set { _embed.Thumbnail = new EmbedThumbnail(value, null, null, null); } } | |||
| public string ImageUrl { get { return _embed.Image?.Url; } set { _embed.Image = new EmbedImage(value, null, null, null); } } | |||
| public DateTimeOffset? Timestamp { get { return _embed.Timestamp; } set { _embed.Timestamp = value; } } | |||
| public Color? Color { get { return _embed.Color; } set { _embed.Color = value; } } | |||
| public Uri Url { get => _embed.Url; set { _embed.Url = value; } } | |||
| public Uri ThumbnailUrl { get => _embed.Thumbnail?.Url; set { _embed.Thumbnail = new EmbedThumbnail(value, null, null, null); } } | |||
| public Uri ImageUrl { get => _embed.Image?.Url; set { _embed.Image = new EmbedImage(value, null, null, null); } } | |||
| public DateTimeOffset? Timestamp { get => _embed.Timestamp; set { _embed.Timestamp = value; } } | |||
| public Color? Color { get => _embed.Color; set { _embed.Color = value; } } | |||
| public EmbedAuthorBuilder Author { get; set; } | |||
| public EmbedFooterBuilder Footer { get; set; } | |||
| @@ -69,17 +69,17 @@ namespace Discord | |||
| Description = description; | |||
| return this; | |||
| } | |||
| public EmbedBuilder WithUrl(string url) | |||
| public EmbedBuilder WithUrl(Uri url) | |||
| { | |||
| Url = url; | |||
| return this; | |||
| } | |||
| public EmbedBuilder WithThumbnailUrl(string thumbnailUrl) | |||
| public EmbedBuilder WithThumbnailUrl(Uri thumbnailUrl) | |||
| { | |||
| ThumbnailUrl = thumbnailUrl; | |||
| return this; | |||
| } | |||
| public EmbedBuilder WithImageUrl(string imageUrl) | |||
| public EmbedBuilder WithImageUrl(Uri imageUrl) | |||
| { | |||
| ImageUrl = imageUrl; | |||
| return this; | |||
| @@ -186,7 +186,8 @@ namespace Discord | |||
| get => _field.Name; | |||
| set | |||
| { | |||
| if (value?.Length > MaxFieldNameLength) throw new ArgumentException($"Field name length must be less than or equal to {MaxFieldNameLength}."); | |||
| if (string.IsNullOrEmpty(value)) throw new ArgumentException($"Field name must not be null or empty"); | |||
| if (value.Length > MaxFieldNameLength) throw new ArgumentException($"Field name length must be less than or equal to {MaxFieldNameLength}."); | |||
| _field.Name = value; | |||
| } | |||
| } | |||
| @@ -197,11 +198,12 @@ namespace Discord | |||
| set | |||
| { | |||
| var stringValue = value.ToString(); | |||
| if (string.IsNullOrEmpty(stringValue)) throw new ArgumentException($"Field value must not be null or empty"); | |||
| if (stringValue.Length > MaxFieldValueLength) throw new ArgumentException($"Field value length must be less than or equal to {MaxFieldValueLength}."); | |||
| _field.Value = stringValue; | |||
| } | |||
| } | |||
| public bool IsInline { get { return _field.Inline; } set { _field.Inline = value; } } | |||
| public bool IsInline { get => _field.Inline; set { _field.Inline = value; } } | |||
| public EmbedFieldBuilder() | |||
| { | |||
| @@ -243,8 +245,8 @@ namespace Discord | |||
| _author.Name = value; | |||
| } | |||
| } | |||
| public string Url { get { return _author.Url; } set { _author.Url = value; } } | |||
| public string IconUrl { get { return _author.IconUrl; } set { _author.IconUrl = value; } } | |||
| public Uri Url { get => _author.Url; set { _author.Url = value; } } | |||
| public Uri IconUrl { get => _author.IconUrl; set { _author.IconUrl = value; } } | |||
| public EmbedAuthorBuilder() | |||
| { | |||
| @@ -256,12 +258,12 @@ namespace Discord | |||
| Name = name; | |||
| return this; | |||
| } | |||
| public EmbedAuthorBuilder WithUrl(string url) | |||
| public EmbedAuthorBuilder WithUrl(Uri url) | |||
| { | |||
| Url = url; | |||
| return this; | |||
| } | |||
| public EmbedAuthorBuilder WithIconUrl(string iconUrl) | |||
| public EmbedAuthorBuilder WithIconUrl(Uri iconUrl) | |||
| { | |||
| IconUrl = iconUrl; | |||
| return this; | |||
| @@ -286,7 +288,7 @@ namespace Discord | |||
| _footer.Text = value; | |||
| } | |||
| } | |||
| public string IconUrl { get { return _footer.IconUrl; } set { _footer.IconUrl = value; } } | |||
| public Uri IconUrl { get => _footer.IconUrl; set { _footer.IconUrl = value; } } | |||
| public EmbedFooterBuilder() | |||
| { | |||
| @@ -298,7 +300,7 @@ namespace Discord | |||
| Text = text; | |||
| return this; | |||
| } | |||
| public EmbedFooterBuilder WithIconUrl(string iconUrl) | |||
| public EmbedFooterBuilder WithIconUrl(Uri iconUrl) | |||
| { | |||
| IconUrl = iconUrl; | |||
| return this; | |||