From 8dde342d978169e2cef3fff6ca0786c101a475f7 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Wed, 16 Nov 2022 22:47:33 -0800 Subject: [PATCH] cargo fmt --- src/commands/challenge.rs | 55 ++++++++++++++++++--------------------- src/utils.rs | 2 +- 2 files changed, 27 insertions(+), 30 deletions(-) diff --git a/src/commands/challenge.rs b/src/commands/challenge.rs index 9a53ac2..d866629 100644 --- a/src/commands/challenge.rs +++ b/src/commands/challenge.rs @@ -34,20 +34,19 @@ pub async fn challenge(ctx: Context<'_>) -> Result<(), Error> { broadcast_typing, description_localized("en-US", "Submit to the latest handwriting challenge.") )] -pub async fn submit( - ctx: Context<'_>, - submission: serenity::Attachment -) -> Result<(), Error> { +pub async fn submit(ctx: Context<'_>, submission: serenity::Attachment) -> Result<(), Error> { // TODO: The code for this command needs to be refactored, // there are large duplicated sections that need to be merged somehow. match ctx { - Context::Application(_) => { ctx.defer_ephemeral().await? }, - Context::Prefix(ctx) => if ctx.msg.attachments.len() == 0 { - ctx.msg - .reply(&ctx.discord.http, "Please attach at least one image.") - .await?; - return Ok(()); - }, + Context::Application(_) => ctx.defer_ephemeral().await?, + Context::Prefix(ctx) => { + if ctx.msg.attachments.len() == 0 { + ctx.msg + .reply(&ctx.discord.http, "Please attach at least one image.") + .await?; + return Ok(()); + } + } } let guild_data = get_guild_data(); let guild = ctx.guild_id().unwrap().as_u64().to_string(); @@ -57,23 +56,22 @@ pub async fn submit( .unwrap() .contains_key("submissionChannel") { - ctx.say("Submissions aren't enabled for this server yet.").await?; + ctx.say("Submissions aren't enabled for this server yet.") + .await?; return Ok(()); } let current_guild_data = &guild_data[&guild].as_object().unwrap(); let submission_channel = current_guild_data["submissionChannel"].as_str().unwrap(); if submission_channel != ctx.channel_id().as_u64().to_string() { ctx.defer_ephemeral().await?; - ctx.say( - format!( - "Sorry, submissions aren't permitted here. Please go to <#{}>. Thanks!", - guild - ), - ) - .await?; + ctx.say(format!( + "Sorry, submissions aren't permitted here. Please go to <#{}>. Thanks!", + guild + )) + .await?; return Ok(()); } - + let challenge_number = get_challenge_number(); let submission_images_dir = get_submission_images_dir(); @@ -172,10 +170,7 @@ pub async fn submit( image_file.flush()?; } submitter_data.insert(String::from("images"), images.into()); - submitter_data.insert( - String::from("id"), - author.id.as_u64().to_string().into(), - ); + submitter_data.insert(String::from("id"), author.id.as_u64().to_string().into()); submission_data.push(submitter_data.into()); } set_submission_data(submission_data); @@ -186,7 +181,7 @@ pub async fn submit( match ctx { Context::Application(_) => message.push_str(thank_you), Context::Prefix(ctx) => match ctx.msg.delete(&ctx.discord.http).await { - Ok(_) => {}, + Ok(_) => {} // don't repost image on this server if no manage messages perm // (if we can't delete user's image it'll be displayed twice) Err(_) => { @@ -204,7 +199,9 @@ pub async fn submit( let data = guild_data[&guild.id.to_string()].as_object().unwrap(); let invite = if data.contains_key("invite") { Some(data["invite"].as_str().unwrap()) - } else { None }; + } else { + None + }; for attachment in attachments.iter() { for (other_guild_id, data) in guild_data.iter() { let here = other_guild_id.eq(&ctx.guild_id().unwrap().as_u64().to_string()); @@ -247,7 +244,7 @@ pub async fn submit( .icon_url(get_avatar(&author)) .name(username) .url(format!("https://discord.com/users/{}", author.id)); - e.set_author(embed_author); + e.set_author(embed_author); e.image(&attachment.url); if let Some(accent_color) = accent_color { e.color(accent_color); @@ -256,8 +253,8 @@ pub async fn submit( }); m }).await?; - }; - }; + } + } } else if invalid_types { message.push_str("Sorry, your submission could not be uploaded; only **.png**, **.jpg**, and **.jpeg** files are permitted."); } diff --git a/src/utils.rs b/src/utils.rs index 9c60856..f01916c 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,6 +1,6 @@ use crate::serenity; -use crate::Error; use crate::Context; +use crate::Error; use rand::seq::IteratorRandom; use serde_json::Map; use serde_json::Value;