cargo clippy --fix

main
Elnu 2 years ago
parent 5702c60fc0
commit 4acff7051d

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

@ -21,7 +21,7 @@ pub async fn i(
} }
let kanji_info = get_kanji_info(character); let kanji_info = get_kanji_info(character);
covered_chars.push(character); covered_chars.push(character);
if kanji_info.len() == 0 { if kanji_info.is_empty() {
skipped_chars += 1; skipped_chars += 1;
continue; continue;
} }
@ -34,7 +34,7 @@ pub async fn i(
message = format!( message = format!(
"Found {} kanji{}\n{}", "Found {} kanji{}\n{}",
found_chars.len(), found_chars.len(),
if found_chars.len() == 0 { "." } else { ":" }, if found_chars.is_empty() { "." } else { ":" },
message message
); );
if skipped_chars > 0 { if skipped_chars > 0 {

@ -332,11 +332,11 @@ pub async fn random_kanji(
.choose(&mut rand::thread_rng()) .choose(&mut rand::thread_rng())
.unwrap(); .unwrap();
let list = subcategories[subcategory_key].as_str().unwrap(); let list = subcategories[subcategory_key].as_str().unwrap();
let kanji = random_from_string(&list); let kanji = random_from_string(list);
display_kanji(ctx, kanji, &format!(", **{}**", subcategory_key)).await?; display_kanji(ctx, kanji, &format!(", **{}**", subcategory_key)).await?;
} else if subcategories.contains_key(&subcategory) { } else if subcategories.contains_key(&subcategory) {
let list = list[&subcategory].as_str().unwrap(); let list = list[&subcategory].as_str().unwrap();
let kanji = random_from_string(&list); let kanji = random_from_string(list);
display_kanji(ctx, kanji, "").await?; display_kanji(ctx, kanji, "").await?;
} else { } else {
let message = format!( let message = format!(

Loading…
Cancel
Save