diff --git a/src/commands/challenge.rs b/src/commands/challenge.rs index 924febd..cc2fd05 100644 --- a/src/commands/challenge.rs +++ b/src/commands/challenge.rs @@ -89,11 +89,11 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul Context::Prefix(ctx) => &ctx.msg.attachments, }; let author = ctx.author(); - let mut images = Vec::new(); + let mut submitted_images = Vec::new(); for (i, submission) in submission_data.iter_mut().enumerate() { if is_matching_submission(&submission, author) { existing_submitter = true; - images = submission["images"].as_array_mut().unwrap().clone().iter().map(|value| value.to_string()).collect(); + let images: Vec = submission["images"].as_array_mut().unwrap().clone().iter().map(|value| value.as_str().unwrap().to_owned()).collect(); for attachment in attachments.iter() { let extension; if let Some(content_type) = &attachment.content_type { @@ -118,12 +118,12 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul images.len() + 1, extension ); - images.push(file_name.clone().into()); let image = reqwest::get(&attachment.url).await?.bytes().await?; let mut image_file = File::create(format!("{}/{}", submission_images_dir, file_name))?; image_file.write_all(&image)?; image_file.flush()?; + submitted_images.push(file_name); } submission["images"] = images.clone().into(); break; @@ -202,7 +202,7 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul Some(data["invite"].as_str().unwrap()) } else { None }; - for image in images.iter() { + for image in submitted_images.iter() { for (other_guild_id, data) in guild_data.iter() { let here = other_guild_id.eq(&ctx.guild_id().unwrap().as_u64().to_string()); if !repost_here && here {