1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
use std::path::PathBuf;
use dotenv::dotenv;
use envconfig::Envconfig;
use grate::tracing;
use lazy_static::lazy_static;
use serenity::model::id::UserId;
lazy_static! {
pub static ref CONFIG: Config = {
dotenv().ok();
Config::init_from_env().unwrap()
};
pub static ref FFMPEG_COMMAND: String = {
let result = CONFIG.ffmpeg.clone().unwrap_or("ffmpeg".to_owned());
tracing::debug!(ffmpeg = %result, "got ffmpeg");
result
};
pub static ref YTDL_COMMAND: String = {
let result = CONFIG.ytdl.clone().unwrap_or("yt-dlp".to_owned());
tracing::debug!(ytdl = %result, "got ytdl");
result
};
}
#[derive(Envconfig)]
pub struct Config {
#[envconfig(from = "DATABASE_URL")]
pub db_string: String,
#[envconfig(from = "MAX_HIST")]
pub max_hist: usize,
#[envconfig(from = "DEFAULT_HIST")]
pub default_hist: usize,
#[envconfig(from = "STEAM_API_KEY")]
pub steam_api_key: String,
#[envconfig(from = "FFMPEG")]
pub ffmpeg: Option<String>,
#[envconfig(from = "YTDL")]
pub ytdl: Option<String>,
#[envconfig(from = "USER_ID_MAPPING")]
pub user_id_mapping: Option<PathBuf>,
#[envconfig(from = "RESTRICT")]
pub restrict: Option<PathBuf>,
#[envconfig(nested = true)]
pub discord: DiscordConfig,
#[envconfig(nested = true)]
pub sheets: SheetsConfig,
}
#[derive(Envconfig)]
pub struct DiscordConfig {
#[envconfig(nested = true)]
pub auth: DiscordAuth,
#[envconfig(from = "OWNER_ID")]
owner: u64,
}
impl DiscordConfig {
#[inline]
pub fn owner(&self) -> UserId {
self.owner.into()
}
}
#[derive(Envconfig)]
pub struct DiscordAuth {
#[envconfig(from = "THULANI_CLIENT_ID")]
pub client_id: u64,
#[envconfig(from = "THULANI_TOKEN")]
pub token: String,
}
#[derive(Envconfig)]
pub struct SheetsConfig {
#[envconfig(from = "SHEETS_API_KEY")]
pub api_key: String,
#[envconfig(from = "SPREADSHEET_ID")]
pub spreadsheet: String,
#[envconfig(from = "MAX_SHEET_COLUMN")]
pub max_column: String,
}
|