diff options
| author | Austin Hellyer <[email protected]> | 2016-11-15 20:25:32 -0700 |
|---|---|---|
| committer | Austin Hellyer <[email protected]> | 2016-11-15 20:25:08 -0800 |
| commit | 56011c411563670d0aa1625ece1218be0af8b09e (patch) | |
| tree | 52b895ccf5ddaaa8d399a2a2a38dee786910aa5b /src/utils/builder/create_message.rs | |
| parent | Add state/framework/etc. conditional compile flags (diff) | |
| download | serenity-56011c411563670d0aa1625ece1218be0af8b09e.tar.xz serenity-56011c411563670d0aa1625ece1218be0af8b09e.zip | |
Add send_message rich embeds
Diffstat (limited to 'src/utils/builder/create_message.rs')
| -rw-r--r-- | src/utils/builder/create_message.rs | 26 |
1 files changed, 23 insertions, 3 deletions
diff --git a/src/utils/builder/create_message.rs b/src/utils/builder/create_message.rs index dc601a4..9bbc461 100644 --- a/src/utils/builder/create_message.rs +++ b/src/utils/builder/create_message.rs @@ -1,11 +1,16 @@ use serde_json::Value; use std::collections::BTreeMap; use std::default::Default; +use super::CreateEmbed; /// A builder to specify the contents of an [`http::create_message`] request, /// primarily meant for use through [`Context::send_message`]. /// -/// `content` is the only required field. +/// There are two situations where different field requirements are present: +/// +/// 1. When sending an [`embed`], no other field is required; +/// 2. Otherwise, [`content`] is the only required field that is required to be +/// set. /// /// Note that if you only need to send the content of a message, without /// specifying other fields, then [`Context::say`] may be a more preferable @@ -13,7 +18,7 @@ use std::default::Default; /// /// # Examples /// -/// Sending a message with a content of `test` and applying text-to-speech: +/// Sending a message with a content of `"test"` and applying text-to-speech: /// /// ```rust,ignore /// // assuming you are in a context @@ -24,6 +29,8 @@ use std::default::Default; /// /// [`Context::say`]: ../../client/struct.Context.html#method.say /// [`Context::send_message`]: ../../client/struct.Context.html#method.send_message +/// [`content`]: #method.content +/// [`embed`]: #method.embed /// [`http::create_message`]: ../../client/http/fn.create_message.html pub struct CreateMessage(pub BTreeMap<String, Value>); @@ -37,6 +44,16 @@ impl CreateMessage { CreateMessage(self.0) } + /// Set an embed for the message. + pub fn embed<F>(mut self, f: F) -> Self + where F: FnOnce(CreateEmbed) -> CreateEmbed { + let embed = Value::Object(f(CreateEmbed::default()).0); + + self.0.insert("embed".to_owned(), embed); + + CreateMessage(self.0) + } + /// Set the nonce. This is used for validation of a sent message. You most /// likely don't need to worry about this. /// @@ -60,8 +77,11 @@ impl CreateMessage { } impl Default for CreateMessage { - /// Creates a map for sending a [`Message`], setting `tts` to `false` by + /// Creates a map for sending a [`Message`], setting [`tts`] to `false` by /// default. + /// + /// [`Message`]: ../../model/struct.Message.html + /// [`tts`]: #method.tts fn default() -> CreateMessage { let mut map = BTreeMap::default(); map.insert("tts".to_owned(), Value::Bool(false)); |