aboutsummaryrefslogtreecommitdiff
path: root/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib.rs')
-rw-r--r--src/lib.rs35
1 files changed, 9 insertions, 26 deletions
diff --git a/src/lib.rs b/src/lib.rs
index 82bdad5..37e9d89 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -2,12 +2,10 @@
#[cfg(all(test, feature = "bench"))]
extern crate test;
-use anyhow::Result;
+use anyhow::{Context, Result};
use irc::client::prelude::*;
-use tracing::info;
-
pub mod config;
pub mod hooks;
pub mod util;
@@ -23,44 +21,29 @@ macro_rules! reply {
pub struct Bot {
pub config: config::Config,
+ pub figment: figment::Figment,
pub irc_client: irc::client::Client,
}
-fn get_env_var(var_name: &str) -> Option<String> {
- match std::env::var(var_name) {
- Ok(var) => {
- info!("using {} from env", var_name);
- Some(var)
- }
- Err(_) => None,
- }
-}
-
impl Bot {
- pub async fn new(config_path: &str) -> Result<Bot> {
- use std::fs;
+ pub async fn new() -> Result<Bot> {
+ let figment = config::Config::figment();
+ let config: config::Config = figment.extract().context("failed to extract config")?;
+
+ let irc_client = Client::from_config(config.clone().into()).await?;
- 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 })
+ pub fn figment(&self) -> &figment::Figment {
+ &self.figment
}
pub async fn sasl_init(&self) -> Result<()> {
lass='insertions'>+39 2021-06-21publish macros subcrateMax Audron-20/+20 2021-06-13release version 1.2.1Max Audron-2/+2 2021-06-13fix crash on message only containing whitespaceMax Audron-1/+4 2021-06-11Release version 1.2.01.2.0Max Audron-2/+2 2021-06-06make pet more compactR0flcopt3r/catinator-pet-commandMax Audron-5/+5 2021-06-05feat: adds pet command.R0flcopt3r-0/+90 2021-06-05feat: send actionR0flcopt3r-1/+9 2021-06-05release version 1.1.0Max Audron-2/+2 2021-06-05document proc macrosMax Audron-4/+97 2021-06-05add intensifyMax Audron-3/+27 2021-06-05add privmsg macroMax Audron-2/+40 2021-06-05fix jb remote urlsMax Audron-4/+4 2021-06-05remove egress gateway configMax Audron-10/+0 2021-06-05update tanka dependenciesMax Audron-8/+8 2021-06-05fix init container nameMax Audron-1/+1 2021-06-05fix tanka dependency pathMax Audron-8/+8 2021-06-05switch to https url for tanka util libMax Audron-2/+2 2021-06-05bump version to 1.0.2Max Audron-2/+2 2021-06-05add tanka ci configurationMax Audron-1/+1 2021-06-05ready tanka deploy for CIMax Audron-32/+69 2021-06-05remove tanka vendoringMax Audron-27651/+0 2021-05-26Release 1.0.1Max Audron-3/+3 2021-05-26fix log breaking once buffer fullMax Audron-2/+33 2021-05-16add deployment stuffMax Audron-6/+27786 2021-05-15add container buildMax Audron-2/+35