Push to switch OS
Signed-off-by: Louis Hollingworth <louis@hollingworth.nl>
This commit is contained in:
parent
c1e9f482b3
commit
290e9c17f5
3 changed files with 45 additions and 8 deletions
17
src/main.rs
17
src/main.rs
|
|
@ -31,11 +31,11 @@ async fn autojoin_room(room_member: matrix_sdk::ruma::events::room::member::Stri
|
|||
let mut delay = 2;
|
||||
let r = client.get_invited_room(rid).unwrap();
|
||||
while let Err(err) = r.accept_invitation().await {
|
||||
eprintln!("Failed to join room {} ({err:?}), retrying in {delay}s", room.room_id());
|
||||
tracing::error!("Failed to join room {} ({err:?}), retrying in {delay}s", room.room_id());
|
||||
tokio::time::sleep(tokio::time::Duration::from_secs(delay)).await;
|
||||
delay *= 2;
|
||||
if delay > 3600 {
|
||||
eprintln!("Can't join room {} ({err:?})", room.room_id());
|
||||
tracing::error!("Can't join room {} ({err:?})", room.room_id());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
|
@ -69,7 +69,7 @@ async fn connect_to_matrix(hs: String, username: String, passwd:String) -> anyho
|
|||
}
|
||||
}
|
||||
|
||||
println!("Logged in as {username}");
|
||||
tracing::info!("Logged in as {username}");
|
||||
let response = client.sync_once(matrix_sdk::config::SyncSettings::default()).await?;
|
||||
client.add_event_handler(on_room_message);
|
||||
client.add_event_handler(autojoin_room);
|
||||
|
|
@ -82,7 +82,16 @@ async fn connect_to_matrix(hs: String, username: String, passwd:String) -> anyho
|
|||
#[tokio::main]
|
||||
async fn main() -> anyhow::Result<()> {
|
||||
dotenvy::dotenv().ok();
|
||||
tracing_subscriber::fmt::init();
|
||||
let filter = tracing_subscriber::EnvFilter::from_default_env()
|
||||
.add_directive(tracing_subscriber::filter::LevelFilter::WARN.into())
|
||||
.add_directive("diru_bot=debug".parse()?);
|
||||
tracing_subscriber::fmt()
|
||||
.with_env_filter(filter)
|
||||
.with_level(true)
|
||||
.with_target(true)
|
||||
.with_ansi(true)
|
||||
.compact()
|
||||
.init();
|
||||
|
||||
let (homeserver_url, username, passwd) = match (std::env::var("HOMESERVER_URL"), std::env::var("MATRIX_BOT_NAME"), std::env::var("MATRIX_BOT_PASSWD")) {
|
||||
(Ok(a), Ok(b), Ok(c)) => (a, b, c),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue