From f22db11c90bb4a0fd05c1272f2572297cc9ff144 Mon Sep 17 00:00:00 2001 From: Gnome! <45660393+GnomedDev@users.noreply.github.com> Date: Fri, 3 Jun 2022 16:18:02 +0100 Subject: [PATCH] Fix clippy warnings (#1933) --- src/framework/standard/help_commands.rs | 7 +--- src/framework/standard/mod.rs | 53 ++++++++++++------------- src/http/routing.rs | 2 +- src/model/guild/emoji.rs | 45 +++++++++------------ 4 files changed, 47 insertions(+), 60 deletions(-) diff --git a/src/framework/standard/help_commands.rs b/src/framework/standard/help_commands.rs index 891c0eba721..5dc8c3bccf2 100644 --- a/src/framework/standard/help_commands.rs +++ b/src/framework/standard/help_commands.rs @@ -580,7 +580,7 @@ async fn fetch_single_command<'a>( let mut similar_commands: Vec = Vec::new(); let mut name = name.to_string(); - match nested_group_command_search( + nested_group_command_search( ctx, msg, groups, @@ -590,10 +590,7 @@ async fn fetch_single_command<'a>( owners, ) .await - { - Ok(found) => Ok(found), - Err(()) => Err(similar_commands), - } + .map_err(|_| similar_commands) } #[cfg(feature = "cache")] diff --git a/src/framework/standard/mod.rs b/src/framework/standard/mod.rs index f61eebf91f8..a5b2ffa6dc2 100644 --- a/src/framework/standard/mod.rs +++ b/src/framework/standard/mod.rs @@ -858,34 +858,31 @@ pub(crate) fn has_correct_permissions( if options.required_permissions().is_empty() { true } else { - message - .guild(cache.as_ref()) - .map(|guild| { - let channel = match guild.channels.get(&message.channel_id) { - Some(Channel::Guild(channel)) => channel, - _ => return false, - }; - - let member = match guild.members.get(&message.author.id) { - Some(member) => member, - None => return false, - }; - - match guild.user_permissions_in(channel, member) { - Ok(perms) => perms.contains(*options.required_permissions()), - Err(e) => { - tracing::error!( - "Error getting permissions for user {} in channel {}: {}", - member.user.id, - channel.id, - e - ); - - false - }, - } - }) - .unwrap_or(false) + message.guild(cache.as_ref()).map_or(false, |guild| { + let channel = match guild.channels.get(&message.channel_id) { + Some(Channel::Guild(channel)) => channel, + _ => return false, + }; + + let member = match guild.members.get(&message.author.id) { + Some(member) => member, + None => return false, + }; + + match guild.user_permissions_in(channel, member) { + Ok(perms) => perms.contains(*options.required_permissions()), + Err(e) => { + tracing::error!( + "Error getting permissions for user {} in channel {}: {}", + member.user.id, + channel.id, + e + ); + + false + }, + } + }) } } diff --git a/src/http/routing.rs b/src/http/routing.rs index d4c9f806520..038837cc26e 100644 --- a/src/http/routing.rs +++ b/src/http/routing.rs @@ -1098,7 +1098,7 @@ impl Route { let mut s = api!("/webhooks/{}/{}?wait={}", webhook_id, token, wait); if let Some(thread_id) = thread_id { - s.push_str(&format!("&thread_id={}", thread_id)); + write!(s, "&thread_id={}", thread_id).unwrap(); } s diff --git a/src/model/guild/emoji.rs b/src/model/guild/emoji.rs index eaae2d9db33..e22e050650c 100644 --- a/src/model/guild/emoji.rs +++ b/src/model/guild/emoji.rs @@ -2,8 +2,8 @@ use std::fmt; #[cfg(all(feature = "cache", feature = "model"))] use crate::cache::Cache; -#[cfg(feature = "cache")] -use crate::http::Http; +#[cfg(all(feature = "cache", feature = "model"))] +use crate::http::CacheHttp; #[cfg(all(feature = "cache", feature = "model"))] use crate::internal::prelude::*; #[cfg(all(feature = "cache", feature = "model"))] @@ -96,13 +96,9 @@ impl Emoji { /// [Manage Emojis and Stickers]: crate::model::permissions::Permissions::MANAGE_EMOJIS_AND_STICKERS #[cfg(feature = "cache")] #[inline] - pub async fn delete + AsRef>(&self, cache_http: T) -> Result<()> { - match self.find_guild_id(&cache_http) { - Some(guild_id) => { - AsRef::::as_ref(&cache_http).delete_emoji(guild_id.0, self.id.0).await - }, - None => Err(Error::Model(ModelError::ItemMissing)), - } + pub async fn delete(&self, cache_http: impl CacheHttp) -> Result<()> { + let guild_id = self.try_find_guild_id(&cache_http)?; + cache_http.http().delete_emoji(guild_id.0, self.id.0).await } /// Edits the emoji by updating it with a new name. @@ -117,25 +113,13 @@ impl Emoji { /// /// [Manage Emojis and Stickers]: crate::model::permissions::Permissions::MANAGE_EMOJIS_AND_STICKERS #[cfg(feature = "cache")] - pub async fn edit + AsRef>( - &mut self, - cache_http: T, - name: &str, - ) -> Result<()> { - match self.find_guild_id(&cache_http) { - Some(guild_id) => { - let map = json!({ - "name": name, - }); + pub async fn edit(&mut self, cache_http: impl CacheHttp, name: &str) -> Result<()> { + let guild_id = self.try_find_guild_id(&cache_http)?; + let map = json!({ "name": name }); - *self = AsRef::::as_ref(&cache_http) - .edit_emoji(guild_id.0, self.id.0, &map, None) - .await?; + *self = cache_http.http().edit_emoji(guild_id.0, self.id.0, &map, None).await?; - Ok(()) - }, - None => Err(Error::Model(ModelError::ItemMissing)), - } + Ok(()) } /// Finds the [`Guild`] that owns the emoji by looking through the Cache. @@ -172,6 +156,15 @@ impl Emoji { None } + #[cfg(feature = "cache")] + #[inline] + fn try_find_guild_id(&self, cache_http: impl CacheHttp) -> Result { + cache_http + .cache() + .and_then(|c| self.find_guild_id(c)) + .ok_or(Error::Model(ModelError::ItemMissing)) + } + /// Generates a URL to the emoji's image. /// /// # Examples