diff --git a/flake.lock b/flake.lock index 66240dd..20c4188 100644 --- a/flake.lock +++ b/flake.lock @@ -45,11 +45,11 @@ "nixpkgs-stable": "nixpkgs-stable" }, "locked": { - "lastModified": 1712579741, - "narHash": "sha256-igpsH+pa6yFwYOdah3cFciCk8gw+ytniG9quf5f/q84=", + "lastModified": 1714478972, + "narHash": "sha256-q//cgb52vv81uOuwz1LaXElp3XAe1TqrABXODAEF6Sk=", "owner": "cachix", "repo": "git-hooks.nix", - "rev": "70f504012f0a132ac33e56988e1028d88a48855c", + "rev": "2849da033884f54822af194400f8dff435ada242", "type": "github" }, "original": { @@ -81,11 +81,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1712608508, - "narHash": "sha256-vMZ5603yU0wxgyQeHJryOI+O61yrX2AHwY6LOFyV1gM=", + "lastModified": 1714635257, + "narHash": "sha256-4cPymbty65RvF1DWQfc+Bc8B233A1BWxJnNULJKQ1EY=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "4cba8b53da471aea2ab2b0c1f30a81e7c451f4b6", + "rev": "63c3a29ca82437c87573e4c6919b09a24ea61b0f", "type": "github" }, "original": { diff --git a/src/chatbot.rs b/src/chatbot.rs index bf2bbe7..aa47d2b 100644 --- a/src/chatbot.rs +++ b/src/chatbot.rs @@ -19,15 +19,8 @@ struct Discord { } impl Discord { - pub fn try_new(conf: Arc) -> Result { - let discord = DDiscord::from_bot_token( - conf.discord - .as_ref() - .unwrap() - .bot_token - .clone() - .expose_secret(), - )?; + pub fn try_new(bot_token: &str) -> Result { + let discord = DDiscord::from_bot_token(bot_token)?; Ok(Self { discord, connection: None, @@ -233,15 +226,19 @@ impl Discord { use crate::prelude::*; pub async fn start(conf: Arc) -> Result<()> { - if conf.discord.is_none() { - warn!("Chatbot starting without Discord token. Nothing will happen."); - // wait forever - future::pending::<()>().await; + match &conf.discord { + None => { + warn!("Chatbot starting without Discord token. Nothing will happen."); + // wait forever + future::pending::<()>().await; + Ok(()) + } + Some(d) => { + let mut discord = Discord::try_new(d.bot_token.expose_secret())?; + let ready_ev = discord.connect().await; + info!("Discord connection ready: {ready_ev:?}"); + let adiscord = Arc::new(discord); + adiscord.handle_commands().await + } } - - let mut discord = Discord::try_new(conf.clone())?; - let ready_ev = discord.connect().await; - info!("Discord connection ready: {ready_ev:?}"); - let adiscord = Arc::new(discord); - adiscord.handle_commands().await } diff --git a/src/config.rs b/src/config.rs index 93a1818..3e7a472 100644 --- a/src/config.rs +++ b/src/config.rs @@ -27,10 +27,6 @@ pub struct Config { pub open_ai: Option, } -pub struct ConfigLoadResult { - pub config: Config, -} - const CONFIG_FILE_PATH: &str = "./conf.toml"; impl Config { diff --git a/src/webserver.rs b/src/webserver.rs index 0f54430..09ef471 100644 --- a/src/webserver.rs +++ b/src/webserver.rs @@ -69,8 +69,9 @@ impl IntoResponse for WebserverError { } } -// This enables using `?` on functions that return `Result<_, anyhow::Error>` to turn them into -// `Result<_, AppError>`. That way you don't need to do that manually. +// This enables using `?` on functions that return `Result<_, anyhow::Error>` +// to turn them into `Result<_, AppError>`. That way you don't need to do that +// manually. impl From for WebserverError where E: Into,