main.rs (1714B)
1 use crate::{config::Config, google_calendar::start_webserver}; 2 use clap::Clap; 3 use matrix_sdk::Client; 4 use mrsbfh::config::Loader; 5 use oauth2::{ 6 basic::{BasicClient, BasicTokenResponse}, 7 CsrfToken, PkceCodeVerifier, 8 }; 9 use once_cell::sync::{Lazy, OnceCell}; 10 use std::{collections::BTreeMap, error::Error}; 11 use tracing::*; 12 13 pub mod commands; 14 mod config; 15 mod errors; 16 mod google_calendar; 17 mod matrix; 18 19 #[derive(Clap)] 20 #[clap(version = "0.1.0", author = "MTRNord")] 21 struct Opts { 22 #[clap(short, long, default_value = "config.yml")] 23 config: String, 24 } 25 26 pub static MATRIX_CLIENT: OnceCell<Client> = OnceCell::new(); 27 pub static LOGIN_SESSIONS_VERIFIER: Lazy< 28 tokio::sync::RwLock<BTreeMap<String, (BasicClient, PkceCodeVerifier, CsrfToken)>>, 29 > = Lazy::new(|| tokio::sync::RwLock::new(BTreeMap::new())); 30 pub static GOOGLE_SESSIONS: Lazy<tokio::sync::RwLock<BTreeMap<String, BasicTokenResponse>>> = 31 Lazy::new(|| tokio::sync::RwLock::new(BTreeMap::new())); 32 pub static STATE_TO_MXID: Lazy<tokio::sync::RwLock<BTreeMap<String, String>>> = 33 Lazy::new(|| tokio::sync::RwLock::new(BTreeMap::new())); 34 35 #[tokio::main] 36 async fn main() -> Result<(), Box<dyn Error>> { 37 tracing_subscriber::fmt() 38 .pretty() 39 .with_thread_names(true) 40 .with_max_level(tracing::Level::INFO) 41 .init(); 42 43 info!("Starting..."); 44 let opts: Opts = Opts::parse(); 45 46 info!("Loading Configs..."); 47 let config = Config::load(opts.config)?; 48 info!("Setting up Client..."); 49 let client = matrix::setup(config.clone()).await?; 50 51 tokio::spawn(async move { 52 start_webserver().await; 53 }); 54 info!("Starting Sync..."); 55 matrix::start_sync(client, config).await?; 56 57 Ok(()) 58 }