diff options
| author | Max Audron <audron@cocaine.farm> | 2021-10-16 13:48:56 +0200 |
|---|---|---|
| committer | Max Audron <audron@cocaine.farm> | 2021-10-16 13:48:56 +0200 |
| commit | 7724231ac4511ae3b7c737b51166dbb9e8d8a62c (patch) | |
| tree | cac73fdfbb80b7bac9f42fa389e9089bc633d0ce | |
| parent | make util functions world public (diff) | |
move bot initialization out of macro
Diffstat (limited to '')
| -rw-r--r-- | macros/src/lib.rs | 9 | ||||
| -rw-r--r-- | src/lib.rs | 7 | ||||
| -rw-r--r-- | src/main.rs | 2 |
3 files changed, 9 insertions, 9 deletions
diff --git a/macros/src/lib.rs b/macros/src/lib.rs index 2ccd220..7c5ce19 100644 --- a/macros/src/lib.rs +++ b/macros/src/lib.rs @@ -175,15 +175,6 @@ pub fn catinator(tokens: TokenStream) -> TokenStream { use irc::client::prelude::*; use catinator::Bot; - let config_path = env::var("CATINATOR_CONFIG").unwrap_or("config.toml".to_string()); - info!("starting bot with config file {}", config_path); - let mut bot = Bot::new(&config_path).await.unwrap(); - - if bot.config.server.sasl { - info!("initializing sasl"); - bot.sasl_init().await.unwrap() - } - #(#matchers_regex)* info!("starting main event loop"); @@ -42,16 +42,23 @@ impl Bot { let config_str = fs::read_to_string(config_path)?; let mut config: config::Config = toml::from_str(&config_str)?; + let bot = Bot { irc_client, config, figment }; if let Some(v) = get_env_var("CATINATOR_PASSWORD") { config.user.password = v }; + if bot.config.server.sasl && bot.config.user.password.is_some() { + tracing::info!("initializing sasl"); + bot.sasl_init().await.unwrap() + } if let Some(v) = get_env_var("CATINATOR_WA_API_KEY") { config.settings.wa_api_key = v }; let irc_client = Client::from_config(config.clone().into()).await?; + Ok(bot) + } Ok(Bot { irc_client, config }) } diff --git a/src/main.rs b/src/main.rs index fd2d3b2..100af91 100644 --- a/src/main.rs +++ b/src/main.rs @@ -9,6 +9,8 @@ async fn main() { .with_thread_ids(true) .init(); + let mut bot = Bot::new().await.unwrap(); + let mut sed = catinator::hooks::sed::Sed::new(); catinator