From 8d36217221820be90f8fe92d590a18787b5868f8 Mon Sep 17 00:00:00 2001 From: ElnuDev Date: Sun, 20 Feb 2022 15:18:47 -0800 Subject: [PATCH] Move opening kanji lists into get_lists_data function --- src/commands/kanji.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) 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"];