matrix-meshtastic-bridge/src/main.rs
Finn 1343410e62
All checks were successful
/ build-container (push) Successful in 6m13s
Add container build
2024-10-14 16:14:20 -07:00

69 lines
1.7 KiB
Rust

use matrix_sdk::{config::SyncSettings, ruma::RoomId};
use tokio::signal;
use tokio::sync::mpsc;
mod bridge;
mod config;
mod db;
mod matrix;
mod meshtastic;
// #[tokio::main]
// async fn main() -> anyhow::Result<()> {
// env_logger::init();
// let config = config::read_config().await;
// let bridge = bridge::Bridge::setup(config).await.unwrap();
// bridge.run().await.unwrap();
// Ok(())
// }
#[tokio::main]
async fn main() -> anyhow::Result<()> {
env_logger::init();
let config = config::read_config().await;
let pool = db::setup(config.db).await.expect("error connecting to db");
let (matrix_tx, matrix_rx) = mpsc::channel(32);
let room_id = RoomId::parse(&config.matrix.room).expect("invalid room id");
log::debug!("matrix room: {:?}", room_id);
let matrix_client = matrix::build(config.matrix)
.await
.expect("error logging into matrix");
matrix_client.sync_once(SyncSettings::default()).await?;
let meshtastic_client = meshtastic::build(config.meshtastic)
.await
.expect("error connecting to meshtastic");
tokio::spawn(async {
meshtastic_client
.receive(matrix_tx)
.await
.expect("error receiving message from meshtastic");
});
tokio::spawn(matrix::sender(matrix_client.clone(), matrix_rx, room_id));
tokio::spawn(matrix::sync(matrix_client.clone()));
match signal::ctrl_c().await {
Ok(()) => {}
Err(err) => {
log::error!("Unable to listen for shutdown signal: {}", err);
}
}
log::debug!("shutting down database connection");
pool.close().await;
log::debug!("db connection closed");
Ok(())
}