From 83790e91c2b7c6cc3e9f71f58d33cee74dbb2b7e Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Tue, 29 Nov 2022 16:32:37 -0800 Subject: [PATCH] Fix imagedelete command --- src/commands/challenge.rs | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/src/commands/challenge.rs b/src/commands/challenge.rs index 45388a4..cd97b1f 100644 --- a/src/commands/challenge.rs +++ b/src/commands/challenge.rs @@ -315,6 +315,7 @@ pub async fn images(ctx: Context<'_>) -> Result<(), Error> { prefix_command, slash_command, ephemeral, + broadcast_typing, description_localized( "en-US", "Delete images from your current submission using image numbers from the images command." @@ -326,6 +327,9 @@ pub async fn imagedelete(ctx: Context<'_>, number: i32) -> Result<(), Error> { .await?; return Ok(()); } + if let Context::Application(_) = ctx { + ctx.defer_ephemeral().await?; + } let challenge_number = get_challenge_number(); let mut submission_data = get_current_submission_data(); for (i, submission) in submission_data.iter_mut().enumerate() { @@ -396,6 +400,12 @@ pub async fn imagedelete(ctx: Context<'_>, number: i32) -> Result<(), Error> { Path::new(old).extension().unwrap().to_str().unwrap() ); let to = format!("{}/{}", submission_images_dir, new); + if old.eq(&new) { + // TODO: This could be made more efficient by + // automatically starting iteration just after deleted image + // since only images with later indexes will be affected + continue; + } fs_extra::file::move_file(from, to, &fs_extra::file::CopyOptions::default()) .unwrap(); *image = new.into();