|
|
|
@ -2,8 +2,8 @@ use crate::utils::*;
|
|
|
|
|
use serde_json::Map;
|
|
|
|
|
|
|
|
|
|
use crate::serenity;
|
|
|
|
|
use crate::Error;
|
|
|
|
|
use crate::Context;
|
|
|
|
|
use crate::Error;
|
|
|
|
|
use poise::command;
|
|
|
|
|
|
|
|
|
|
use slug::slugify;
|
|
|
|
@ -43,7 +43,10 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
|
|
|
|
Context::Prefix(ctx) => {
|
|
|
|
|
if ctx.msg.attachments.len() == 0 {
|
|
|
|
|
ctx.msg
|
|
|
|
|
.reply(&ctx.serenity_context.http, "Please attach at least one image.")
|
|
|
|
|
.reply(
|
|
|
|
|
&ctx.serenity_context.http,
|
|
|
|
|
"Please attach at least one image.",
|
|
|
|
|
)
|
|
|
|
|
.await?;
|
|
|
|
|
return Ok(());
|
|
|
|
|
}
|
|
|
|
@ -75,7 +78,10 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
|
|
|
|
|
|
|
|
|
let challenge_number = get_challenge_number();
|
|
|
|
|
let submission_images_dir = get_submission_images_dir();
|
|
|
|
|
let timestamp = std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).unwrap().as_millis();
|
|
|
|
|
let timestamp = std::time::SystemTime::now()
|
|
|
|
|
.duration_since(std::time::UNIX_EPOCH)
|
|
|
|
|
.unwrap()
|
|
|
|
|
.as_millis();
|
|
|
|
|
|
|
|
|
|
// Ensure that submission_images_dir exists
|
|
|
|
|
let path = Path::new(&submission_images_dir);
|
|
|
|
@ -95,7 +101,13 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
|
|
|
|
for submission in submission_data.iter_mut() {
|
|
|
|
|
if is_matching_submission(&submission, author) {
|
|
|
|
|
existing_submitter = true;
|
|
|
|
|
let mut 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 (i, attachment) in attachments.iter().enumerate() {
|
|
|
|
|
let extension;
|
|
|
|
|
if let Some(content_type) = &attachment.content_type {
|
|
|
|
@ -118,7 +130,11 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
|
|
|
|
slugify(&author.name),
|
|
|
|
|
author.discriminator,
|
|
|
|
|
timestamp,
|
|
|
|
|
if i == 0 { "".to_owned() } else { format!("-{}", i + 1) },
|
|
|
|
|
if i == 0 {
|
|
|
|
|
"".to_owned()
|
|
|
|
|
} else {
|
|
|
|
|
format!("-{}", i + 1)
|
|
|
|
|
},
|
|
|
|
|
extension
|
|
|
|
|
);
|
|
|
|
|
images.push(file_name.clone().into());
|
|
|
|
@ -162,7 +178,11 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
|
|
|
|
slugify(&author.name),
|
|
|
|
|
author.discriminator,
|
|
|
|
|
timestamp,
|
|
|
|
|
if i == 0 { "".to_owned() } else { format!("-{}", i + 1) },
|
|
|
|
|
if i == 0 {
|
|
|
|
|
"".to_owned()
|
|
|
|
|
} else {
|
|
|
|
|
format!("-{}", i + 1)
|
|
|
|
|
},
|
|
|
|
|
extension
|
|
|
|
|
);
|
|
|
|
|
images.push(file_name.clone().into());
|
|
|
|
@ -179,7 +199,11 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
|
|
|
|
set_submission_data(submission_data);
|
|
|
|
|
let mut message = String::new();
|
|
|
|
|
if requires_rebuild {
|
|
|
|
|
let thank_you = &format!("Thank you for submitting! You can view your submission at <https://{domain}/{}>", challenge_number, domain = get_domain());
|
|
|
|
|
let thank_you = &format!(
|
|
|
|
|
"Thank you for submitting! You can view your submission at <https://{domain}/{}>",
|
|
|
|
|
challenge_number,
|
|
|
|
|
domain = get_domain()
|
|
|
|
|
);
|
|
|
|
|
let mut repost_here = true;
|
|
|
|
|
match ctx {
|
|
|
|
|
Context::Application(_) => message.push_str(thank_you),
|
|
|
|
@ -203,7 +227,8 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
|
|
|
|
let invite = if data.contains_key("invite") {
|
|
|
|
|
Some(data["invite"].as_str().unwrap())
|
|
|
|
|
} else {
|
|
|
|
|
None };
|
|
|
|
|
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());
|
|
|
|
@ -228,34 +253,42 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
|
|
|
|
.await
|
|
|
|
|
.unwrap()
|
|
|
|
|
.accent_colour;
|
|
|
|
|
channel.send_message(&ctx.serenity_context().http, |m| {
|
|
|
|
|
m.embed(|e| {
|
|
|
|
|
let username = format!("{}#{}", author.name, author.discriminator);
|
|
|
|
|
let domain = get_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();
|
|
|
|
|
channel
|
|
|
|
|
.send_message(&ctx.serenity_context().http, |m| {
|
|
|
|
|
m.embed(|e| {
|
|
|
|
|
let username = format!("{}#{}", author.name, author.discriminator);
|
|
|
|
|
let domain = get_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 {
|
|
|
|
@ -400,7 +433,8 @@ pub async fn imagedelete(ctx: Context<'_>, number: i32) -> Result<(), Error> {
|
|
|
|
|
pub async fn suggest(
|
|
|
|
|
ctx: Context<'_>,
|
|
|
|
|
#[rest]
|
|
|
|
|
#[description = "Suggestion text. Please include passage and source."] suggestion: String,
|
|
|
|
|
#[description = "Suggestion text. Please include passage and source."]
|
|
|
|
|
suggestion: String,
|
|
|
|
|
) -> Result<(), Error> {
|
|
|
|
|
let guild_data = get_guild_data();
|
|
|
|
|
let channel = serenity::ChannelId(
|
|
|
|
@ -430,10 +464,7 @@ pub async fn suggest(
|
|
|
|
|
let username = format!("{}#{}", author.name, author.discriminator);
|
|
|
|
|
e.title("New suggestion");
|
|
|
|
|
e.description(if let Context::Prefix(ctx) = ctx {
|
|
|
|
|
format!(
|
|
|
|
|
"{suggestion}\n\n[See original message]({})",
|
|
|
|
|
ctx.msg.link(),
|
|
|
|
|
)
|
|
|
|
|
format!("{suggestion}\n\n[See original message]({})", ctx.msg.link(),)
|
|
|
|
|
} else {
|
|
|
|
|
suggestion
|
|
|
|
|
});
|
|
|
|
|