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

Commit

Permalink
fix(moderation): save overwrites before modifying them
Browse files Browse the repository at this point in the history
  • Loading branch information
oSumAtrIX committed Oct 7, 2022
1 parent 6279a79 commit 2f67c59
Showing 1 changed file with 18 additions and 13 deletions.
31 changes: 18 additions & 13 deletions src/commands/moderation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use poise::serenity_prelude::{
RoleId,
User,
};
use tracing::log::error;
use tracing::{debug, trace};

use crate::db::model::{LockedChannel, Muted};
Expand Down Expand Up @@ -72,21 +73,9 @@ pub async fn lock(ctx: Context<'_>) -> Result<(), Error> {
})
.collect();

// lock the channel by and creating the new permission overwrite
for permission_overwrite in &permission_overwrites {
let permission = Permissions::SEND_MESSAGES & Permissions::ADD_REACTIONS;
channel
.create_permission(http, &PermissionOverwrite {
allow: permission_overwrite.allow & !permission,
deny: permission_overwrite.deny | permission,
kind: permission_overwrite.kind,
})
.await?;
}

// save the original overwrites
let updated: Document = LockedChannel {
overwrites: Some(permission_overwrites),
overwrites: Some(permission_overwrites.clone()),
..Default::default()
}
.into();
Expand All @@ -100,6 +89,22 @@ pub async fn lock(ctx: Context<'_>) -> Result<(), Error> {
)
.await?;

// lock the channel by and creating the new permission overwrite
for permission_overwrite in &permission_overwrites {
let permission = Permissions::SEND_MESSAGES & Permissions::ADD_REACTIONS;

if let Err(err) = channel
.create_permission(http, &PermissionOverwrite {
allow: permission_overwrite.allow & !permission,
deny: permission_overwrite.deny | permission,
kind: permission_overwrite.kind,
})
.await
{
error!("Failed to create the new permission: {:?}", err);
}
}

respond_moderation(
&ctx,
&ModerationKind::Lock(channel.name.clone(), None),
Expand Down

0 comments on commit 2f67c59

Please sign in to comment.