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