late-submissions
Elnu 3 years ago
parent 10bc1ad69a
commit d39506ec95

@ -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(
&ctx.http,
if kanji_info.len() == 0 {
"Couldn't find that character in any kanji list!" "Couldn't find that character in any kanji list!"
} else { } else {
&kanji_info &kanji_info
}).await.unwrap(); },
)
.await
.unwrap();
return Ok(()); return Ok(());
} }
let mut message = String::from(""); let mut message = String::from("");
@ -120,13 +127,21 @@ async fn i(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
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
.send_message(&ctx.http, |m| {
m.reference_message(msg); m.reference_message(msg);
m.allowed_mentions(|am| { m.allowed_mentions(|am| {
am.empty_parse(); am.empty_parse();
@ -148,7 +163,9 @@ async fn i(ctx: &Context, msg: &Message, args: Args) -> CommandResult {
e e
}); });
m m
}).await.unwrap(); })
.await
.unwrap();
Ok(()) Ok(())
} }

Loading…
Cancel
Save