From 437c177ab3b32121afcfce1f5df03a7e3ef44f38 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Wed, 23 Nov 2022 14:20:20 -0800 Subject: [PATCH] Actually fix embeds --- src/commands/challenge.rs | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/commands/challenge.rs b/src/commands/challenge.rs index 1d74f1e..9ac5742 100644 --- a/src/commands/challenge.rs +++ b/src/commands/challenge.rs @@ -93,7 +93,7 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul for (i, submission) in submission_data.iter_mut().enumerate() { if is_matching_submission(&submission, author) { existing_submitter = true; - let images: Vec = submission["images"].as_array_mut().unwrap().clone().iter().map(|value| value.as_str().unwrap().to_owned()).collect(); + 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() { let extension; if let Some(content_type) = &attachment.content_type { @@ -118,6 +118,7 @@ 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))?; @@ -227,11 +228,7 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul .await .unwrap() .accent_colour; - let mut pathbuf = std::path::PathBuf::new(); - pathbuf.push(&submission_images_dir); - pathbuf.push(&image); channel.send_message(&ctx.discord().http, |m| { - m.add_file(&pathbuf); m.embed(|e| { let username = format!("{}#{}", author.name, author.discriminator); let n = get_challenge_number(); @@ -250,14 +247,14 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul .name(username) .url(format!("https://discord.com/users/{}", author.id)); e.set_author(embed_author); - e.image(format!("attachment://{image}")); + e.image(format!("https://tegakituesday.com/{n}/{image}")); if let Some(accent_color) = accent_color { e.color(accent_color); } e }); m - }).await?; + }).await.unwrap(); } } } else if invalid_types {