Compare commits
No commits in common. "b57720a2f875ea8766fbcbd555a5c31ca91c0247" and "5a65c713bd9455fc53c34e4821c6622e3d9bf87d" have entirely different histories.
b57720a2f8
...
5a65c713bd
@ -1,5 +1,6 @@
|
|||||||
use std::{collections::HashMap, fmt, fs::File, io::BufReader};
|
use std::{collections::HashMap, fmt, fs::File, io::BufReader};
|
||||||
|
|
||||||
|
use anyhow::Context;
|
||||||
use matrix_sdk::ruma::{OwnedRoomOrAliasId, OwnedUserId, RoomOrAliasId, UserId};
|
use matrix_sdk::ruma::{OwnedRoomOrAliasId, OwnedUserId, RoomOrAliasId, UserId};
|
||||||
use serde::de;
|
use serde::de;
|
||||||
|
|
||||||
@ -111,7 +112,7 @@ where
|
|||||||
deserializer.deserialize_any(OptionalRoomOrAliasIdVisitor)
|
deserializer.deserialize_any(OptionalRoomOrAliasIdVisitor)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_blocking(path: String) -> anyhow::Result<Config> {
|
fn load_blocking(path: &String) -> anyhow::Result<Config> {
|
||||||
let f = File::open(path)?;
|
let f = File::open(path)?;
|
||||||
let r = BufReader::new(f);
|
let r = BufReader::new(f);
|
||||||
let config: Config = serde_yaml::from_reader(r)?;
|
let config: Config = serde_yaml::from_reader(r)?;
|
||||||
@ -120,6 +121,9 @@ fn load_blocking(path: String) -> anyhow::Result<Config> {
|
|||||||
|
|
||||||
pub async fn load<S: AsRef<str>>(path: S) -> anyhow::Result<Config> {
|
pub async fn load<S: AsRef<str>>(path: S) -> anyhow::Result<Config> {
|
||||||
let p = String::from(path.as_ref());
|
let p = String::from(path.as_ref());
|
||||||
let config = tokio::task::spawn_blocking(move || load_blocking(p)).await??;
|
let config = tokio::task::spawn_blocking(move || {
|
||||||
|
load_blocking(&p).with_context(|| format!("Failed to load config from {}", p))
|
||||||
|
})
|
||||||
|
.await??;
|
||||||
Ok(config)
|
Ok(config)
|
||||||
}
|
}
|
||||||
|
34
src/main.rs
34
src/main.rs
@ -8,8 +8,9 @@ extern crate serde;
|
|||||||
mod config;
|
mod config;
|
||||||
mod event;
|
mod event;
|
||||||
|
|
||||||
use std::{env, net::IpAddr, ops::Deref, sync::Arc, time::Duration};
|
use std::{env, net::IpAddr, ops::Deref, process::exit, sync::Arc, time::Duration};
|
||||||
|
|
||||||
|
use anyhow::Context;
|
||||||
use constant_time_eq::constant_time_eq;
|
use constant_time_eq::constant_time_eq;
|
||||||
use event::{GitlabEvent, GitlabEventExt};
|
use event::{GitlabEvent, GitlabEventExt};
|
||||||
use http::StatusCode;
|
use http::StatusCode;
|
||||||
@ -49,7 +50,10 @@ async fn matrix_connect(config: &config::Config) -> anyhow::Result<Client> {
|
|||||||
let sync_client = client.clone();
|
let sync_client = client.clone();
|
||||||
tokio::spawn(async move {
|
tokio::spawn(async move {
|
||||||
let settings = build_sync_settings(&sync_client).await;
|
let settings = build_sync_settings(&sync_client).await;
|
||||||
sync_client.sync(settings).await.unwrap();
|
if let Err(err) = sync_client.sync(settings).await {
|
||||||
|
error!("Matrix sync failed: {}", err);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Ok(client)
|
Ok(client)
|
||||||
@ -129,23 +133,18 @@ async fn handle_gitlab_event(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tokio::main]
|
async fn run() -> anyhow::Result<()> {
|
||||||
async fn main() -> anyhow::Result<()> {
|
|
||||||
let lenv = env_logger::Env::new()
|
|
||||||
.filter("BEBOT_LOG")
|
|
||||||
.write_style("BEBOT_LOG_STYLE");
|
|
||||||
env_logger::init_from_env(lenv);
|
|
||||||
|
|
||||||
let config_path = env::args()
|
let config_path = env::args()
|
||||||
.nth(1)
|
.nth(1)
|
||||||
.expect("Config file should be passed as only parameter");
|
.ok_or_else(|| anyhow!("Config file should be passed as only parameter"))?;
|
||||||
let config = Arc::new(config::load(config_path).await?);
|
let config = Arc::new(config::load(config_path).await?);
|
||||||
let addr = config
|
let addr = config
|
||||||
.bind_address
|
.bind_address
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.map(|ba| ba.clone())
|
.map(|ba| ba.clone())
|
||||||
.unwrap_or_else(|| "127.0.0.1".to_string())
|
.unwrap_or_else(|| "127.0.0.1".to_string())
|
||||||
.parse::<IpAddr>()?;
|
.parse::<IpAddr>()
|
||||||
|
.context("Failed to parse bind_address")?;
|
||||||
let port = config.bind_port.unwrap_or(3000);
|
let port = config.bind_port.unwrap_or(3000);
|
||||||
|
|
||||||
let matrix_client = matrix_connect(&config).await?;
|
let matrix_client = matrix_connect(&config).await?;
|
||||||
@ -191,3 +190,16 @@ async fn main() -> anyhow::Result<()> {
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tokio::main]
|
||||||
|
async fn main() {
|
||||||
|
let lenv = env_logger::Env::new()
|
||||||
|
.filter("BEBOT_LOG")
|
||||||
|
.write_style("BEBOT_LOG_STYLE");
|
||||||
|
env_logger::init_from_env(lenv);
|
||||||
|
|
||||||
|
if let Err(err) = run().await {
|
||||||
|
error!("{}", err);
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user