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 | |
| 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')
| -rw-r--r-- | src/model/channel/reaction.rs | 53 | ||||
| -rw-r--r-- | src/model/user.rs | 61 |
2 files changed, 60 insertions, 54 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) } diff --git a/src/model/user.rs b/src/model/user.rs index 66b7285..359d497 100644 --- a/src/model/user.rs +++ b/src/model/user.rs @@ -492,35 +492,38 @@ impl User { return Err(Error::Model(ModelError::MessagingBot)); } - let private_channel_id = feature_cache! {{ - let finding = { - let cache = CACHE.read().unwrap(); - - let finding = cache.private_channels - .values() - .map(|ch| ch.read().unwrap()) - .find(|ch| ch.recipient.read().unwrap().id == self.id) - .map(|ch| ch.id); - - finding - }; - - if let Some(finding) = finding { - finding - } else { - let map = json!({ - "recipient_id": self.id.0, - }); - - http::create_private_channel(&map)?.id - } - } else { - let map = json!({ - "recipient_id": self.id.0, - }); - - http::create_private_channel(&map)?.id - }}; + let private_channel_id = + feature_cache! { + { + let finding = { + let cache = CACHE.read().unwrap(); + + let finding = cache.private_channels + .values() + .map(|ch| ch.read().unwrap()) + .find(|ch| ch.recipient.read().unwrap().id == self.id) + .map(|ch| ch.id); + + finding + }; + + if let Some(finding) = finding { + finding + } else { + let map = json!({ + "recipient_id": self.id.0, + }); + + http::create_private_channel(&map)?.id + } + } else { + let map = json!({ + "recipient_id": self.id.0, + }); + + http::create_private_channel(&map)?.id + } + }; private_channel_id.send_message(f) } |