diff --git a/Makefile b/Makefile index eee52aa..3691909 100644 --- a/Makefile +++ b/Makefile @@ -55,5 +55,5 @@ docker-refresh: docker-clean backend-up ## Refresh the docker containers psql: ## Connect to the database @$(ENV) docker exec -it siren-postgres psql -U ${DATABASE_USER} -P pager=off -insert-api: +insert-api: ## Insert test API key into the database @$(ENV) ./scripts/insert_api_key.sh \ No newline at end of file diff --git a/bruno/environments/Localhost.bru b/bruno/environments/Localhost.bru index 27db5cb..3be8e02 100644 --- a/bruno/environments/Localhost.bru +++ b/bruno/environments/Localhost.bru @@ -1,7 +1,7 @@ vars { baseUrl: http://localhost:3000/api - server: 1061092965579235398 } vars:secret [ + server, apiKey ] diff --git a/src/main.rs b/src/main.rs index 0cee757..d31ac40 100644 --- a/src/main.rs +++ b/src/main.rs @@ -35,13 +35,8 @@ struct AppState { #[tokio::main] async fn main() -> Result<(), Box> { - if let Err(err) = from_filename(".env.local") { - eprintln!("Failed to load .env.local: {}", err); - } - dotenv().ok(); - - env_logger::init_from_env(env_logger::Env::default().filter_or("RUST_LOG", "warn,siren=info")); - + // Run initialization + initialize_environment()?; data::initialize().await?; let token: String = env::var("DISCORD_TOKEN").expect("Expected a token in the environment"); @@ -100,6 +95,29 @@ async fn main() -> Result<(), Box> { Ok(()) } +fn initialize_environment() -> std::io::Result<()> { + // Iterate over files in the current directory + for entry in std::fs::read_dir(".")? { + let entry = entry?; + let path = entry.path(); + + // Check if the file name starts with ".env" and is a file + if let Some(file_name) = path.file_name().and_then(|n| n.to_str()) { + if file_name.starts_with(".env") && path.is_file() { + // Try to load the file + if let Err(err) = from_filename(&file_name) { + eprintln!("Failed to load {}: {}", file_name, err); + } else { + println!("Loaded: {}", file_name); + } + } + } + } + + env_logger::init_from_env(env_logger::Env::default().filter_or("RUST_LOG", "warn,siren=info")); + Ok(()) +} + async fn get_bot_info(http: &Http) -> (Option, UserId) { match http.get_current_application_info().await { Ok(info) => {