Compare commits
1 commit
Author | SHA1 | Date | |
---|---|---|---|
6dd5db6550 |
4 changed files with 25 additions and 31 deletions
12
flake.lock
12
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": {
|
||||
|
|
|
@ -19,15 +19,8 @@ struct Discord {
|
|||
}
|
||||
|
||||
impl Discord {
|
||||
pub fn try_new(conf: Arc<Config>) -> Result<Self> {
|
||||
let discord = DDiscord::from_bot_token(
|
||||
conf.discord
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.bot_token
|
||||
.clone()
|
||||
.expose_secret(),
|
||||
)?;
|
||||
pub fn try_new(bot_token: &str) -> Result<Self> {
|
||||
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<Config>) -> 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
|
||||
}
|
||||
|
|
|
@ -27,10 +27,6 @@ pub struct Config {
|
|||
pub open_ai: Option<OpenAI>,
|
||||
}
|
||||
|
||||
pub struct ConfigLoadResult {
|
||||
pub config: Config,
|
||||
}
|
||||
|
||||
const CONFIG_FILE_PATH: &str = "./conf.toml";
|
||||
|
||||
impl Config {
|
||||
|
|
|
@ -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<E> From<E> for WebserverError
|
||||
where
|
||||
E: Into<anyhow::Error>,
|
||||
|
|
Loading…
Reference in a new issue