diff options
| author | Zeyla Hellyer <[email protected]> | 2018-01-18 10:36:50 -0800 |
|---|---|---|
| committer | Zeyla Hellyer <[email protected]> | 2018-01-18 10:36:50 -0800 |
| commit | edb76627d3fe292688b3c072c3d3f40db52e8aef (patch) | |
| tree | b37affd2a928d1845bdebe23a5456f7e3e878fd0 /src/model | |
| parent | Update readme example (diff) | |
| download | serenity-edb76627d3fe292688b3c072c3d3f40db52e8aef.tar.xz serenity-edb76627d3fe292688b3c072c3d3f40db52e8aef.zip | |
Add an `EditMessage` builder
When editing messages, not all fields are applicable. Attachments, TTS,
and reactions are not applicable. To help with this distinction,
separate message editing into a different builder.
Diffstat (limited to 'src/model')
| -rw-r--r-- | src/model/channel/channel_id.rs | 12 | ||||
| -rw-r--r-- | src/model/channel/group.rs | 10 | ||||
| -rw-r--r-- | src/model/channel/guild_channel.rs | 10 | ||||
| -rw-r--r-- | src/model/channel/message.rs | 16 | ||||
| -rw-r--r-- | src/model/channel/mod.rs | 10 | ||||
| -rw-r--r-- | src/model/channel/private_channel.rs | 10 |
6 files changed, 32 insertions, 36 deletions
diff --git a/src/model/channel/channel_id.rs b/src/model/channel/channel_id.rs index 7093dfb..5cb8763 100644 --- a/src/model/channel/channel_id.rs +++ b/src/model/channel/channel_id.rs @@ -6,7 +6,7 @@ use std::borrow::Cow; #[cfg(feature = "model")] use std::fmt::Write as FmtWrite; #[cfg(feature = "model")] -use builder::{CreateMessage, EditChannel, GetMessages}; +use builder::{CreateMessage, EditChannel, EditMessage, GetMessages}; #[cfg(all(feature = "cache", feature = "model"))] use CACHE; #[cfg(feature = "model")] @@ -200,7 +200,7 @@ impl ChannelId { /// /// Message editing preserves all unchanged message data. /// - /// Refer to the documentation for [`CreateMessage`] for more information + /// Refer to the documentation for [`EditMessage`] for more information /// regarding message restrictions and requirements. /// /// **Note**: Requires that the current user be the author of the message. @@ -212,12 +212,12 @@ impl ChannelId { /// over the limit. /// /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong - /// [`CreateMessage`]: ../builder/struct.CreateMessage.html + /// [`EditMessage`]: ../builder/struct.EditMessage.html /// [`Message`]: struct.Message.html - /// [`the limit`]: ../builder/struct.CreateMessage.html#method.content + /// [`the limit`]: ../builder/struct.EditMessage.html#method.content pub fn edit_message<F, M>(&self, message_id: M, f: F) -> Result<Message> - where F: FnOnce(CreateMessage) -> CreateMessage, M: Into<MessageId> { - let msg = f(CreateMessage::default()); + where F: FnOnce(EditMessage) -> EditMessage, M: Into<MessageId> { + let msg = f(EditMessage::default()); if let Some(content) = msg.0.get(&"content") { if let Value::String(ref content) = *content { diff --git a/src/model/channel/group.rs b/src/model/channel/group.rs index 69e9cc7..0ee2a71 100644 --- a/src/model/channel/group.rs +++ b/src/model/channel/group.rs @@ -2,7 +2,7 @@ use chrono::{DateTime, FixedOffset}; use model::prelude::*; #[cfg(feature = "model")] -use builder::{CreateMessage, GetMessages}; +use builder::{CreateMessage, EditMessage, GetMessages}; #[cfg(feature = "model")] use http::{self, AttachmentType}; #[cfg(feature = "model")] @@ -134,7 +134,7 @@ impl Group { /// /// Message editing preserves all unchanged message data. /// - /// Refer to the documentation for [`CreateMessage`] for more information + /// Refer to the documentation for [`EditMessage`] for more information /// regarding message restrictions and requirements. /// /// **Note**: Requires that the current user be the author of the message. @@ -146,12 +146,12 @@ impl Group { /// over the limit. /// /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong - /// [`CreateMessage`]: ../builder/struct.CreateMessage.html + /// [`EditMessage`]: ../builder/struct.EditMessage.html /// [`Message`]: struct.Message.html - /// [`the limit`]: ../builder/struct.CreateMessage.html#method.content + /// [`the limit`]: ../builder/struct.EditMessage.html#method.content #[inline] pub fn edit_message<F, M>(&self, message_id: M, f: F) -> Result<Message> - where F: FnOnce(CreateMessage) -> CreateMessage, M: Into<MessageId> { + where F: FnOnce(EditMessage) -> EditMessage, M: Into<MessageId> { self.channel_id.edit_message(message_id, f) } diff --git a/src/model/channel/guild_channel.rs b/src/model/channel/guild_channel.rs index 3653cb6..ef14d07 100644 --- a/src/model/channel/guild_channel.rs +++ b/src/model/channel/guild_channel.rs @@ -4,7 +4,7 @@ use model::prelude::*; #[cfg(all(feature = "cache", feature = "model"))] use CACHE; #[cfg(feature = "model")] -use builder::{CreateInvite, CreateMessage, EditChannel, GetMessages}; +use builder::{CreateInvite, CreateMessage, EditChannel, EditMessage, GetMessages}; #[cfg(feature = "model")] use http::{self, AttachmentType}; #[cfg(all(feature = "cache", feature = "model"))] @@ -333,7 +333,7 @@ impl GuildChannel { /// /// Message editing preserves all unchanged message data. /// - /// Refer to the documentation for [`CreateMessage`] for more information + /// Refer to the documentation for [`EditMessage`] for more information /// regarding message restrictions and requirements. /// /// **Note**: Requires that the current user be the author of the message. @@ -345,12 +345,12 @@ impl GuildChannel { /// over the limit. /// /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong - /// [`CreateMessage`]: ../builder/struct.CreateMessage.html + /// [`EditMessage`]: ../builder/struct.EditMessage.html /// [`Message`]: struct.Message.html - /// [`the limit`]: ../builder/struct.CreateMessage.html#method.content + /// [`the limit`]: ../builder/struct.EditMessage.html#method.content #[inline] pub fn edit_message<F, M>(&self, message_id: M, f: F) -> Result<Message> - where F: FnOnce(CreateMessage) -> CreateMessage, M: Into<MessageId> { + where F: FnOnce(EditMessage) -> EditMessage, M: Into<MessageId> { self.id.edit_message(message_id, f) } diff --git a/src/model/channel/message.rs b/src/model/channel/message.rs index f3834bd..d8abf3d 100644 --- a/src/model/channel/message.rs +++ b/src/model/channel/message.rs @@ -5,7 +5,7 @@ use model::prelude::*; use serde_json::Value; #[cfg(feature = "model")] -use builder::{CreateEmbed, CreateMessage}; +use builder::{CreateEmbed, EditMessage}; #[cfg(all(feature = "cache", feature = "model"))] use CACHE; #[cfg(all(feature = "cache", feature = "model"))] @@ -178,7 +178,7 @@ impl Message { /// /// Message editing preserves all unchanged message data. /// - /// Refer to the documentation for [`CreateMessage`] for more information + /// Refer to the documentation for [`EditMessage`] for more information /// regarding message restrictions and requirements. /// /// **Note**: Requires that the current user be the author of the message. @@ -204,10 +204,10 @@ impl Message { /// /// [`ModelError::InvalidUser`]: enum.ModelError.html#variant.InvalidUser /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong - /// [`CreateMessage`]: ../builder/struct.CreateMessage.html - /// [`the limit`]: ../builder/struct.CreateMessage.html#method.content + /// [`EditMessage`]: ../builder/struct.EditMessage.html + /// [`the limit`]: ../builder/struct.EditMessage.html#method.content pub fn edit<F>(&mut self, f: F) -> Result<()> - where F: FnOnce(CreateMessage) -> CreateMessage { + where F: FnOnce(EditMessage) -> EditMessage { #[cfg(feature = "cache")] { if self.author.id != CACHE.read().user.id { @@ -215,7 +215,7 @@ impl Message { } } - let mut builder = CreateMessage::default(); + let mut builder = EditMessage::default(); if !self.content.is_empty() { builder = builder.content(&self.content); @@ -225,10 +225,6 @@ impl Message { builder = builder.embed(|_| CreateEmbed::from(embed.clone())); } - if self.tts { - builder = builder.tts(true); - } - let map = serenity_utils::vecmap_to_json_map(f(builder).0); match http::edit_message(self.channel_id.0, self.id.0, &Value::Object(map)) { diff --git a/src/model/channel/mod.rs b/src/model/channel/mod.rs index 1a6bcd5..eadc7bb 100644 --- a/src/model/channel/mod.rs +++ b/src/model/channel/mod.rs @@ -28,7 +28,7 @@ use serde_json; use super::utils::deserialize_u64; #[cfg(feature = "model")] -use builder::{CreateMessage, GetMessages}; +use builder::{CreateMessage, EditMessage, GetMessages}; #[cfg(feature = "model")] use http::AttachmentType; #[cfg(feature = "model")] @@ -277,7 +277,7 @@ impl Channel { /// /// Message editing preserves all unchanged message data. /// - /// Refer to the documentation for [`CreateMessage`] for more information + /// Refer to the documentation for [`EditMessage`] for more information /// regarding message restrictions and requirements. /// /// **Note**: Requires that the current user be the author of the message. @@ -289,14 +289,14 @@ impl Channel { /// over the limit. /// /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong - /// [`CreateMessage`]: ../builder/struct.CreateMessage.html + /// [`EditMessage`]: ../builder/struct.EditMessage.html /// [`Message`]: struct.Message.html - /// [`the limit`]: ../builder/struct.CreateMessage.html#method.content + /// [`the limit`]: ../builder/struct.EditMessage.html#method.content #[cfg(feature = "model")] #[deprecated(since = "0.4.2", note = "Use the inner channel's method")] #[inline] pub fn edit_message<F, M>(&self, message_id: M, f: F) -> Result<Message> - where F: FnOnce(CreateMessage) -> CreateMessage, M: Into<MessageId> { + where F: FnOnce(EditMessage) -> EditMessage, M: Into<MessageId> { self.id().edit_message(message_id, f) } diff --git a/src/model/channel/private_channel.rs b/src/model/channel/private_channel.rs index 39dcac3..3bae61d 100644 --- a/src/model/channel/private_channel.rs +++ b/src/model/channel/private_channel.rs @@ -4,7 +4,7 @@ use std::fmt::{Display, Formatter, Result as FmtResult}; use super::deserialize_single_recipient; #[cfg(feature = "model")] -use builder::{CreateMessage, GetMessages}; +use builder::{CreateMessage, EditMessage, GetMessages}; #[cfg(feature = "model")] use http::AttachmentType; #[cfg(feature = "model")] @@ -116,7 +116,7 @@ impl PrivateChannel { /// /// Message editing preserves all unchanged message data. /// - /// Refer to the documentation for [`CreateMessage`] for more information + /// Refer to the documentation for [`EditMessage`] for more information /// regarding message restrictions and requirements. /// /// **Note**: Requires that the current user be the author of the message. @@ -128,12 +128,12 @@ impl PrivateChannel { /// over the limit. /// /// [`ModelError::MessageTooLong`]: enum.ModelError.html#variant.MessageTooLong - /// [`CreateMessage`]: ../builder/struct.CreateMessage.html + /// [`EditMessage`]: ../builder/struct.EditMessage.html /// [`Message`]: struct.Message.html - /// [`the limit`]: ../builder/struct.CreateMessage.html#method.content + /// [`the limit`]: ../builder/struct.EditMessage.html#method.content #[inline] pub fn edit_message<F, M>(&self, message_id: M, f: F) -> Result<Message> - where F: FnOnce(CreateMessage) -> CreateMessage, M: Into<MessageId> { + where F: FnOnce(EditMessage) -> EditMessage, M: Into<MessageId> { self.id.edit_message(message_id, f) } |