Add IEmbed#ToEmbedBuilder extension method (#863)
* Add IEmbed#ToEmbedBuilder extension method * Implementing reviewed changes. * Switch to object initializers for author and footer.
This commit is contained in:
committed by
Christopher F
parent
f9963380a7
commit
5218e6be97
@@ -1,3 +1,5 @@
|
|||||||
|
using System;
|
||||||
|
|
||||||
namespace Discord
|
namespace Discord
|
||||||
{
|
{
|
||||||
public static class EmbedBuilderExtensions
|
public static class EmbedBuilderExtensions
|
||||||
@@ -19,5 +21,38 @@ namespace Discord
|
|||||||
|
|
||||||
public static EmbedBuilder WithAuthor(this EmbedBuilder builder, IGuildUser user) =>
|
public static EmbedBuilder WithAuthor(this EmbedBuilder builder, IGuildUser user) =>
|
||||||
builder.WithAuthor($"{user.Nickname ?? user.Username}#{user.Discriminator}", user.GetAvatarUrl());
|
builder.WithAuthor($"{user.Nickname ?? user.Username}#{user.Discriminator}", user.GetAvatarUrl());
|
||||||
|
|
||||||
|
public static EmbedBuilder ToEmbedBuilder(this IEmbed embed)
|
||||||
|
{
|
||||||
|
if (embed.Type != EmbedType.Rich)
|
||||||
|
throw new InvalidOperationException($"Only {nameof(EmbedType.Rich)} embeds may be built.");
|
||||||
|
|
||||||
|
var builder = new EmbedBuilder
|
||||||
|
{
|
||||||
|
Author = new EmbedAuthorBuilder
|
||||||
|
{
|
||||||
|
Name = embed.Author?.Name,
|
||||||
|
IconUrl = embed.Author?.IconUrl,
|
||||||
|
Url = embed.Author?.Url
|
||||||
|
},
|
||||||
|
Color = embed.Color ?? Color.Default,
|
||||||
|
Description = embed.Description,
|
||||||
|
Footer = new EmbedFooterBuilder
|
||||||
|
{
|
||||||
|
Text = embed.Footer?.Text,
|
||||||
|
IconUrl = embed.Footer?.IconUrl
|
||||||
|
},
|
||||||
|
ImageUrl = embed.Image?.Url,
|
||||||
|
ThumbnailUrl = embed.Thumbnail?.Url,
|
||||||
|
Timestamp = embed.Timestamp,
|
||||||
|
Title = embed.Title,
|
||||||
|
Url = embed.Url
|
||||||
|
};
|
||||||
|
|
||||||
|
foreach (var field in embed.Fields)
|
||||||
|
builder.AddField(field.Name, field.Value, field.Inline);
|
||||||
|
|
||||||
|
return builder;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user