Browse Source

Cleaned up EmbedBuilder

tags/1.0-rc
RogueException 8 years ago
parent
commit
af6c3e10c3
1 changed files with 45 additions and 95 deletions
  1. +45
    -95
      src/Discord.Net.Core/Utils/EmbedBuilder.cs

+ 45
- 95
src/Discord.Net.Core/Utils/EmbedBuilder.cs View File

@@ -9,124 +9,74 @@ namespace Discord
{
public class EmbedBuilder
{
private Embed embed = new Embed();
List<Field> fields = new List<Field>();
private Embed model = new Embed();
private List<Field> fields = new List<Field>();

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<EmbedFieldBuilder, EmbedFieldBuilder> 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<EmbedBuilderAuthor> action)
{
fields.Add(builder(new EmbedFieldBuilder()).Build());
return this;
var author = new EmbedBuilderAuthor();
action(author);
model.Author = author.ToModel();
}
public EmbedBuilder Author(Func<EmbedAuthorBuilder, EmbedAuthorBuilder> builder)
public void SetFooter(Action<EmbedBuilderFooter> action)
{
embed.Author = builder(new EmbedAuthorBuilder()).Build();
return this;
var footer = new EmbedBuilderFooter();
action(footer);
model.Footer = footer.ToModel();
}
public EmbedBuilder Footer(Func<EmbedFooterBuilder, EmbedFooterBuilder> builder)
public void AddField(Action<EmbedBuilderField> 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;
}
}

Loading…
Cancel
Save