Add embed builder extensions (#460)
* Add embed builder extensions People in #dotnet_discord-net suggested that this should be part of the lib after I demonstrated it * Move some extensions into EmbedBuilder [2] Apparently git didn't like that previous commit * Fix error with EmbedBuilderExtensions A summary of issues which happened: - Git decided to add an amend commit (I told it to quit?) - VS Code thinks everything is an error so it wasn't helpful - dotnet decided to think there was no error until I deleted all build outputs and rebuild Sometimes I question my ability to use version control properly.
This commit is contained in:
committed by
RogueException
parent
74f6a4b392
commit
fdd38c8d7f
@@ -137,6 +137,17 @@ namespace Discord
|
||||
Author = author;
|
||||
return this;
|
||||
}
|
||||
public EmbedBuilder WithAuthor(string name, string iconUrl = null, string url = null)
|
||||
{
|
||||
var author = new EmbedAuthorBuilder
|
||||
{
|
||||
Name = name,
|
||||
IconUrl = iconUrl,
|
||||
Url = url
|
||||
};
|
||||
Author = author;
|
||||
return this;
|
||||
}
|
||||
public EmbedBuilder WithFooter(EmbedFooterBuilder footer)
|
||||
{
|
||||
Footer = footer;
|
||||
@@ -149,6 +160,16 @@ namespace Discord
|
||||
Footer = footer;
|
||||
return this;
|
||||
}
|
||||
public EmbedBuilder WithFooter(string text, string iconUrl = null)
|
||||
{
|
||||
var footer = new EmbedFooterBuilder
|
||||
{
|
||||
Text = text,
|
||||
IconUrl = iconUrl
|
||||
};
|
||||
Footer = footer;
|
||||
return this;
|
||||
}
|
||||
|
||||
public EmbedBuilder AddField(string name, object value)
|
||||
{
|
||||
@@ -185,6 +206,17 @@ namespace Discord
|
||||
this.AddField(field);
|
||||
return this;
|
||||
}
|
||||
public EmbedBuilder AddField(string title, string text, bool inline = false)
|
||||
{
|
||||
var field = new EmbedFieldBuilder
|
||||
{
|
||||
Name = title,
|
||||
Value = text,
|
||||
IsInline = inline
|
||||
};
|
||||
_fields.Add(field);
|
||||
return this;
|
||||
}
|
||||
|
||||
public Embed Build()
|
||||
{
|
||||
|
||||
20
src/Discord.Net.Rest/Extensions/EmbedBuilderExtensions.cs
Normal file
20
src/Discord.Net.Rest/Extensions/EmbedBuilderExtensions.cs
Normal file
@@ -0,0 +1,20 @@
|
||||
namespace Discord
|
||||
{
|
||||
public static class EmbedBuilderExtensions
|
||||
{
|
||||
public static EmbedBuilder WithColor(this EmbedBuilder builder, uint rawValue) =>
|
||||
builder.WithColor(new Color(rawValue));
|
||||
|
||||
public static EmbedBuilder WithColor(this EmbedBuilder builder, byte r, byte g, byte b) =>
|
||||
builder.WithColor(new Color(r, g, b));
|
||||
|
||||
public static EmbedBuilder WithColor(this EmbedBuilder builder, float r, float g, float b) =>
|
||||
builder.WithColor(new Color(r, g, b));
|
||||
|
||||
public static EmbedBuilder WithAuthor(this EmbedBuilder builder, IUser user) =>
|
||||
builder.WithAuthor($"{user.Username}#{user.Discriminator}", user.AvatarUrl);
|
||||
|
||||
public static EmbedBuilder WithAuthor(this EmbedBuilder builder, IGuildUser user) =>
|
||||
builder.WithAuthor($"{user.Nickname ?? user.Username}#{user.Discriminator}", user.AvatarUrl);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user