Skip to content

Commit

Permalink
Fallback to HTTP in user_permissions even with cache enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
kangalio committed Dec 5, 2022
1 parent 7015c2b commit b7a9f1f
Showing 1 changed file with 2 additions and 23 deletions.
25 changes: 2 additions & 23 deletions src/dispatch/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,7 @@ async fn user_permissions(
None => return Some(serenity::Permissions::all()), // no permission checks in DMs
};

#[cfg(feature = "cache")]
let guild = match ctx.cache.guild(guild_id) {
Some(x) => x,
None => return None, // Guild not in cache
};
#[cfg(not(feature = "cache"))]
let guild = match ctx.http.get_guild(guild_id.0).await {
Ok(x) => x,
Err(_) => return None,
};
let guild = guild_id.to_partial_guild(ctx).await.ok()?;

// Use to_channel so that it can fallback on HTTP for threads (which aren't in cache usually)
let channel = match channel_id.to_channel(ctx).await {
Expand All @@ -38,19 +29,7 @@ async fn user_permissions(
Err(_) => return None,
};

#[cfg(feature = "cache")]
let cached_member = guild.members.get(&user_id).cloned();
#[cfg(not(feature = "cache"))]
let cached_member = None;

// If member not in cache (probably because presences intent is not enabled), retrieve via HTTP
let member = match cached_member {
Some(x) => x,
None => match ctx.http.get_member(guild_id.0, user_id.0).await {
Ok(member) => member,
Err(_) => return None,
},
};
let member = guild.member(ctx, user_id).await.ok()?;

guild.user_permissions_in(&channel, &member).ok()
}
Expand Down

0 comments on commit b7a9f1f

Please sign in to comment.