Move opening kanji lists into get_lists_data function

late-submissions
Elnu 3 years ago
parent 96a813074b
commit 8d36217221

@ -36,16 +36,21 @@ async fn display_kanji(ctx: &Context, msg: &Message, kanji: char, comment: &str)
Ok(()) Ok(())
} }
fn get_lists_data() -> Value {
let mut lists_file = File::open("kanji_lists.json").unwrap();
let mut lists_json = String::new();
lists_file.read_to_string(&mut lists_json).unwrap();
let lists_data: Value = serde_json::from_str(&lists_json).unwrap();
lists_data
}
async fn random_kanji( async fn random_kanji(
category: &str, category: &str,
ctx: &Context, ctx: &Context,
msg: &Message, msg: &Message,
mut args: Args, mut args: Args,
) -> CommandResult { ) -> CommandResult {
let mut lists_file = File::open("kanji_lists.json").unwrap(); let lists_data = get_lists_data();
let mut lists_json = String::new();
lists_file.read_to_string(&mut lists_json).unwrap();
let lists_data: Value = serde_json::from_str(&lists_json).unwrap();
let category = &lists_data[category]; let category = &lists_data[category];
let default_version = category["default"].as_str().unwrap(); let default_version = category["default"].as_str().unwrap();
let list = &category["versions"][default_version]["characters"]; let list = &category["versions"][default_version]["characters"];

Loading…
Cancel
Save