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(())
}
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"];

Loading…
Cancel
Save