Actually fix embeds

late-submissions
Elnu 2 years ago
parent f7fbd48df5
commit 437c177ab3

@ -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<String> = submission["images"].as_array_mut().unwrap().clone().iter().map(|value| value.as_str().unwrap().to_owned()).collect();
let mut 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() {
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 {

Loading…
Cancel
Save