54 lines
2.0 KiB
C#
54 lines
2.0 KiB
C#
using System.Collections.Immutable;
|
|
using System.Diagnostics;
|
|
using System.Linq;
|
|
using Model = Discord.API.Embed;
|
|
|
|
namespace Discord
|
|
{
|
|
[DebuggerDisplay(@"{DebuggerDisplay,nq}")]
|
|
public class Embed : IEmbed
|
|
{
|
|
public string Description { get; }
|
|
public string Url { get; }
|
|
public string Title { get; }
|
|
public string Type { get; }
|
|
public uint? Color { get; }
|
|
public EmbedAuthor? Author { get; }
|
|
public EmbedFooter? Footer { get; }
|
|
public EmbedProvider? Provider { get; }
|
|
public EmbedThumbnail? Thumbnail { get; }
|
|
public ImmutableArray<EmbedField> Fields { get; }
|
|
|
|
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;
|
|
Title = title;
|
|
Description = description;
|
|
Url = url;
|
|
Provider = provider;
|
|
Thumbnail = thumbnail;
|
|
}
|
|
internal static Embed Create(Model model)
|
|
{
|
|
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.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;
|
|
private string DebuggerDisplay => $"{Title} ({Type})";
|
|
}
|
|
}
|