aboutsummaryrefslogtreecommitdiff
path: root/src/model
diff options
context:
space:
mode:
authorAustin Hellyer <[email protected]>2016-11-11 13:07:18 -0800
committerAustin Hellyer <[email protected]>2016-11-11 13:07:18 -0800
commita40d821a7cf0361bbffdedcb5f91761a1a285401 (patch)
treeb787a46ad5619bb29121f6134bff4f0005fa2f96 /src/model
parentAdd a clippy config (diff)
downloadserenity-a40d821a7cf0361bbffdedcb5f91761a1a285401.tar.xz
serenity-a40d821a7cf0361bbffdedcb5f91761a1a285401.zip
Add delete_message_reactions + register event
Add the `delete_message_reactions` endpoint (`DELETE /channels/{}/messages/{}/reactions`) and implement a method on the `Message` struct for easy access, `delete_reactions`. Register the `MESSAGE_REACTION_REMOVE_ALL` event and add an event handler.
Diffstat (limited to 'src/model')
-rw-r--r--src/model/channel.rs26
-rw-r--r--src/model/gateway.rs19
2 files changed, 43 insertions, 2 deletions
diff --git a/src/model/channel.rs b/src/model/channel.rs
index 178db25..989bda8 100644
--- a/src/model/channel.rs
+++ b/src/model/channel.rs
@@ -404,8 +404,8 @@ impl Message {
/// Returns a [`ClientError::InvalidPermissions`] if the current user does
/// not have the required permissions.
///
- /// [`ClientError::InvalidPermissions]: ../client/enum.ClientError.html#variant.InvalidPermissions
- /// [`ClientError::InvalidUser]: ../client/enum.ClientError.html#variant.InvalidUser
+ /// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
+ /// [`ClientError::InvalidUser`]: ../client/enum.ClientError.html#variant.InvalidUser
/// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
pub fn delete(&self) -> Result<()> {
let req = permissions::MANAGE_MESSAGES;
@@ -422,6 +422,28 @@ impl Message {
http::delete_message(self.channel_id.0, self.id.0)
}
+ /// Deletes all of the [`Reaction`]s associated with the message.
+ ///
+ /// **Note**: Requires the [Manage Messages] permission.
+ ///
+ /// # Errors
+ ///
+ /// Returns a [`ClientError::InvalidPermissions`] if the current user does
+ /// not have the required permissions.
+ ///
+ /// [`ClientError::InvalidPermissions`]: ../client/enum.ClientError.html#variant.InvalidPermissions
+ /// [`Reaction`]: struct.Reaction.html
+ /// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html
+ pub fn delete_reactions(&self) -> Result<()> {
+ let req = permissions::MANAGE_MESSAGES;
+
+ if !try!(utils::user_has_perms(self.channel_id, req)) {
+ return Err(Error::Client(ClientError::InvalidPermissions(req)));
+ }
+
+ http::delete_message_reactions(self.channel_id.0, self.id.0)
+ }
+
/// Edits this message, replacing the original content with new content.
///
/// **Note**: You must be the author of the message to be able to do this.
diff --git a/src/model/gateway.rs b/src/model/gateway.rs
index dfdddf2..35a65d0 100644
--- a/src/model/gateway.rs
+++ b/src/model/gateway.rs
@@ -222,6 +222,12 @@ pub struct ReactionRemoveEvent {
pub reaction: Reaction,
}
+#[derive(Clone, Copy, Debug)]
+pub struct ReactionRemoveAllEvent {
+ pub channel_id: ChannelId,
+ pub message_id: MessageId,
+}
+
/// The "Ready" event, containing initial state
#[derive(Clone, Debug)]
pub struct ReadyEvent {
@@ -467,6 +473,14 @@ pub enum Event {
///
/// [`on_message_reaction_remove`]: ../client/struct.Client.html#method.on_message_reaction_remove
ReactionRemove(ReactionRemoveEvent),
+ /// A request was issued to remove all [`Reaction`]s from a [`Message`].
+ ///
+ /// Fires the [`on_reaction_remove_all`] event handler.
+ ///
+ /// [`Message`]: struct.Message.html
+ /// [`Reaction`]: struct.Reaction.html
+ /// [`on_reaction_remove_all`]: ../client/struct.Clint.html#method.on_reaction_remove_all
+ ReactionRemoveAll(ReactionRemoveAllEvent),
/// The first event in a connection, containing the initial state.
///
/// May also be received at a later time in the event of a reconnect.
@@ -670,6 +684,11 @@ impl Event {
Ok(Event::ReactionRemove(ReactionRemoveEvent {
reaction: try!(Reaction::decode(Value::Object(value)))
}))
+ } else if kind == "MESSAGE_REACTION_REMOVE_ALL" {
+ Ok(Event::ReactionRemoveAll(ReactionRemoveAllEvent {
+ channel_id: try!(remove(&mut value, "channel_id").and_then(ChannelId::decode)),
+ message_id: try!(remove(&mut value, "message_id").and_then(MessageId::decode)),
+ }))
} else if kind == "MESSAGE_UPDATE" {
missing!(value, Event::MessageUpdate(MessageUpdateEvent {
id: try!(remove(&mut value, "id").and_then(MessageId::decode)),