diff --git a/src/bots/title.rs b/src/bots/title.rs index 99c756d..45543c7 100644 --- a/src/bots/title.rs +++ b/src/bots/title.rs @@ -91,7 +91,7 @@ impl Titlebot { )?; let mut spotify = ClientCredsSpotify::new(spotify_creds); - //spotify.request_token().await?; + spotify.request_token().await?; Ok(Self { url_regex, title_regex, diff --git a/src/main.rs b/src/main.rs index daf2847..3e72f42 100644 --- a/src/main.rs +++ b/src/main.rs @@ -56,7 +56,6 @@ pub struct AppState { titlebot: Titlebot, db: ExecutorConnection, git_channel: String, - git_recv: Receiver, } #[derive(Deserialize)] @@ -128,10 +127,9 @@ async fn main() -> anyhow::Result<()> { titlebot: Titlebot::create(spotify_creds).await?, db: db_conn, git_channel: client_config.git_channel, - git_recv, }; - if let Err(e) = executor(state, http_listen).await { + if let Err(e) = executor(state, git_recv, http_listen).await { tracing::error!("Error in message loop: {}", e); } @@ -143,11 +141,17 @@ async fn main() -> anyhow::Result<()> { Ok(()) } -async fn executor(mut state: AppState, http_listen: SocketAddr) -> anyhow::Result<()> { +async fn executor( + mut state: AppState, + mut git_recv: Receiver, + http_listen: SocketAddr, +) -> anyhow::Result<()> { let web_db = state.db.clone(); + let git_channel = state.git_channel.clone(); select! { - //r = web_service::run(web_db, http_listen) => r?; + r = web_service::run(web_db, http_listen) => r?, r = message_loop(&mut state) => r?, + r = git_recv.recv() => state.client.privmsg(&git_channel, &get_str(r)).await?, _ = terminate_signal() => { tracing::info!("Sending QUIT message"); state.client.quit(Some("überbot shutting down")).await?; @@ -166,12 +170,6 @@ async fn message_loop(state: &mut AppState) -> anyhow::Result<()> { .await?; } } - - if let Some(s) = state.git_recv.recv().await { - state.client.privmsg(&state.git_channel, &s).await?; - } - - tracing::info!("aaa"); } Ok(()) } @@ -298,3 +296,11 @@ async fn handle_privmsg( } Ok(()) } + +fn get_str(r: Option) -> String { + if let Some(s) = r { + s + } else { + String::new() + } +}