From e112be0d872eb1e313143812a8476a78f71b4dc0 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Sun, 20 Feb 2022 17:57:28 -0800 Subject: [PATCH] Polish -h i command & add to -h help --- src/commands/kanji.rs | 29 +++++++---------------------- src/commands/meta.rs | 1 + 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/src/commands/kanji.rs b/src/commands/kanji.rs index 8f65d15..672fea8 100644 --- a/src/commands/kanji.rs +++ b/src/commands/kanji.rs @@ -96,26 +96,11 @@ fn get_kanji_info(kanji: char) -> String { #[command] async fn i(ctx: &Context, msg: &Message, args: Args) -> CommandResult { let input = args.rest(); - // chars must be mutable because it is an iterator - 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(); - return Ok(()); - } + let chars = input.chars(); let mut message = String::from(""); let mut covered_chars: Vec = Vec::new(); let mut skipped_chars = 0; - let mut found_chars = 0; + let mut found_chars: Vec = Vec::new(); for character in chars { if covered_chars.contains(&character) { continue; @@ -126,16 +111,16 @@ async fn i(ctx: &Context, msg: &Message, args: Args) -> CommandResult { skipped_chars += 1; continue; } - found_chars += 1; + found_chars.push(character); message.push_str(&format!( "[{}](https://jisho.org/search/{}%23kanji): {}\n", character, character, kanji_info )); } - message = format!("Found {} kanji:\n{}", found_chars, message); + message = format!("Found {} kanji{}\n{}", found_chars.len(), if found_chars.len() == 0 { "." } else { ":" }, message); if skipped_chars > 0 { message.push_str(&format!( - "Skipped {} character{} that I couldn't find in any kanji list!", + "Skipped {} character{}.", skipped_chars, if skipped_chars == 1 { "" } else { "s" } )); @@ -157,8 +142,8 @@ async fn i(ctx: &Context, msg: &Message, args: Args) -> CommandResult { .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())); + if found_chars.len() == 1 { + e.thumbnail(get_so_diagram(found_chars[0])); } e }); diff --git a/src/commands/meta.rs b/src/commands/meta.rs index adaab3a..a32fc8f 100644 --- a/src/commands/meta.rs +++ b/src/commands/meta.rs @@ -19,6 +19,7 @@ __**Tegaki Tuesday 手書きの火曜日**__ :wastebasket: `{p}imageDelete ` Delete images from your current submission using image numbers from -h images. __**Kanji 漢字**__ +:information_source: `{p}i ` Get category information and links to Jisho for character(s), along with with stroke a order diagram for single characters. :paintbrush: `{p}so ` Get stroke order diagrams for character(s), maximum 4 :game_die: `{p}jinmeiyo` Random Jinmeiyō kanji :game_die: `{p}joyo` Random Jōyō kanji