Extracted environment loading into a method
This commit is contained in:
32
src/main.rs
32
src/main.rs
@@ -35,13 +35,8 @@ struct AppState {
|
||||
|
||||
#[tokio::main]
|
||||
async fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
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<dyn std::error::Error>> {
|
||||
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>, UserId) {
|
||||
match http.get_current_application_info().await {
|
||||
Ok(info) => {
|
||||
|
||||
Reference in New Issue
Block a user