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