Browse Source

Support Rich Embeds on Entities

tags/1.0-rc
Christopher F 8 years ago
parent
commit
63b06ff477
6 changed files with 113 additions and 6 deletions
  1. +1
    -1
      src/Discord.Net.Core/API/Common/Embed.cs
  2. +29
    -0
      src/Discord.Net.Core/Entities/Messages/EmbedAuthor.cs
  3. +27
    -0
      src/Discord.Net.Core/Entities/Messages/EmbedField.cs
  4. +27
    -0
      src/Discord.Net.Core/Entities/Messages/EmbedFooter.cs
  5. +7
    -1
      src/Discord.Net.Core/Entities/Messages/IEmbed.cs
  6. +22
    -4
      src/Discord.Net.Rest/Entities/Messages/Embed.cs

+ 1
- 1
src/Discord.Net.Core/API/Common/Embed.cs View File

@@ -14,7 +14,7 @@ namespace Discord.API
[JsonProperty("url")] [JsonProperty("url")]
public string Url { get; set; } public string Url { get; set; }
[JsonProperty("color")] [JsonProperty("color")]
public uint Color { get; set; }
public uint? Color { get; set; }
[JsonProperty("author")] [JsonProperty("author")]
public Optional<EmbedAuthor> Author { get; set; } public Optional<EmbedAuthor> Author { get; set; }
[JsonProperty("footer")] [JsonProperty("footer")]


+ 29
- 0
src/Discord.Net.Core/Entities/Messages/EmbedAuthor.cs View File

@@ -0,0 +1,29 @@
using System.Diagnostics;
using Model = Discord.API.EmbedAuthor;

namespace Discord
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public struct EmbedAuthor
{
public string Name { get; set; }
public string Url { get; set; }
public string IconUrl { get; set; }
public string ProxyIconUrl { get; set; }

private EmbedAuthor(string name, string url, string iconUrl, string proxyIconUrl)
{
Name = name;
Url = url;
IconUrl = iconUrl;
ProxyIconUrl = proxyIconUrl;
}
internal static EmbedAuthor Create(Model model)
{
return new EmbedAuthor(model.Name, model.Url, model.IconUrl, model.ProxyIconUrl);
}

private string DebuggerDisplay => $"{Name} ({Url})";
public override string ToString() => Name;
}
}

+ 27
- 0
src/Discord.Net.Core/Entities/Messages/EmbedField.cs View File

@@ -0,0 +1,27 @@
using System.Diagnostics;
using Model = Discord.API.EmbedField;

namespace Discord
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public struct EmbedField
{
public string Name { get; set; }
public string Value { get; set; }
public bool Inline { get; set; }

private EmbedField(string name, string value, bool inline)
{
Name = name;
Value = value;
Inline = inline;
}
internal static EmbedField Create(Model model)
{
return new EmbedField(model.Name, model.Value, model.Inline);
}

private string DebuggerDisplay => $"{Name} ({Value}";
public override string ToString() => Name;
}
}

+ 27
- 0
src/Discord.Net.Core/Entities/Messages/EmbedFooter.cs View File

@@ -0,0 +1,27 @@
using System.Diagnostics;
using Model = Discord.API.EmbedFooter;

namespace Discord
{
[DebuggerDisplay("{DebuggerDisplay,nq}")]
public struct EmbedFooter
{
public string Text { get; set; }
public string IconUrl { get; set; }
public string ProxyUrl { get; set; }

private EmbedFooter(string text, string iconUrl, string proxyUrl)
{
Text = text;
IconUrl = iconUrl;
ProxyUrl = proxyUrl;
}
internal static EmbedFooter Create(Model model)
{
return new EmbedFooter(model.Text, model.IconUrl, model.ProxyIconUrl);
}

private string DebuggerDisplay => $"{Text} ({IconUrl})";
public override string ToString() => Text;
}
}

+ 7
- 1
src/Discord.Net.Core/Entities/Messages/IEmbed.cs View File

@@ -1,4 +1,6 @@
namespace Discord
using System.Collections.Immutable;

namespace Discord
{ {
public interface IEmbed public interface IEmbed
{ {
@@ -6,7 +8,11 @@
string Type { get; } string Type { get; }
string Title { get; } string Title { get; }
string Description { get; } string Description { get; }
uint? Color { get; }
EmbedAuthor? Author { get; }
EmbedFooter? Footer { get; }
EmbedProvider? Provider { get; } EmbedProvider? Provider { get; }
EmbedThumbnail? Thumbnail { get; } EmbedThumbnail? Thumbnail { get; }
ImmutableArray<EmbedField> Fields { get; }
} }
} }

+ 22
- 4
src/Discord.Net.Rest/Entities/Messages/Embed.cs View File

@@ -1,4 +1,6 @@
using System.Diagnostics;
using System.Collections.Immutable;
using System.Diagnostics;
using System.Linq;
using Model = Discord.API.Embed; using Model = Discord.API.Embed;


namespace Discord namespace Discord
@@ -10,10 +12,23 @@ namespace Discord
public string Url { get; } public string Url { get; }
public string Title { get; } public string Title { get; }
public string Type { get; } public string Type { get; }
public uint? Color { get; }
public EmbedAuthor? Author { get; }
public EmbedFooter? Footer { get; }
public EmbedProvider? Provider { get; } public EmbedProvider? Provider { get; }
public EmbedThumbnail? Thumbnail { get; } public EmbedThumbnail? Thumbnail { get; }
public ImmutableArray<EmbedField> Fields { get; }


internal Embed(string type, string title, string description, string url, EmbedProvider? provider, EmbedThumbnail? thumbnail)
internal Embed(string type,
string title,
string description,
string url,
uint? color,
EmbedAuthor? author,
EmbedFooter? footer,
EmbedProvider? provider,
EmbedThumbnail? thumbnail,
ImmutableArray<EmbedField> fields)
{ {
Type = type; Type = type;
Title = title; Title = title;
@@ -24,9 +39,12 @@ namespace Discord
} }
internal static Embed Create(Model model) internal static Embed Create(Model model)
{ {
return new Embed(model.Type, model.Title, model.Description, model.Url,
return new Embed(model.Type, model.Title, model.Description, model.Url, model.Color,
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.Provider.IsSpecified ? EmbedProvider.Create(model.Provider.Value) : (EmbedProvider?)null,
model.Thumbnail.IsSpecified ? EmbedThumbnail.Create(model.Thumbnail.Value) : (EmbedThumbnail?)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<EmbedField>());
} }


public override string ToString() => Title; public override string ToString() => Title;


Loading…
Cancel
Save