From 16e660f5cd3787e587a5d082f57ab9d900aee0ca Mon Sep 17 00:00:00 2001 From: Nathan Perry Date: Sat, 20 Jun 2020 16:17:05 -0400 Subject: move configuration into envconfig --- src/util.rs | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'src/util.rs') 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 { - let channel_id = ChannelId(must_env_lookup::("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(s: &str) -> T { - env::var(s).expect(&format!("missing env var {}", s)) - .parse::().unwrap_or_else(|_| panic!(format!("bad format for {}", s))) -} -- cgit v1.3.1