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();