Skip to content
This repository has been archived by the owner on Jul 5, 2024. It is now read-only.

Commit

Permalink
refactor: replace map_or(false, ..) with is_some_and(..)
Browse files Browse the repository at this point in the history
  • Loading branch information
vilgotf committed Jun 1, 2023
1 parent 7c30e57 commit 2e65816
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
4 changes: 2 additions & 2 deletions src/commands/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ pub async fn run(ctx: super::Context) -> super::Result {
crate::prune::guild(guild, |state| {
BOT.cache
.member(state.guild_id(), state.user_id())
.map_or(false, |member| member.roles().contains(&role))
.is_some_and(|member| member.roles().contains(&role))
})
.await
}
Expand All @@ -63,7 +63,7 @@ pub async fn run(ctx: super::Context) -> super::Result {
crate::prune::channel(channel, guild, |state| {
BOT.cache
.member(state.guild_id(), state.user_id())
.map_or(false, |member| member.roles().contains(&role))
.is_some_and(|member| member.roles().contains(&role))
})
.await
}
Expand Down
18 changes: 9 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,14 @@ async fn main() -> Result<(), anyhow::Error> {
/// Handle a gateway [`Event`].
async fn handle(event: Event) {
let skip = match &event {
// skip if permission did not change
Event::ChannelUpdate(c) => BOT.cache.channel(c.id).map_or(false, |cached| {
cached.permission_overwrites != c.permission_overwrites
}),
// skip if permissions did not change
Event::RoleUpdate(r) => {
BOT.cache.role(r.role.id).map(|r| r.permissions) != Some(r.role.permissions)
}
Event::ChannelUpdate(c) => BOT
.cache
.channel(c.id)
.is_some_and(|cached| cached.permission_overwrites != c.permission_overwrites),
Event::RoleUpdate(r) => BOT
.cache
.role(r.role.id)
.is_some_and(|cached| cached.permissions != r.role.permissions),
_ => false,
};

Expand Down Expand Up @@ -215,7 +215,7 @@ impl BotRef {
/// Whether the guild has auto prune enabled.
fn auto_prune(&self, guild: Id<GuildMarker>) -> bool {
// event order isn't guarenteed, so this might not be cached yet
self.cache.member(guild, self.id).map_or(false, |member| {
self.cache.member(guild, self.id).is_some_and(|member| {
!member
.roles()
.iter()
Expand Down

0 comments on commit 2e65816

Please sign in to comment.