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