Skip to content

Commit

Permalink
Allow setting the embed builders directly (#962)
Browse files Browse the repository at this point in the history
  • Loading branch information
Prof-Bloodstone authored Oct 4, 2020
1 parent 7ef12ee commit b522e83
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
13 changes: 11 additions & 2 deletions src/builder/create_embed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ use crate::utils::Colour;
pub struct CreateEmbed(pub HashMap<&'static str, Value>);

impl CreateEmbed {
/// Set the author of the embed.
/// Build the author of the embed.
///
/// Refer to the documentation for [`CreateEmbedAuthor`] for more
/// information.
Expand All @@ -53,7 +53,11 @@ impl CreateEmbed {
where F: FnOnce(&mut CreateEmbedAuthor) -> &mut CreateEmbedAuthor {
let mut author = CreateEmbedAuthor::default();
f(&mut author);
self.set_author(author)
}

/// Set the author of the embed.
pub fn set_author(&mut self, author: CreateEmbedAuthor) -> &mut Self {
let map = utils::hashmap_to_json_map(author.0);

self.0.insert("author", Value::Object(map));
Expand Down Expand Up @@ -160,7 +164,7 @@ impl CreateEmbed {
self
}

/// Set the footer of the embed.
/// Build the footer of the embed.
///
/// Refer to the documentation for [`CreateEmbedFooter`] for more
/// information.
Expand All @@ -170,6 +174,11 @@ impl CreateEmbed {
where F: FnOnce(&mut CreateEmbedFooter) -> &mut CreateEmbedFooter {
let mut create_embed_footer = CreateEmbedFooter::default();
f(&mut create_embed_footer);
self.set_footer(create_embed_footer)
}

/// Set the footer of the embed.
pub fn set_footer(&mut self, create_embed_footer: CreateEmbedFooter) -> &mut Self {
let footer = create_embed_footer.0;
let map = utils::hashmap_to_json_map(footer);

Expand Down
7 changes: 6 additions & 1 deletion src/builder/create_message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,16 @@ impl<'a> CreateMessage<'a> {
self
}

/// Set an embed for the message.
/// Create an embed for the message.
pub fn embed<F>(&mut self, f: F) -> &mut Self
where F: FnOnce(&mut CreateEmbed) -> &mut CreateEmbed {
let mut embed = CreateEmbed::default();
f(&mut embed);
self.set_embed(embed)
}

/// Set an embed for the message.
pub fn set_embed(&mut self, embed: CreateEmbed) -> &mut Self {
let map = utils::hashmap_to_json_map(embed.0);
let embed = Value::Object(map);

Expand Down

0 comments on commit b522e83

Please sign in to comment.