Add support for reading mail-archive.com RSS feeds
This commit is contained in:
43
src/main.rs
43
src/main.rs
@@ -22,37 +22,50 @@ extern crate log;
|
||||
extern crate serde;
|
||||
|
||||
mod config;
|
||||
mod gitlab;
|
||||
mod gitlab_event;
|
||||
mod gitlab_webhook;
|
||||
mod mail_archive;
|
||||
mod matrix;
|
||||
|
||||
use std::{env, net::IpAddr, process::exit, sync::Arc};
|
||||
use std::{env, net::IpAddr, process::exit};
|
||||
|
||||
use anyhow::Context;
|
||||
use futures::future::join_all;
|
||||
use warp::Filter;
|
||||
|
||||
async fn run() -> anyhow::Result<()> {
|
||||
let config_path = env::args()
|
||||
.nth(1)
|
||||
.ok_or_else(|| anyhow!("Config file should be passed as only parameter"))?;
|
||||
let config = Arc::new(config::load(config_path).await?);
|
||||
let mut config = config::load(config_path).await?;
|
||||
|
||||
let matrix_client = matrix::connect(&config).await.context("Failed to connect to Matrix")?;
|
||||
|
||||
let gitlab = gitlab::build_webhook_route(Arc::clone(&config), matrix_client)?;
|
||||
let routes = gitlab.with(warp::log("bebot"));
|
||||
let handles = if let Some(mail_archive) = config.mail_archive.take() {
|
||||
mail_archive::start_polling(mail_archive, matrix_client.clone())?
|
||||
} else {
|
||||
vec![]
|
||||
};
|
||||
|
||||
let addr = config
|
||||
.bind_address
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| "127.0.0.1".to_string())
|
||||
.parse::<IpAddr>()
|
||||
.context("Failed to parse bind_address")?;
|
||||
let port = config.bind_port.unwrap_or(3000);
|
||||
warp::serve(routes).run((addr, port)).await;
|
||||
if let Some(gitlab_webhook) = config.gitlab_webhook.take() {
|
||||
let gitlab = gitlab_webhook::build_route(gitlab_webhook, matrix_client.clone())?;
|
||||
let routes = gitlab.with(warp::log("bebot"));
|
||||
|
||||
Ok(())
|
||||
let addr = config
|
||||
.bind_address
|
||||
.as_ref()
|
||||
.cloned()
|
||||
.unwrap_or_else(|| "127.0.0.1".to_string())
|
||||
.parse::<IpAddr>()
|
||||
.context("Failed to parse bind_address")?;
|
||||
let port = config.bind_port.unwrap_or(3000);
|
||||
warp::serve(routes).run((addr, port)).await;
|
||||
}
|
||||
|
||||
join_all(handles).await;
|
||||
|
||||
error!("No functionality is configured; exiting");
|
||||
exit(1);
|
||||
}
|
||||
|
||||
#[tokio::main]
|
||||
|
Reference in New Issue
Block a user