aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authoralex <[email protected]>2017-05-25 01:36:59 +0200
committerZeyla Hellyer <[email protected]>2017-05-24 16:36:59 -0700
commit77b5b480d67e747908f8f4fb9f910bab23b761b5 (patch)
treea8f62266916a0dbefac576c14f6de189c07159db /src
parentAdd more examples and improve some others (diff)
downloadserenity-77b5b480d67e747908f8f4fb9f910bab23b761b5.tar.xz
serenity-77b5b480d67e747908f8f4fb9f910bab23b761b5.zip
Support adding reactions when creating message
These reactions are added onto the `MessageCreate` builder, and are sent after the message has been created.
Diffstat (limited to 'src')
-rw-r--r--src/builder/create_message.rs18
-rw-r--r--src/model/channel/channel_id.rs12
2 files changed, 23 insertions, 7 deletions
diff --git a/src/builder/create_message.rs b/src/builder/create_message.rs
index 9a2349a..14be4ca 100644
--- a/src/builder/create_message.rs
+++ b/src/builder/create_message.rs
@@ -1,4 +1,5 @@
use super::CreateEmbed;
+use ::model::ReactionType;
use ::internal::prelude::*;
/// A builder to specify the contents of an [`http::send_message`] request,
@@ -37,7 +38,7 @@ use ::internal::prelude::*;
/// [`embed`]: #method.embed
/// [`http::send_message`]: ../http/fn.send_message.html
#[derive(Clone, Debug)]
-pub struct CreateMessage(pub Map<String, Value>);
+pub struct CreateMessage(pub Map<String, Value>, pub Option<Vec<ReactionType>>);
impl CreateMessage {
/// Set the content of the message.
@@ -46,7 +47,7 @@ impl CreateMessage {
pub fn content(mut self, content: &str) -> Self {
self.0.insert("content".to_owned(), Value::String(content.to_owned()));
- CreateMessage(self.0)
+ CreateMessage(self.0, self.1)
}
/// Set an embed for the message.
@@ -56,7 +57,7 @@ impl CreateMessage {
self.0.insert("embed".to_owned(), embed);
- CreateMessage(self.0)
+ CreateMessage(self.0, self.1)
}
/// Set whether the message is text-to-speech.
@@ -67,7 +68,14 @@ impl CreateMessage {
pub fn tts(mut self, tts: bool) -> Self {
self.0.insert("tts".to_owned(), Value::Bool(tts));
- CreateMessage(self.0)
+ CreateMessage(self.0, self.1)
+ }
+
+ /// Adds a list of reactions to create after the message's sent.
+ pub fn reactions<R: Into<ReactionType>>(mut self, reactions: Vec<R>) -> Self {
+ self.1 = Some(reactions.into_iter().map(|r| r.into()).collect());
+
+ CreateMessage(self.0, self.1)
}
}
@@ -81,6 +89,6 @@ impl Default for CreateMessage {
let mut map = Map::default();
map.insert("tts".to_owned(), Value::Bool(false));
- CreateMessage(map)
+ CreateMessage(map, None)
}
}
diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs
index 3967dba..76fe6f7 100644
--- a/src/model/channel/channel_id.rs
+++ b/src/model/channel/channel_id.rs
@@ -425,12 +425,20 @@ impl ChannelId {
/// [Send Messages]: permissions/constant.SEND_MESSAGES.html
pub fn send_message<F>(&self, f: F) -> Result<Message>
where F: FnOnce(CreateMessage) -> CreateMessage {
- let map = f(CreateMessage::default()).0;
+ let CreateMessage(map, reactions) = f(CreateMessage::default());
Message::check_content_length(&map)?;
Message::check_embed_length(&map)?;
- http::send_message(self.0, &Value::Object(map))
+ let message = http::send_message(self.0, &Value::Object(map))?;
+
+ if let Some(reactions) = reactions {
+ for reaction in reactions {
+ self.create_reaction(message.id, reaction)?;
+ }
+ }
+
+ Ok(message)
}
/// Unpins a [`Message`] in the channel given by its Id.