aboutsummaryrefslogtreecommitdiff
path: root/src/util.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/util.rs
parent7cd17b04f7422dcce1410ec26922cba161cd6e0d (diff)
move configuration into envconfig
Diffstat (limited to 'src/util.rs')
-rw-r--r--src/util.rs19
1 files changed, 4 insertions, 15 deletions
diff --git a/src/util.rs b/src/util.rs
index eb38d9c..ca50157 100644
--- a/src/util.rs
+++ b/src/util.rs
@@ -1,9 +1,3 @@
-use std::{
- env,
- str::FromStr,
-};
-
-use dotenv;
use serenity::{
client::Context,
model::{
@@ -19,6 +13,7 @@ use url::Url;
use lazy_static::lazy_static;
use crate::{
+ CONFIG,
audio::PlayQueue,
Result,
};
@@ -38,13 +33,12 @@ impl CtxExt for Context {
}
fn users_listening(&self) -> Result<bool> {
- let channel_id = ChannelId(must_env_lookup::<u64>("VOICE_CHANNEL"));
- let channel = channel_id.to_channel(self)?;
+ let channel = CONFIG.discord.voice_channel().to_channel(self)?;
let res = channel.guild()
.and_then(|ch| ch.read().guild(self))
.map(|g| (&g.read().voice_states)
.into_iter()
- .any(|(_, state)| state.channel_id == Some(channel_id)))
+ .any(|(_, state)| state.channel_id == Some(CONFIG.discord.voice_channel())))
.unwrap_or(false);
Ok(res)
@@ -81,12 +75,7 @@ lazy_static! {
pub static ref OAUTH_URL: Url = Url::parse(
&format!(
"https://discordapp.com/api/oauth2/authorize?scope=bot&permissions={}&client_id={}",
- REQUIRED_PERMS.bits(), dotenv!("THULANI_CLIENT_ID"),
+ REQUIRED_PERMS.bits(), CONFIG.discord.auth.client_id,
)
).unwrap();
}
-
-pub fn must_env_lookup<T: FromStr>(s: &str) -> T {
- env::var(s).expect(&format!("missing env var {}", s))
- .parse::<T>().unwrap_or_else(|_| panic!(format!("bad format for {}", s)))
-}