|
|
|
@ -41,7 +41,7 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
|
|
|
|
match ctx {
|
|
|
|
|
Context::Application(_) => ctx.defer_ephemeral().await?,
|
|
|
|
|
Context::Prefix(ctx) => {
|
|
|
|
|
if ctx.msg.attachments.len() == 0 {
|
|
|
|
|
if ctx.msg.attachments.is_empty() {
|
|
|
|
|
ctx.msg
|
|
|
|
|
.reply(
|
|
|
|
|
&ctx.serenity_context.http,
|
|
|
|
@ -99,7 +99,7 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
|
|
|
|
let author = ctx.author();
|
|
|
|
|
let mut submitted_images = Vec::new();
|
|
|
|
|
for submission in submission_data.iter_mut() {
|
|
|
|
|
if is_matching_submission(&submission, author) {
|
|
|
|
|
if is_matching_submission(submission, author) {
|
|
|
|
|
existing_submitter = true;
|
|
|
|
|
let mut images: Vec<String> = submission["images"]
|
|
|
|
|
.as_array_mut()
|
|
|
|
@ -137,7 +137,7 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
|
|
|
|
},
|
|
|
|
|
extension
|
|
|
|
|
);
|
|
|
|
|
images.push(file_name.clone().into());
|
|
|
|
|
images.push(file_name.clone());
|
|
|
|
|
let image = reqwest::get(&attachment.url).await?.bytes().await?;
|
|
|
|
|
let mut image_file =
|
|
|
|
|
File::create(format!("{}/{}", submission_images_dir, file_name))?;
|
|
|
|
@ -185,7 +185,7 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
|
|
|
|
},
|
|
|
|
|
extension
|
|
|
|
|
);
|
|
|
|
|
images.push(file_name.clone().into());
|
|
|
|
|
images.push(file_name.clone());
|
|
|
|
|
let image = reqwest::get(&attachment.url).await?.bytes().await?;
|
|
|
|
|
let mut image_file = File::create(format!("{}/{}", submission_images_dir, file_name))?;
|
|
|
|
|
image_file.write_all(&image)?;
|
|
|
|
@ -275,7 +275,7 @@ pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Resul
|
|
|
|
|
e.description(description);
|
|
|
|
|
let mut embed_author = serenity::builder::CreateEmbedAuthor::default();
|
|
|
|
|
embed_author
|
|
|
|
|
.icon_url(get_avatar(&author))
|
|
|
|
|
.icon_url(get_avatar(author))
|
|
|
|
|
.name(username)
|
|
|
|
|
.url(format!("https://discord.com/users/{}", author.id));
|
|
|
|
|
e.set_author(embed_author);
|
|
|
|
@ -311,7 +311,7 @@ pub async fn images(ctx: Context<'_>) -> Result<(), Error> {
|
|
|
|
|
let images: Vec<String> = {
|
|
|
|
|
let mut images = Vec::new();
|
|
|
|
|
for submission in submission_data.iter() {
|
|
|
|
|
if is_matching_submission(&submission, &ctx.author()) {
|
|
|
|
|
if is_matching_submission(submission, ctx.author()) {
|
|
|
|
|
for image in submission["images"].as_array().unwrap().iter() {
|
|
|
|
|
images.push(String::from(image.as_str().unwrap()));
|
|
|
|
|
}
|
|
|
|
@ -321,7 +321,7 @@ pub async fn images(ctx: Context<'_>) -> Result<(), Error> {
|
|
|
|
|
images
|
|
|
|
|
};
|
|
|
|
|
let challenge_number = get_challenge_number();
|
|
|
|
|
if images.len() == 0 {
|
|
|
|
|
if images.is_empty() {
|
|
|
|
|
ctx.say(format!(
|
|
|
|
|
"You haven't submitted anything for Tegaki Tuesday #{}.",
|
|
|
|
|
challenge_number
|
|
|
|
@ -329,10 +329,10 @@ pub async fn images(ctx: Context<'_>) -> Result<(), Error> {
|
|
|
|
|
.await?;
|
|
|
|
|
return Ok(());
|
|
|
|
|
}
|
|
|
|
|
let mut message = String::from(format!(
|
|
|
|
|
let mut message = format!(
|
|
|
|
|
"Your submission images for Tegaki Tuesday #{}:\n",
|
|
|
|
|
challenge_number
|
|
|
|
|
));
|
|
|
|
|
);
|
|
|
|
|
for (i, image) in images.iter().enumerate() {
|
|
|
|
|
message.push_str(&format!(
|
|
|
|
|
"({})<https://{domain}/{}/{}>\n",
|
|
|
|
@ -368,7 +368,7 @@ pub async fn imagedelete(ctx: Context<'_>, number: i32) -> Result<(), Error> {
|
|
|
|
|
let challenge_number = get_challenge_number();
|
|
|
|
|
let mut submission_data = get_current_submission_data();
|
|
|
|
|
for (i, submission) in submission_data.iter_mut().enumerate() {
|
|
|
|
|
if !is_matching_submission(&submission, &ctx.author()) {
|
|
|
|
|
if !is_matching_submission(submission, ctx.author()) {
|
|
|
|
|
continue;
|
|
|
|
|
}
|
|
|
|
|
let mut images = submission["images"].as_array().unwrap().clone();
|
|
|
|
@ -402,7 +402,7 @@ pub async fn imagedelete(ctx: Context<'_>, number: i32) -> Result<(), Error> {
|
|
|
|
|
Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => (),
|
|
|
|
|
Err(_) => panic!("Failed to remove file"),
|
|
|
|
|
};
|
|
|
|
|
let mut message = String::from(format!("Deleted **{}** from your submission.", image));
|
|
|
|
|
let mut message = format!("Deleted **{}** from your submission.", image);
|
|
|
|
|
if images.len() == 1 {
|
|
|
|
|
message.push_str(" As there are no more images left attached to your submission, it has been deleted.");
|
|
|
|
|
submission_data.remove(i);
|
|
|
|
@ -470,7 +470,7 @@ pub async fn suggest(
|
|
|
|
|
});
|
|
|
|
|
let mut embed_author = serenity::builder::CreateEmbedAuthor::default();
|
|
|
|
|
embed_author
|
|
|
|
|
.icon_url(get_avatar(&author))
|
|
|
|
|
.icon_url(get_avatar(author))
|
|
|
|
|
.name(username)
|
|
|
|
|
.url(format!("https://discord.com/users/{}", author.id));
|
|
|
|
|
e.set_author(embed_author);
|
|
|
|
|