Load environment from file

This commit is contained in:
jude 2023-03-23 19:24:43 +00:00
parent f7b0150688
commit 5fc7584100
5 changed files with 15 additions and 2 deletions

1
Cargo.lock generated
View File

@ -2091,6 +2091,7 @@ name = "soundfx-rs"
version = "1.5.7" version = "1.5.7"
dependencies = [ dependencies = [
"dashmap", "dashmap",
"dotenv",
"env_logger", "env_logger",
"lazy_static", "lazy_static",
"log", "log",

View File

@ -19,6 +19,7 @@ log = "0.4"
serde_json = "1.0" serde_json = "1.0"
dashmap = "5.3" dashmap = "5.3"
serde = "1.0" serde = "1.0"
dotenv = "0.15.0"
[patch."https://github.com/serenity-rs/serenity"] [patch."https://github.com/serenity-rs/serenity"]
serenity = { version = "0.11.5" } serenity = { version = "0.11.5" }
@ -29,7 +30,7 @@ suggests = "mysql-server-8.0"
maintainer-scripts = "debian" maintainer-scripts = "debian"
assets = [ assets = [
["target/release/soundfx-rs", "usr/bin/soundfx-rs", "755"], ["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] [package.metadata.deb.systemd-units]

View File

7
conf/default.env Normal file
View File

@ -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=

View File

@ -8,7 +8,7 @@ mod event_handlers;
mod models; mod models;
mod utils; mod utils;
use std::{env, sync::Arc}; use std::{env, path::Path, sync::Arc};
use dashmap::DashMap; use dashmap::DashMap;
use poise::serenity_prelude::{ use poise::serenity_prelude::{
@ -68,6 +68,10 @@ pub async fn register_application_commands(
#[tokio::main] #[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> { async fn main() -> Result<(), Box<dyn std::error::Error + Send + Sync>> {
if Path::new("/etc/soundfx-rs/default.env").exists() {
dotenv::from_path("/etc/soundfx-rs/default.env").unwrap();
}
env_logger::init(); env_logger::init();
let discord_token = env::var("DISCORD_TOKEN").expect("Missing DISCORD_TOKEN from environment"); let discord_token = env::var("DISCORD_TOKEN").expect("Missing DISCORD_TOKEN from environment");