#[macro_use] extern crate log; #[macro_use] mod log_util; mod config; mod register; mod toot; use config::Config; use elefren::{helpers::cli, MastodonClient}; use std::path::PathBuf; fn main() { std::env::set_var("RUST_LOG", "unionbot=debug,warn"); log_util::initialise(); let path = PathBuf::new().join("acab.toml"); let mut cfg = Config::load(path.as_path()); // Register the app, or authenticate. Tries to re-write the // configuration file with the updated client secrets, but will // print to stdout if this fails. let masto = match cfg.secret() { Some(_) => { debug!("Attempting authentication with stored secret..."); cfg.registration() }, None => { warn!("No client secret available, attempting registration!"); let reg = register::register(&cfg).unwrap(); let masto = cli::authenticate(reg).unwrap(); cfg.update_secret(&masto.data); info!("Persisting client configuration in {}", "acab.toml"); if let Err(e) = cfg.save(path.as_path()) { error!("Writing configuration file failed: {}", e); error!("Dumping new configuration on stdout..."); println!("{}", cfg.as_toml()); fatal!("Byeee"); } masto } }; info!("Successfully authenticated! ^-^"); masto.new_status(toot::make(&cfg)).unwrap(); }