From a455ccc3343e058fcb0c6e3714128b33d1da4e49 Mon Sep 17 00:00:00 2001 From: "Sindre G. Langhus" Date: Thu, 24 Nov 2016 01:17:39 +0100 Subject: [PATCH] Adds a timestamp and fixes Volts issues with Thumbnail and Image URLs. --- src/Discord.Net.Core/API/Common/Embed.cs | 3 + .../Entities/Messages/EmbedBuilder.cs | 82 ++++--------------- .../Entities/Messages/IEmbed.cs | 4 +- .../Entities/Messages/Embed.cs | 8 +- 4 files changed, 26 insertions(+), 71 deletions(-) diff --git a/src/Discord.Net.Core/API/Common/Embed.cs b/src/Discord.Net.Core/API/Common/Embed.cs index eb56ce696..5a6661f0a 100644 --- a/src/Discord.Net.Core/API/Common/Embed.cs +++ b/src/Discord.Net.Core/API/Common/Embed.cs @@ -1,4 +1,5 @@ #pragma warning disable CS1591 +using System; using Newtonsoft.Json; namespace Discord.API @@ -15,6 +16,8 @@ namespace Discord.API public string Url { get; set; } [JsonProperty("color")] public uint? Color { get; set; } + [JsonProperty("timestamp")] + public Optional Timestamp { get; set; } [JsonProperty("author")] public Optional Author { get; set; } [JsonProperty("footer")] diff --git a/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs b/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs index c0069aa9a..f98371a31 100644 --- a/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs +++ b/src/Discord.Net.Core/Entities/Messages/EmbedBuilder.cs @@ -23,11 +23,11 @@ namespace Discord public string Title { get { return _model.Title; } set { _model.Title = value; } } public string Description { get { return _model.Description; } set { _model.Description = value; } } public string Url { get { return _model.Url; } set { _model.Url = value; } } + public string ThumbnailUrl { get; set; } + public string ImageUrl { get; set; } public Color? Color { get { return _model.Color.HasValue ? new Color(_model.Color.Value) : (Color?)null; } set { _model.Color = value?.RawValue; } } public EmbedAuthorBuilder Author { get; set; } public EmbedFooterBuilder Footer { get; set; } - public EmbedThumbnailBuilder Thumbnail { get; set; } - public EmbedImageBuilder Image { get; set; } public EmbedBuilder WithTitle(string title) { @@ -44,6 +44,16 @@ namespace Discord Url = url; return this; } + public EmbedBuilder WithThumbnailUrl(string thumbnailUrl) + { + ThumbnailUrl = thumbnailUrl; + return this; + } + public EmbedBuilder WithImageUrl(string imageUrl) + { + ImageUrl = ImageUrl; + return this; + } public EmbedBuilder WithColor(Color color) { Color = color; @@ -74,30 +84,6 @@ namespace Discord Footer = footer; return this; } - public EmbedBuilder WithThumbnail(EmbedThumbnailBuilder thumbnail) - { - Thumbnail = thumbnail; - return this; - } - public EmbedBuilder WithThumbnail(Action action) - { - var thumbnail = new EmbedThumbnailBuilder(); - action(thumbnail); - Thumbnail = thumbnail; - return this; - } - public EmbedBuilder WithImage(EmbedImageBuilder image) - { - Image = image; - return this; - } - public EmbedBuilder WithImage(Action action) - { - var image = new EmbedImageBuilder(); - action(image); - Image = image; - return this; - } public EmbedBuilder AddField(Action action) { @@ -111,8 +97,8 @@ namespace Discord { _model.Author = Author?.ToModel(); _model.Footer = Footer?.ToModel(); - _model.Thumbnail = Thumbnail?.ToModel(); - _model.Image = Image?.ToModel(); + _model.Thumbnail = ThumbnailUrl != null ? new Thumbnail { Url = ThumbnailUrl } : null; + _model.Image = ImageUrl != null ? new Image { Url = ImageUrl } : null; _model.Fields = _fields.ToArray(); return _model; } @@ -207,44 +193,4 @@ namespace Discord internal Footer ToModel() => _model; } - - public class EmbedThumbnailBuilder - { - private Thumbnail _model; - - public string Url { get { return _model.Url; } set { _model.Url = value; } } - - public EmbedThumbnailBuilder() - { - _model = new Thumbnail(); - } - - public EmbedThumbnailBuilder WithUrl(string url) - { - Url = url; - return this; - } - - internal Thumbnail ToModel() => _model; - } - - public class EmbedImageBuilder - { - private Image _model; - - public string Url { get { return _model.Url; } set { _model.Url = value; } } - - public EmbedImageBuilder() - { - _model = new Image(); - } - - public EmbedImageBuilder WithUrl(string url) - { - Url = url; - return this; - } - - internal Image ToModel() => _model; - } } diff --git a/src/Discord.Net.Core/Entities/Messages/IEmbed.cs b/src/Discord.Net.Core/Entities/Messages/IEmbed.cs index 86463534d..d684827c3 100644 --- a/src/Discord.Net.Core/Entities/Messages/IEmbed.cs +++ b/src/Discord.Net.Core/Entities/Messages/IEmbed.cs @@ -1,4 +1,5 @@ -using System.Collections.Immutable; +using System; +using System.Collections.Immutable; namespace Discord { @@ -9,6 +10,7 @@ namespace Discord string Title { get; } string Description { get; } Color? Color { get; } + DateTimeOffset? Timestamp { get; } EmbedImage? Image { get; } EmbedVideo? Video { get; } EmbedAuthor? Author { get; } diff --git a/src/Discord.Net.Rest/Entities/Messages/Embed.cs b/src/Discord.Net.Rest/Entities/Messages/Embed.cs index 7124df417..f51e7e7a7 100644 --- a/src/Discord.Net.Rest/Entities/Messages/Embed.cs +++ b/src/Discord.Net.Rest/Entities/Messages/Embed.cs @@ -14,6 +14,7 @@ namespace Discord public string Title { get; } public string Type { get; } public Color? Color { get; } + public DateTimeOffset? Timestamp { get; } public EmbedImage? Image { get; } public EmbedVideo? Video { get; } public EmbedAuthor? Author { get; } @@ -26,7 +27,8 @@ namespace Discord string title, string description, string url, - Color? color, + Color? color, + DateTimeOffset? timestamp, EmbedImage? image, EmbedVideo? video, EmbedAuthor? author, @@ -40,6 +42,7 @@ namespace Discord Description = description; Url = url; Color = color; + Timestamp = timestamp; Image = image; Video = video; Author = author; @@ -52,13 +55,14 @@ namespace Discord { return new Embed(model.Type, model.Title, model.Description, model.Url, model.Color.HasValue ? new Color(model.Color.Value) : (Color?)null, + model.Timestamp.IsSpecified ? model.Timestamp.Value : (DateTimeOffset?)null, model.Image.IsSpecified ? EmbedImage.Create(model.Image.Value) : (EmbedImage?)null, model.Video.IsSpecified ? EmbedVideo.Create(model.Video.Value) : (EmbedVideo?)null, model.Author.IsSpecified ? EmbedAuthor.Create(model.Author.Value) : (EmbedAuthor?)null, model.Footer.IsSpecified ? EmbedFooter.Create(model.Footer.Value) : (EmbedFooter?)null, model.Provider.IsSpecified ? EmbedProvider.Create(model.Provider.Value) : (EmbedProvider?)null, model.Thumbnail.IsSpecified ? EmbedThumbnail.Create(model.Thumbnail.Value) : (EmbedThumbnail?)null, - model.Fields.IsSpecified ? model.Fields.Value.Select(x => EmbedField.Create(x)).ToImmutableArray() : ImmutableArray.Create()); + model.Fields.IsSpecified ? model.Fields.Value.Select(EmbedField.Create).ToImmutableArray() : ImmutableArray.Create()); } public override string ToString() => Title;