@@ -9,17 +9,23 @@ namespace Discord
{
private readonly Embed _embed;
/// <summary> The maximum number of fields allowed by Discord. </summary>
public const int MaxFieldCount = 25;
/// <summary> The maximum length of title allowed by Discord. </summary>
public const int MaxTitleLength = 256;
/// <summary> The maximum length of description allowed by Discord. </summary>
public const int MaxDescriptionLength = 2048;
/// <summary> The maximum length of total characters allowed by Discord. </summary>
public const int MaxEmbedLength = 6000; // user bot limit is 2000, but we don't validate that here.
/// <summary> Creates a new <see cref="EmbedBuilder"/>. </summary>
public EmbedBuilder()
{
_embed = new Embed(EmbedType.Rich);
Fields = new List<EmbedFieldBuilder>();
}
/// <summary> Gets or sets the title of an <see cref="Embed"/>. </summary>
public string Title
{
get => _embed.Title;
@@ -30,6 +36,7 @@ namespace Discord
}
}
/// <summary> Gets or sets the description of an <see cref="Embed"/>. </summary>
public string Description
{
get => _embed.Description;
@@ -40,6 +47,7 @@ namespace Discord
}
}
/// <summary> Gets or sets the URL of an <see cref="Embed"/>. </summary>
public string Url
{
get => _embed.Url;
@@ -49,6 +57,7 @@ namespace Discord
_embed.Url = value;
}
}
/// <summary> Gets or sets the thumbnail URL of an <see cref="Embed"/>. </summary>
public string ThumbnailUrl
{
get => _embed.Thumbnail?.Url;
@@ -58,6 +67,7 @@ namespace Discord
_embed.Thumbnail = new EmbedThumbnail(value, null, null, null);
}
}
/// <summary> Gets or sets the image URL of an <see cref="Embed"/>. </summary>
public string ImageUrl
{
get => _embed.Image?.Url;
@@ -67,12 +77,17 @@ namespace Discord
_embed.Image = new EmbedImage(value, null, null, null);
}
}
/// <summary> Gets or sets the timestamp of an <see cref="Embed"/>. </summary>
public DateTimeOffset? Timestamp { get => _embed.Timestamp; set { _embed.Timestamp = value; } }
/// <summary> Gets or sets the sidebar color of an <see cref="Embed"/>. </summary>
public Color? Color { get => _embed.Color; set { _embed.Color = value; } }
/// <summary> Gets or sets the <see cref="EmbedAuthorBuilder"/> of an <see cref="Embed"/>. </summary>
public EmbedAuthorBuilder Author { get; set; }
/// <summary> Gets or sets the <see cref="EmbedFooterBuilder"/> of an <see cref="Embed"/>. </summary>
public EmbedFooterBuilder Footer { get; set; }
private List<EmbedFieldBuilder> _fields;
/// <summary> Gets or sets the list of <see cref="EmbedFieldBuilder"/> of an <see cref="Embed"/>. </summary>
public List<EmbedFieldBuilder> Fields
{
get => _fields;
@@ -85,52 +100,71 @@ namespace Discord
}
}
/// <summary> Sets the title of an <see cref="Embed"/>. </summary>
/// <param name="title"> The title to be set. </param>
public EmbedBuilder WithTitle(string title)
{
Title = title;
return this;
}
/// <summary> Sets the description of an <see cref="Embed"/>. </summary>
/// <param name="description"> The description to be set. </param>
public EmbedBuilder WithDescription(string description)
{
Description = description;
return this;
}
/// <summary> Sets the URL of an <see cref="Embed"/>. </summary>
/// <param name="url"> The URL to be set. </param>
public EmbedBuilder WithUrl(string url)
{
Url = url;
return this;
}
/// <summary> Sets the thumbnail URL of an <see cref="Embed"/>. </summary>
/// <param name="thumbnailUrl"> The thumbnail URL to be set. </param>
public EmbedBuilder WithThumbnailUrl(string thumbnailUrl)
{
ThumbnailUrl = thumbnailUrl;
return this;
}
/// <summary> Sets the image URL of an <see cref="Embed"/>. </summary>
/// <param name="imageUrl"> The image URL to be set. </param>
public EmbedBuilder WithImageUrl(string imageUrl)
{
ImageUrl = imageUrl;
return this;
}
/// <summary> Sets the timestamp of an <see cref="Embed"/> to the current time. </summary>
public EmbedBuilder WithCurrentTimestamp()
{
Timestamp = DateTimeOffset.UtcNow;
return this;
}
/// <summary> Sets the timestamp of an <see cref="Embed"/>. </summary>
/// <param name="dateTimeOffset"> The timestamp to be set. </param>
public EmbedBuilder WithTimestamp(DateTimeOffset dateTimeOffset)
{
Timestamp = dateTimeOffset;
return this;
}
/// <summary> Sets the sidebar color of an <see cref="Embed"/>. </summary>
/// <param name="color"> The color to be set. </param>
public EmbedBuilder WithColor(Color color)
{
Color = color;
return this;
}
/// <summary> Sets the <see cref="EmbedAuthorBuilder"/> of an <see cref="Embed"/>. </summary>
/// <param name="author"> The author builder class containing the author field properties. </param>
public EmbedBuilder WithAuthor(EmbedAuthorBuilder author)
{
Author = author;
return this;
}
/// <summary> Sets the author field of an <see cref="Embed"/> with the provided properties. </summary>
/// <param name="action"> The delegate containing the author field properties. </param>
public EmbedBuilder WithAuthor(Action<EmbedAuthorBuilder> action)
{
var author = new EmbedAuthorBuilder();
@@ -138,6 +172,10 @@ namespace Discord
Author = author;
return this;
}
/// <summary> Sets the author field of an <see cref="Embed"/> with the provided name, icon URL, and URL. </summary>
/// <param name="name"> The title of the author field. </param>
/// <param name="iconUrl"> The icon URL of the author field. </param>
/// <param name="url"> The URL of the author field. </param>
public EmbedBuilder WithAuthor(string name, string iconUrl = null, string url = null)
{
var author = new EmbedAuthorBuilder
@@ -149,11 +187,15 @@ namespace Discord
Author = author;
return this;
}
/// <summary> Sets the <see cref="EmbedFooterBuilder"/> of an <see cref="Embed"/>. </summary>
/// <param name="footer"> The footer builder class containing the footer field properties. </param>
public EmbedBuilder WithFooter(EmbedFooterBuilder footer)
{
Footer = footer;
return this;
}
/// <summary> Sets the footer field of an <see cref="Embed"/> with the provided properties. </summary>
/// <param name="action"> The delegate containing the footer field properties. </param>
public EmbedBuilder WithFooter(Action<EmbedFooterBuilder> action)
{
var footer = new EmbedFooterBuilder();
@@ -161,6 +203,9 @@ namespace Discord
Footer = footer;
return this;
}
/// <summary> Sets the footer field of an <see cref="Embed"/> with the provided name, icon URL. </summary>
/// <param name="text"> The title of the footer field. </param>
/// <param name="iconUrl"> The icon URL of the footer field. </param>
public EmbedBuilder WithFooter(string text, string iconUrl = null)
{
var footer = new EmbedFooterBuilder
@@ -172,6 +217,10 @@ namespace Discord
return this;
}
/// <summary> Adds an <see cref="Embed"/> field with the provided name and value. </summary>
/// <param name="name"> The title of the field. </param>
/// <param name="value"> The value of the field. </param>
/// <param name="inline"> Indicates whether the field is in-line or not. </param>
public EmbedBuilder AddField(string name, object value, bool inline = false)
{
var field = new EmbedFieldBuilder()
@@ -182,6 +231,8 @@ namespace Discord
return this;
}
/// <summary> Adds a field with the provided <see cref="EmbedFieldBuilder"/> to an <see cref="Embed"/>. </summary>
/// <param name="field"> The field builder class containing the field properties. </param>
public EmbedBuilder AddField(EmbedFieldBuilder field)
{
if (Fields.Count >= MaxFieldCount)
@@ -192,6 +243,8 @@ namespace Discord
Fields.Add(field);
return this;
}
/// <summary> Adds an <see cref="Embed"/> field with the provided properties. </summary>
/// <param name="action"> The delegate containing the field properties. </param>
public EmbedBuilder AddField(Action<EmbedFieldBuilder> action)
{
var field = new EmbedFieldBuilder();
@@ -200,6 +253,8 @@ namespace Discord
return this;
}
/// <summary> Builds the <see cref="Embed"/> into a Rich Embed format. </summary>
/// <returns> The built embed object. </returns>
public Embed Build()
{
_embed.Footer = Footer?.Build();