Skip to content

Commit

Permalink
Fix clippy warnings (serenity-rs#1933)
Browse files Browse the repository at this point in the history
  • Loading branch information
GnomedDev authored and arqunis committed Sep 2, 2022
1 parent 9871901 commit 2a64777
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 60 deletions.
7 changes: 2 additions & 5 deletions src/framework/standard/help_commands.rs
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,7 @@ async fn fetch_single_command<'a>(
let mut similar_commands: Vec<SuggestedCommandName> = Vec::new();
let mut name = name.to_string();

match nested_group_command_search(
nested_group_command_search(
ctx,
msg,
groups,
Expand All @@ -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")]
Expand Down
53 changes: 25 additions & 28 deletions src/framework/standard/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
}
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/http/routing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
45 changes: 19 additions & 26 deletions src/model/guild/emoji.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"))]
Expand Down Expand Up @@ -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<T: AsRef<Cache> + AsRef<Http>>(&self, cache_http: T) -> Result<()> {
match self.find_guild_id(&cache_http) {
Some(guild_id) => {
AsRef::<Http>::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.
Expand All @@ -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<T: AsRef<Cache> + AsRef<Http>>(
&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::<Http>::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.
Expand Down Expand Up @@ -172,6 +156,15 @@ impl Emoji {
None
}

#[cfg(feature = "cache")]
#[inline]
fn try_find_guild_id(&self, cache_http: impl CacheHttp) -> Result<GuildId> {
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
Expand Down

0 comments on commit 2a64777

Please sign in to comment.