Move guild data path into environment variable

late-submissions
Elnu 3 years ago
parent 4f1d9f62e2
commit 72333cc116

@ -1,3 +1,4 @@
DISCORD_TOKEN= DISCORD_TOKEN=
PREFIX="-h " PREFIX="-h "
HUGO=/path/to/hugo HUGO=/path/to/hugo
GUILD_DATA=/path/to/guilds.json

@ -14,17 +14,16 @@ use std::env;
use crate::ShardManagerContainer; use crate::ShardManagerContainer;
use crate::commands::challenge::get_challenge_number; use crate::commands::challenge::get_challenge_number;
const GUILD_DATA_PATH: &str = "guilds.json";
pub fn get_guild_data() -> Map<String, Value> { pub fn get_guild_data() -> Map<String, Value> {
let guild_data_json = match File::open(GUILD_DATA_PATH) { let guild_data_path = env::var("GUILD_DATA").unwrap();
let guild_data_json = match File::open(guild_data_path) {
Ok(mut file) => { Ok(mut file) => {
let mut json = String::new(); let mut json = String::new();
file.read_to_string(&mut json).unwrap(); file.read_to_string(&mut json).unwrap();
json json
} }
Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => { Err(ref e) if e.kind() == std::io::ErrorKind::NotFound => {
let mut file = File::create(GUILD_DATA_PATH).unwrap(); let mut file = File::create(guild_data_path).unwrap();
file.write_all(b"{}").unwrap(); file.write_all(b"{}").unwrap();
file.flush().unwrap(); file.flush().unwrap();
String::from("{}") String::from("{}")

Loading…
Cancel
Save