aboutsummaryrefslogtreecommitdiff
path: root/src/config.rs
diff options
context:
space:
mode:
authorNathan Perry <np@nathanperry.dev>2020-06-20 16:17:05 -0400
committerNathan Perry <np@nathanperry.dev>2020-06-20 16:17:05 -0400
commit16e660f5cd3787e587a5d082f57ab9d900aee0ca (patch)
treeb6d67d820f2342f42f2dae00318f416d8a6142f9 /src/config.rs
parent7cd17b04f7422dcce1410ec26922cba161cd6e0d (diff)
move configuration into envconfig
Diffstat (limited to 'src/config.rs')
-rw-r--r--src/config.rs80
1 files changed, 80 insertions, 0 deletions
diff --git a/src/config.rs b/src/config.rs
new file mode 100644
index 0000000..13d015e
--- /dev/null
+++ b/src/config.rs
@@ -0,0 +1,80 @@
+use serenity::{
+ model::id::{
+ GuildId,
+ UserId,
+ ChannelId,
+ },
+};
+
+use envconfig::Envconfig;
+
+#[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,
+
+ pub discord: DiscordConfig,
+
+ pub sheets: SheetsConfig,
+}
+
+#[derive(Envconfig)]
+pub struct DiscordConfig {
+ pub auth: DiscordAuth,
+
+ #[envconfig(from = "TARGET_GUILD")]
+ guild: u64,
+
+ #[envconfig(from = "OWNER_ID")]
+ owner: u64,
+
+ #[envconfig(from = "VOICE_CHANNEL")]
+ voice_channel: u64,
+}
+
+impl DiscordConfig {
+ #[inline]
+ pub fn guild(&self) -> GuildId {
+ self.guild.into()
+ }
+
+ #[inline]
+ pub fn owner(&self) -> UserId {
+ self.owner.into()
+ }
+
+ #[inline]
+ pub fn voice_channel(&self) -> ChannelId {
+ self.voice_channel.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,
+} \ No newline at end of file