diff --git a/src/commands/kanji.rs b/src/commands/kanji.rs index c89f97a..240306c 100644 --- a/src/commands/kanji.rs +++ b/src/commands/kanji.rs @@ -36,16 +36,21 @@ async fn display_kanji(ctx: &Context, msg: &Message, kanji: char, comment: &str) 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( category: &str, ctx: &Context, msg: &Message, mut args: Args, ) -> CommandResult { - 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(); + let lists_data = get_lists_data(); let category = &lists_data[category]; let default_version = category["default"].as_str().unwrap(); let list = &category["versions"][default_version]["characters"];