From 5fc7584100303babc17aa5376d3d1041d4c37bea Mon Sep 17 00:00:00 2001 From: jude Date: Thu, 23 Mar 2023 19:24:43 +0000 Subject: [PATCH] Load environment from file --- Cargo.lock | 1 + Cargo.toml | 3 ++- conf/default | 0 conf/default.env | 7 +++++++ src/main.rs | 6 +++++- 5 files changed, 15 insertions(+), 2 deletions(-) delete mode 100644 conf/default create mode 100644 conf/default.env diff --git a/Cargo.lock b/Cargo.lock index d163485..8aeefd5 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -2091,6 +2091,7 @@ name = "soundfx-rs" version = "1.5.7" dependencies = [ "dashmap", + "dotenv", "env_logger", "lazy_static", "log", diff --git a/Cargo.toml b/Cargo.toml index 09bbb66..bf17d44 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -19,6 +19,7 @@ log = "0.4" serde_json = "1.0" dashmap = "5.3" serde = "1.0" +dotenv = "0.15.0" [patch."https://github.com/serenity-rs/serenity"] serenity = { version = "0.11.5" } @@ -29,7 +30,7 @@ suggests = "mysql-server-8.0" maintainer-scripts = "debian" assets = [ ["target/release/soundfx-rs", "usr/bin/soundfx-rs", "755"], - ["conf/default", "etc/soundfx-rs/default", "600"] + ["conf/default.env", "etc/soundfx-rs/default.env", "600"] ] [package.metadata.deb.systemd-units] diff --git a/conf/default b/conf/default deleted file mode 100644 index e69de29..0000000 diff --git a/conf/default.env b/conf/default.env new file mode 100644 index 0000000..303ab1a --- /dev/null +++ b/conf/default.env @@ -0,0 +1,7 @@ +DISCORD_TOKEN= +DATABASE_URL=mysql://localhost/soundfx +UPLOAD_MAX_SIZE=2097152 +MAX_SOUNDS=8 +CACHING_LOCATION=/tmp +PATREON_GUILD= +PATREON_ROLE= diff --git a/src/main.rs b/src/main.rs index 8326ef8..b28ba39 100644 --- a/src/main.rs +++ b/src/main.rs @@ -8,7 +8,7 @@ mod event_handlers; mod models; mod utils; -use std::{env, sync::Arc}; +use std::{env, path::Path, sync::Arc}; use dashmap::DashMap; use poise::serenity_prelude::{ @@ -68,6 +68,10 @@ pub async fn register_application_commands( #[tokio::main] async fn main() -> Result<(), Box> { + if Path::new("/etc/soundfx-rs/default.env").exists() { + dotenv::from_path("/etc/soundfx-rs/default.env").unwrap(); + } + env_logger::init(); let discord_token = env::var("DISCORD_TOKEN").expect("Missing DISCORD_TOKEN from environment");