Actually fix embeds

late-submissions
Elnu 2 years ago
parent e0f164338a
commit 3667074018

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

Loading…
Cancel
Save