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