Skip to content

Commit

Permalink
fix: env config
Browse files Browse the repository at this point in the history
  • Loading branch information
oleggtro committed Aug 12, 2022
1 parent 46b2e89 commit 87dc75e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
10 changes: 6 additions & 4 deletions config.sample.toml
@@ -1,4 +1,6 @@
DISCORD_TOKEN="the discord bot token"
SPOTIFY_USERNAME="your spotify email"
SPOTIFY_PASSWORD="your spotify password"
DISCORD_USER_ID="your discord id here"
# you will have to insert your own values here

DISCORD_TOKEN="Mjk3ODQzNDgzNzgzODU2MjMw.SxDNko.UOdRWlDuz_lFrTOeQWEuzKGBmDFdVTGns3jd4o"
SPOTIFY_USERNAME="mail@example.com"
SPOTIFY_PASSWORD="MySpotifyPassword"
DISCORD_USER_ID=301780655019130880
7 changes: 5 additions & 2 deletions src/lib/config.rs
Expand Up @@ -5,19 +5,22 @@ use figment::{
use serde::{Deserialize};

#[derive(Deserialize, Clone)]
#[serde(rename_all = "SCREAMING_SNAKE_CASE")]
pub struct Config {
#[serde(alias = "DISCORD_TOKEN")]
pub discord_token: String,
#[serde(alias = "SPOTIFY_USERNAME")]
pub spotify_username: String,
#[serde(alias = "SPOTIFY_PASSWORD")]
pub spotify_password: String,
#[serde(alias = "DISCORD_USER_ID")]
pub discord_user_id: u64,
}

impl Config {
pub fn new() -> Result<Self, Error> {
let config: Config = Figment::new()
.merge(Toml::file("config.toml"))
.merge(Env::raw().map(|v| v.to_string().to_lowercase().into()))
.merge(Env::raw())
.extract()?;
Ok(config)
}
Expand Down

0 comments on commit 87dc75e

Please sign in to comment.