diff --git a/src/main.rs b/src/main.rs index 519732d546..ad37c70cec 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,6 +5,7 @@ use crate::util::anyhow_result::AnyhowResult; use twitch_api2::TwitchClient; use twitch_api2::helix::channels::GetChannelInformationRequest; use twitch_oauth2::{AppAccessToken, Scope, TwitchToken, tokens::errors::AppAccessTokenError, ClientId, ClientSecret}; +use crate::twitch::secrets::TwitchSecrets; pub mod twitch; pub mod util; @@ -27,11 +28,10 @@ fn main() -> AnyhowResult<()> { #[tokio::main] async fn run() -> AnyhowResult<()> { - let client_id = "".to_string(); - let client_secret = "".to_string(); + let secrets = TwitchSecrets::from_file("secrets.toml")?; - let client_id = ClientId::new(client_id); - let client_secret = ClientSecret::new(client_secret); + let client_id = ClientId::new(&secrets.app_client_id); + let client_secret = ClientSecret::new(&secrets.app_client_secret); let client: TwitchClient = TwitchClient::default(); let token = AppAccessToken::get_app_access_token( @@ -42,7 +42,8 @@ async fn run() -> AnyhowResult<()> { ).await?; let req = GetChannelInformationRequest::builder() - .broadcaster_id("27620241") + //.broadcaster_id("27620241") + .broadcaster_id("650154491") .build(); println!( diff --git a/src/twitch/secrets.rs b/src/twitch/secrets.rs index 237c5d18f1..539a6507b0 100644 --- a/src/twitch/secrets.rs +++ b/src/twitch/secrets.rs @@ -2,13 +2,12 @@ use crate::util::anyhow_result::AnyhowResult; // TODO: Not sure I need all of these. The less I need to keep, the better. // Oauth delegation in particular seems not necessary. -#[derive(Clone)] +#[derive(Clone, serde::Deserialize)] pub struct TwitchSecrets { pub username: String, pub stream_key: String, pub app_client_id: String, pub app_client_secret: String, - pub oauth_access_token: String, } impl TwitchSecrets { @@ -17,14 +16,12 @@ impl TwitchSecrets { stream_key: &str, app_client_id: &str, app_client_secret: &str, - oauth_access_token: &str ) -> Self { Self { username: username.to_string(), stream_key: stream_key.to_string(), app_client_id: app_client_id.to_string(), app_client_secret: app_client_secret.to_string(), - oauth_access_token: oauth_access_token.to_string(), } } @@ -34,8 +31,13 @@ impl TwitchSecrets { &easyenv::get_env_string_required("TWITCH_STREAM_KEY")?, &easyenv::get_env_string_required("TWITCH_APP_CLIENT_ID")?, &easyenv::get_env_string_required("TWITCH_APP_CLIENT_SECRET")?, - &easyenv::get_env_string_required("TWITCH_OAUTH_ACCESS_TOKEN")?, )) } + + pub fn from_file(filename: &str) -> AnyhowResult { + let contents = std::fs::read_to_string(filename)?; + let secrets = toml::from_str(&contents)?; + Ok(secrets) + } }