knowledge-search

git clone git://archive.git.mtrnord.blog/MTRNord/knowledge-search.git
Log | Files | Refs | README | LICENSE

main.rs (2739B)


      1 #![deny(unsafe_code, clippy::unwrap_used)]
      2 #![warn(
      3     clippy::cognitive_complexity,
      4     clippy::branches_sharing_code,
      5     clippy::imprecise_flops,
      6     clippy::missing_const_for_fn,
      7     clippy::mutex_integer,
      8     clippy::path_buf_push_overwrite,
      9     clippy::redundant_pub_crate,
     10     clippy::pedantic,
     11     clippy::dbg_macro,
     12     clippy::todo,
     13     clippy::fallible_impl_from,
     14     clippy::filetype_is_file,
     15     clippy::suboptimal_flops,
     16     clippy::fn_to_numeric_cast_any,
     17     clippy::if_then_some_else_none,
     18     clippy::imprecise_flops,
     19     clippy::lossy_float_literal,
     20     clippy::panic_in_result_fn,
     21     clippy::clone_on_ref_ptr
     22 )]
     23 #![allow(clippy::missing_panics_doc)]
     24 // I am lazy. Dont blame me!
     25 #![allow(missing_docs)]
     26 
     27 use std::collections::BTreeSet;
     28 
     29 use color_eyre::{eyre::bail, Result};
     30 
     31 use config::{load, write_access_token};
     32 use matrix::IndexerBot;
     33 use tracing::info;
     34 
     35 mod config;
     36 mod indradb_utils;
     37 mod matrix;
     38 
     39 #[tokio::main]
     40 async fn main() -> Result<()> {
     41     std::env::set_var("RUST_LOG", "matrix_sdk=info,matrix-indexer=debug");
     42     tracing_subscriber::fmt::init();
     43     color_eyre::install()?;
     44 
     45     // Errors in the config will crash directly.
     46     let config = load();
     47 
     48     // Make sure to update identifier list. These are ONLY the ones we can query aka they are indexed
     49     let mut identifiers = BTreeSet::from([
     50         String::from("text_message_body"),
     51         String::from("text_message_formatted_body"),
     52         String::from("room_id"),
     53         String::from("room_name"),
     54         String::from("room_topic"),
     55         String::from("event_id"),
     56     ]);
     57     utils::add_identifiers(&mut identifiers)?;
     58 
     59     #[allow(clippy::unwrap_used)]
     60     let mut bot = match config.auth_data {
     61         config::AuthData::UsernamePassword(mxid, password) => {
     62             let bot = IndexerBot::new(
     63                 config.homeserver_url,
     64                 mxid,
     65                 password,
     66                 config.indradb_endpoint,
     67             )
     68             .await?;
     69             let access_token = bot.access_token();
     70             let device_id = bot.device_id();
     71             if access_token.is_none() || device_id.is_none() {
     72                 bail!("Login to matrix must have failed. We got no access_token or device_id!");
     73             }
     74             write_access_token(access_token.unwrap(), device_id.unwrap())?;
     75             bot
     76         }
     77         config::AuthData::AccessToken(mxid, access_token, device_id) => {
     78             IndexerBot::relogin(
     79                 config.homeserver_url,
     80                 mxid,
     81                 access_token,
     82                 device_id,
     83                 config.indradb_endpoint,
     84             )
     85             .await?
     86         }
     87     };
     88     info!("Starting to process");
     89     bot.start_processing().await?;
     90 
     91     Ok(())
     92 }