diff --git a/src/commands/kanji.rs b/src/commands/kanji.rs index c7e534a..8f65d15 100644 --- a/src/commands/kanji.rs +++ b/src/commands/kanji.rs @@ -2,8 +2,8 @@ use serenity::framework::standard::{macros::command, Args, CommandResult}; use serenity::model::prelude::*; use serenity::prelude::*; -use serde_json::Value; use serde_json::Map; +use serde_json::Value; use std::fs::File; use std::io::Read; @@ -61,10 +61,12 @@ fn get_kanji_info(kanji: char) -> String { if list.contains(kanji) { info.push_str(&format!("**{}**, ", category_name)); } - }, + } // if variants (map) None => { - let variants = &category["versions"][default_version]["characters"].as_object().unwrap(); + let variants = &category["versions"][default_version]["characters"] + .as_object() + .unwrap(); let mut in_variants = false; for variant in variants.keys() { let list = variants[variant].as_str().unwrap(); @@ -98,11 +100,16 @@ async fn i(ctx: &Context, msg: &Message, args: Args) -> CommandResult { let mut chars = input.chars(); if input.len() == 1 { let kanji_info = get_kanji_info(chars.next().unwrap()); - msg.reply(&ctx.http, if kanji_info.len() == 0 { - "Couldn't find that character in any kanji list!" - } else { - &kanji_info - }).await.unwrap(); + msg.reply( + &ctx.http, + if kanji_info.len() == 0 { + "Couldn't find that character in any kanji list!" + } else { + &kanji_info + }, + ) + .await + .unwrap(); return Ok(()); } let mut message = String::from(""); @@ -113,42 +120,52 @@ async fn i(ctx: &Context, msg: &Message, args: Args) -> CommandResult { if covered_chars.contains(&character) { continue; } - let kanji_info = get_kanji_info(character); + let kanji_info = get_kanji_info(character); covered_chars.push(character); if kanji_info.len() == 0 { skipped_chars += 1; continue; } found_chars += 1; - message.push_str(&format!("[{}](https://jisho.org/search/{}%23kanji): {}\n", character, character, kanji_info)); + message.push_str(&format!( + "[{}](https://jisho.org/search/{}%23kanji): {}\n", + character, character, kanji_info + )); } message = format!("Found {} kanji:\n{}", found_chars, message); if skipped_chars > 0 { - message.push_str(&format!("Skipped {} character{} that I couldn't find in any kanji list!", skipped_chars, if skipped_chars == 1 { "" } else { "s" })); + message.push_str(&format!( + "Skipped {} character{} that I couldn't find in any kanji list!", + skipped_chars, + if skipped_chars == 1 { "" } else { "s" } + )); } - msg.channel_id.send_message(&ctx.http, |m| { - m.reference_message(msg); - m.allowed_mentions(|am| { - am.empty_parse(); - am - }); - m.embed(|e| { - e.title(input); - e.description(message); - let mut author = serenity::builder::CreateEmbedAuthor::default(); - author - .icon_url("https://raw.githubusercontent.com/ElnuDev/ji-chan/main/ji-chan.png") - .name("字ちゃん") - .url("https://github.com/ElnuDev/ji-chan"); - e.set_author(author); - e.color(serenity::utils::Colour::from_rgb(251, 73, 52)); - if input.chars().count() == 1 { - e.thumbnail(get_so_diagram(input.chars().next().unwrap())); - } - e - }); - m - }).await.unwrap(); + msg.channel_id + .send_message(&ctx.http, |m| { + m.reference_message(msg); + m.allowed_mentions(|am| { + am.empty_parse(); + am + }); + m.embed(|e| { + e.title(input); + e.description(message); + let mut author = serenity::builder::CreateEmbedAuthor::default(); + author + .icon_url("https://raw.githubusercontent.com/ElnuDev/ji-chan/main/ji-chan.png") + .name("字ちゃん") + .url("https://github.com/ElnuDev/ji-chan"); + e.set_author(author); + e.color(serenity::utils::Colour::from_rgb(251, 73, 52)); + if input.chars().count() == 1 { + e.thumbnail(get_so_diagram(input.chars().next().unwrap())); + } + e + }); + m + }) + .await + .unwrap(); Ok(()) }