From 2f67c59bb3536f0edc8ed2b400e10bfd9213959a Mon Sep 17 00:00:00 2001 From: oSumAtrIX Date: Fri, 7 Oct 2022 13:01:30 +0200 Subject: [PATCH] fix(moderation): save overwrites before modifying them --- src/commands/moderation.rs | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/src/commands/moderation.rs b/src/commands/moderation.rs index 194e912..9d62e05 100644 --- a/src/commands/moderation.rs +++ b/src/commands/moderation.rs @@ -9,6 +9,7 @@ use poise::serenity_prelude::{ RoleId, User, }; +use tracing::log::error; use tracing::{debug, trace}; use crate::db::model::{LockedChannel, Muted}; @@ -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(); @@ -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),