From af6c3e10c37297dd6279e237cfb4d94cb549c335 Mon Sep 17 00:00:00 2001 From: RogueException Date: Mon, 14 Nov 2016 20:16:24 -0400 Subject: [PATCH] Cleaned up EmbedBuilder --- src/Discord.Net.Core/Utils/EmbedBuilder.cs | 140 +++++++-------------- 1 file changed, 45 insertions(+), 95 deletions(-) diff --git a/src/Discord.Net.Core/Utils/EmbedBuilder.cs b/src/Discord.Net.Core/Utils/EmbedBuilder.cs index 42861709f..dca4377eb 100644 --- a/src/Discord.Net.Core/Utils/EmbedBuilder.cs +++ b/src/Discord.Net.Core/Utils/EmbedBuilder.cs @@ -9,124 +9,74 @@ namespace Discord { public class EmbedBuilder { - private Embed embed = new Embed(); - List fields = new List(); + private Embed model = new Embed(); + private List fields = new List(); public EmbedBuilder() { - embed.Type = "rich"; + model.Type = "rich"; } - public EmbedBuilder Title(string title) - { - embed.Title = title; - return this; - } - public EmbedBuilder Description(string description) - { - embed.Description = description; - return this; - } - public EmbedBuilder Url(string url) - { - embed.Url = url; - return this; - } - public EmbedBuilder Color(Color color) - { - embed.Color = color.RawValue; - return this; - } - public EmbedBuilder Field(Func builder) + public string Title { get { return model.Title; } set { model.Title = value; } } + public string Description { get { return model.Description; } set { model.Description = value; } } + public string Url { get { return model.Url; } set { model.Url = value; } } + public Color? Color { get { return model.Color.HasValue ? new Color(model.Color.Value) : (Color?)null; } set { model.Color = value?.RawValue; } } + + public void SetAuthor(Action action) { - fields.Add(builder(new EmbedFieldBuilder()).Build()); - return this; + var author = new EmbedBuilderAuthor(); + action(author); + model.Author = author.ToModel(); } - public EmbedBuilder Author(Func builder) + public void SetFooter(Action action) { - embed.Author = builder(new EmbedAuthorBuilder()).Build(); - return this; + var footer = new EmbedBuilderFooter(); + action(footer); + model.Footer = footer.ToModel(); } - public EmbedBuilder Footer(Func builder) + public void AddField(Action action) { - embed.Footer = builder(new EmbedFooterBuilder()).Build(); - return this; + var field = new EmbedBuilderField(); + action(field); + fields.Add(field.ToModel()); } - public Embed Build() + + internal Embed Build() { - embed.Fields = fields.ToArray(); - return embed; + model.Fields = fields.ToArray(); + return model; } - } - public class EmbedFieldBuilder + public class EmbedBuilderField { - private Field embedField = new Field(); + private Field model = new Field(); - public EmbedFieldBuilder Name(string name) - { - embedField.Name = name; - return this; - } - public EmbedFieldBuilder Value(string value) - { - embedField.Value = value; - return this; - } - public EmbedFieldBuilder Inline(bool inline) - { - embedField.Inline = inline; - return this; - } - public Field Build() - { - return embedField; - } + public string Name { get { return model.Name; } set { model.Name = value; } } + public string Value { get { return model.Value; } set { model.Value = value; } } + public bool IsInline { get { return model.Inline; } set { model.Inline = value; } } + + internal Field ToModel() => model; } - public class EmbedAuthorBuilder + public class EmbedBuilderAuthor { - private Author author = new Author(); - - public EmbedAuthorBuilder Name(string name) - { - author.Name = name; - return this; - } - public EmbedAuthorBuilder Url(string url) - { - author.Url = url; - return this; - } - public EmbedAuthorBuilder IconUrl(string iconUrl) - { - author.IconUrl = iconUrl; - return this; - } - public Author Build() - { - return author; - } + private Author model = new Author(); + + public string Name { get { return model.Name; } set { model.Name = value; } } + public string Url { get { return model.Url; } set { model.Url = value; } } + public string IconUrl { get { return model.IconUrl; } set { model.IconUrl = value; } } + + internal Author ToModel() => model; } - public class EmbedFooterBuilder + public class EmbedBuilderFooter { - private Footer footer = new Footer(); + private Footer model = new Footer(); - public EmbedFooterBuilder Text(string text) - { - footer.Text = text; - return this; - } - public EmbedFooterBuilder IconUrl(string iconUrl) - { - footer.IconUrl = iconUrl; - return this; - } - public Footer Build() - { - return footer; - } + public string Text { get { return model.Text; } set { model.Text = value; } } + public string IconUrl { get { return model.IconUrl; } set { model.IconUrl = value; } } + + internal Footer ToModel() => model; } }