From e3d85efe968d5902af696be4c147367ab01dac3e Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Wed, 30 Nov 2022 00:34:37 -0800 Subject: [PATCH] Fix edge case where multiple attachments --- src/commands/challenge.rs | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/commands/challenge.rs b/src/commands/challenge.rs index cd37a25..b105d72 100644 --- a/src/commands/challenge.rs +++ b/src/commands/challenge.rs @@ -91,11 +91,11 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul }; let author = ctx.author(); let mut submitted_images = Vec::new(); - for (i, submission) in submission_data.iter_mut().enumerate() { + for submission in submission_data.iter_mut() { if is_matching_submission(&submission, author) { existing_submitter = true; let mut images: Vec = submission["images"].as_array_mut().unwrap().clone().iter().map(|value| value.as_str().unwrap().to_owned()).collect(); - for attachment in attachments.iter() { + for (i, attachment) in attachments.iter().enumerate() { let extension; if let Some(content_type) = &attachment.content_type { if content_type == "image/png" { @@ -112,11 +112,12 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul } requires_rebuild = true; let file_name = format!( - "{}-{}-{}-{}.{}", + "{}-{}-{}-{}{}.{}", i + 1, slugify(&author.name), author.discriminator, timestamp, + if i == 0 { "".to_owned() } else { format!("-{}", i + 1) }, extension ); images.push(file_name.clone().into()); @@ -138,7 +139,7 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul format!("{}#{}", author.name, author.discriminator).into(), ); let mut images: Vec = Vec::new(); - for attachment in attachments.iter() { + for (i, attachment) in attachments.iter().enumerate() { let extension; if let Some(content_type) = &attachment.content_type { if content_type == "image/png" { @@ -155,11 +156,12 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul } requires_rebuild = true; let file_name = format!( - "{}-{}-{}-{}.{}", + "{}-{}-{}-{}{}.{}", submission_data.len() + 1, slugify(&author.name), author.discriminator, timestamp, + if i == 0 { "".to_owned() } else { format!("-{}", i + 1) }, extension ); images.push(file_name.clone().into());