Polish -h i command & add to -h help
This commit is contained in:
parent
d39506ec95
commit
e112be0d87
2 changed files with 8 additions and 22 deletions
|
@ -96,26 +96,11 @@ fn get_kanji_info(kanji: char) -> String {
|
||||||
#[command]
|
#[command]
|
||||||
async fn i(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
async fn i(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||||
let input = args.rest();
|
let input = args.rest();
|
||||||
// chars must be mutable because it is an iterator
|
let chars = input.chars();
|
||||||
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 mut message = String::from("");
|
let mut message = String::from("");
|
||||||
let mut covered_chars: Vec<char> = Vec::new();
|
let mut covered_chars: Vec<char> = Vec::new();
|
||||||
let mut skipped_chars = 0;
|
let mut skipped_chars = 0;
|
||||||
let mut found_chars = 0;
|
let mut found_chars: Vec<char> = Vec::new();
|
||||||
for character in chars {
|
for character in chars {
|
||||||
if covered_chars.contains(&character) {
|
if covered_chars.contains(&character) {
|
||||||
continue;
|
continue;
|
||||||
|
@ -126,16 +111,16 @@ async fn i(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
|
||||||
skipped_chars += 1;
|
skipped_chars += 1;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
found_chars += 1;
|
found_chars.push(character);
|
||||||
message.push_str(&format!(
|
message.push_str(&format!(
|
||||||
"[{}](https://jisho.org/search/{}%23kanji): {}\n",
|
"[{}](https://jisho.org/search/{}%23kanji): {}\n",
|
||||||
character, character, kanji_info
|
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 {
|
if skipped_chars > 0 {
|
||||||
message.push_str(&format!(
|
message.push_str(&format!(
|
||||||
"Skipped {} character{} that I couldn't find in any kanji list!",
|
"Skipped {} character{}.",
|
||||||
skipped_chars,
|
skipped_chars,
|
||||||
if skipped_chars == 1 { "" } else { "s" }
|
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");
|
.url("https://github.com/ElnuDev/ji-chan");
|
||||||
e.set_author(author);
|
e.set_author(author);
|
||||||
e.color(serenity::utils::Colour::from_rgb(251, 73, 52));
|
e.color(serenity::utils::Colour::from_rgb(251, 73, 52));
|
||||||
if input.chars().count() == 1 {
|
if found_chars.len() == 1 {
|
||||||
e.thumbnail(get_so_diagram(input.chars().next().unwrap()));
|
e.thumbnail(get_so_diagram(found_chars[0]));
|
||||||
}
|
}
|
||||||
e
|
e
|
||||||
});
|
});
|
||||||
|
|
|
@ -19,6 +19,7 @@ __**Tegaki Tuesday 手書きの火曜日**__
|
||||||
:wastebasket: `{p}imageDelete <image number>` Delete images from your current submission using image numbers from -h images.
|
:wastebasket: `{p}imageDelete <image number>` Delete images from your current submission using image numbers from -h images.
|
||||||
|
|
||||||
__**Kanji 漢字**__
|
__**Kanji 漢字**__
|
||||||
|
:information_source: `{p}i <text>` Get category information and links to Jisho for character(s), along with with stroke a order diagram for single characters.
|
||||||
:paintbrush: `{p}so <text>` Get stroke order diagrams for character(s), maximum 4
|
:paintbrush: `{p}so <text>` Get stroke order diagrams for character(s), maximum 4
|
||||||
:game_die: `{p}jinmeiyo` Random Jinmeiyō kanji
|
:game_die: `{p}jinmeiyo` Random Jinmeiyō kanji
|
||||||
:game_die: `{p}joyo` Random Jōyō kanji
|
:game_die: `{p}joyo` Random Jōyō kanji
|
||||||
|
|
Loading…
Add table
Reference in a new issue