Add _test_submission.png silent test submissions

This commit is contained in:
Elnu 2025-03-26 20:27:36 -07:00
parent 2e45f0205a
commit b3cb507b16

View file

@ -99,6 +99,7 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
};
let author = ctx.author();
let mut submitted_images = Vec::new();
let mut is_test = false;
for submission in submission_data.iter_mut() {
if is_matching_submission(submission, author) {
existing_submitter = true;
@ -110,6 +111,9 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
.map(|value| value.as_str().unwrap().to_owned())
.collect();
for (i, attachment) in attachments.iter().enumerate() {
if attachment.filename.starts_with("_test_submission.") {
is_test = true;
}
let extension;
if let Some(content_type) = &attachment.content_type {
if content_type == "image/png" {
@ -156,6 +160,9 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
submitter_data.insert(String::from("username"), username.clone().into());
let mut images: Vec<String> = Vec::new();
for (i, attachment) in attachments.iter().enumerate() {
if attachment.filename.starts_with("_test_submission.") {
is_test = true;
}
let extension;
if let Some(content_type) = &attachment.content_type {
if content_type == "image/png" {
@ -227,74 +234,76 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
} else {
None
};
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 !here && other_guild_id.eq("116379774825267202") {
// Don't crosspost to 日英
continue;
}
if !repost_here && here {
continue;
}
let data = match data.as_object() {
Some(data) => data,
// "suggestionChannel": "..." is at root level,
// and is not an object. Ignore it.
None => continue,
};
if !data.contains_key("submissionChannel") {
continue;
}
let channel = serenity::ChannelId(
data["submissionChannel"]
.as_str()
if !is_test {
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 !here && other_guild_id.eq("116379774825267202") {
// Don't crosspost to 日英
continue;
}
if !repost_here && here {
continue;
}
let data = match data.as_object() {
Some(data) => data,
// "suggestionChannel": "..." is at root level,
// and is not an object. Ignore it.
None => continue,
};
if !data.contains_key("submissionChannel") {
continue;
}
let channel = serenity::ChannelId(
data["submissionChannel"]
.as_str()
.unwrap()
.parse::<u64>()
.unwrap(),
);
let accent_color = ctx
.serenity_context()
.http
.get_user(*author.id.as_u64())
.await
.unwrap()
.parse::<u64>()
.unwrap(),
);
let accent_color = ctx
.serenity_context()
.http
.get_user(*author.id.as_u64())
.await
.unwrap()
.accent_colour;
channel
.send_message(&ctx.serenity_context().http, |m| {
m.embed(|e| {
let domain = &ARGS.domain;
let n = get_challenge_number();
let mut description = format!(
"New submission to [Tegaki Tuesday #{n}](https://{domain}/{n})!"
);
if !here {
description.push_str(&if let Some(invite) = invite {
format!(
"\nCrossposted from [{}](https://discord.gg/{invite})",
guild.name
)
} else {
format!("\nCrossposted from {}", guild.name)
});
};
e.description(description);
let mut embed_author = serenity::builder::CreateEmbedAuthor::default();
embed_author
.icon_url(get_avatar(author))
.name(username)
.url(format!("https://discord.com/users/{}", author.id));
e.set_author(embed_author);
e.image(format!("https://{domain}/{n}/{image}"));
if let Some(accent_color) = accent_color {
e.color(accent_color);
}
e
});
m
})
.await
.unwrap();
.accent_colour;
channel
.send_message(&ctx.serenity_context().http, |m| {
m.embed(|e| {
let domain = &ARGS.domain;
let n = get_challenge_number();
let mut description = format!(
"New submission to [Tegaki Tuesday #{n}](https://{domain}/{n})!"
);
if !here {
description.push_str(&if let Some(invite) = invite {
format!(
"\nCrossposted from [{}](https://discord.gg/{invite})",
guild.name
)
} else {
format!("\nCrossposted from {}", guild.name)
});
};
e.description(description);
let mut embed_author = serenity::builder::CreateEmbedAuthor::default();
embed_author
.icon_url(get_avatar(author))
.name(username)
.url(format!("https://discord.com/users/{}", author.id));
e.set_author(embed_author);
e.image(format!("https://{domain}/{n}/{image}"));
if let Some(accent_color) = accent_color {
e.color(accent_color);
}
e
});
m
})
.await
.unwrap();
}
}
}
} else if invalid_types {