diff options
| author | Maiddog <[email protected]> | 2017-08-27 04:17:59 -0500 |
|---|---|---|
| committer | alex <[email protected]> | 2017-08-27 11:17:59 +0200 |
| commit | e1a8fe3e9f619fbb94dd54993c8f5d25fd5dc375 (patch) | |
| tree | 4c6c45cc592505f971c13aee8dfbdd41107a84ce /src/model/channel/reaction.rs | |
| parent | Add ability to play DCA and Opus files. (#148) (diff) | |
| download | serenity-e1a8fe3e9f619fbb94dd54993c8f5d25fd5dc375.tar.xz serenity-e1a8fe3e9f619fbb94dd54993c8f5d25fd5dc375.zip | |
Prevent malformed opus data from crashing the bot process (#149)
Diffstat (limited to 'src/model/channel/reaction.rs')
| -rw-r--r-- | src/model/channel/reaction.rs | 53 |
1 files changed, 28 insertions, 25 deletions
diff --git a/src/model/channel/reaction.rs b/src/model/channel/reaction.rs index be5dfb8..121bf43 100644 --- a/src/model/channel/reaction.rs +++ b/src/model/channel/reaction.rs @@ -46,31 +46,34 @@ impl Reaction { /// [Manage Messages]: permissions/constant.MANAGE_MESSAGES.html /// [permissions]: permissions pub fn delete(&self) -> Result<()> { - let user_id = feature_cache! {{ - let user = if self.user_id == CACHE.read().unwrap().user.id { - None - } else { - Some(self.user_id.0) - }; - - // If the reaction is one _not_ made by the current user, then ensure - // that the current user has permission* to delete the reaction. - // - // Normally, users can only delete their own reactions. - // - // * The `Manage Messages` permission. - if user.is_some() { - let req = permissions::MANAGE_MESSAGES; - - if !utils::user_has_perms(self.channel_id, req).unwrap_or(true) { - return Err(Error::Model(ModelError::InvalidPermissions(req))); - } - } - - user - } else { - Some(self.user_id.0) - }}; + let user_id = + feature_cache! { + { + let user = if self.user_id == CACHE.read().unwrap().user.id { + None + } else { + Some(self.user_id.0) + }; + + // If the reaction is one _not_ made by the current user, then ensure + // that the current user has permission* to delete the reaction. + // + // Normally, users can only delete their own reactions. + // + // * The `Manage Messages` permission. + if user.is_some() { + let req = permissions::MANAGE_MESSAGES; + + if !utils::user_has_perms(self.channel_id, req).unwrap_or(true) { + return Err(Error::Model(ModelError::InvalidPermissions(req))); + } + } + + user + } else { + Some(self.user_id.0) + } + }; http::delete_reaction(self.channel_id.0, self.message_id.0, user_id, &self.emoji) } |