* 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.tags/1.0
| @@ -137,6 +137,17 @@ namespace Discord | |||||
| Author = author; | Author = author; | ||||
| return this; | 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) | public EmbedBuilder WithFooter(EmbedFooterBuilder footer) | ||||
| { | { | ||||
| Footer = footer; | Footer = footer; | ||||
| @@ -149,6 +160,16 @@ namespace Discord | |||||
| Footer = footer; | Footer = footer; | ||||
| return this; | 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) | public EmbedBuilder AddField(string name, object value) | ||||
| { | { | ||||
| @@ -185,6 +206,17 @@ namespace Discord | |||||
| this.AddField(field); | this.AddField(field); | ||||
| return this; | 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() | public Embed Build() | ||||
| { | { | ||||
| @@ -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); | |||||
| } | |||||
| } | |||||