Compare commits

..

2 Commits

5 changed files with 26 additions and 11 deletions

11
Cargo.lock generated
View File

@ -4571,6 +4571,15 @@ version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "signal-hook-registry"
version = "1.4.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1"
dependencies = [
"libc",
]
[[package]]
name = "signature"
version = "2.2.0"
@ -4897,7 +4906,9 @@ dependencies = [
"bytes",
"libc",
"mio",
"parking_lot",
"pin-project-lite",
"signal-hook-registry",
"socket2",
"tokio-macros",
"tracing",

View File

@ -41,7 +41,7 @@ ncr = { version = "0", features = ["cfb8", "ecb", "gcm"] }
parking_lot = "0"
serde = "1"
serde_json = "1"
tokio = { version = "1", features = ["macros"] }
tokio = { version = "1", features = ["full"] }
zip = { version = "2", default-features = false, features = ["flate2"] }
[features]

View File

@ -1,4 +1,4 @@
use std::{net::SocketAddr, process::exit};
use std::{net::SocketAddr, process::exit, time::Duration};
use anyhow::{Context, Result};
use azalea::{
@ -10,7 +10,7 @@ use hyper_util::rt::TokioIo;
use log::{debug, error, info, trace};
use mlua::{Error, Function, IntoLuaMulti, Table};
use ncr::utils::trim_header;
use tokio::net::TcpListener;
use tokio::{net::TcpListener, time::sleep};
#[cfg(feature = "matrix")]
use crate::matrix;
@ -284,8 +284,12 @@ fn matrix_init(client: &Client, state: State) {
if let Ok(options) = globals.get::<Table>("MatrixOptions") {
let name = client.username();
tokio::spawn(async move {
if let Err(error) = matrix::login(state, options, globals, name).await {
error!("failed to log into matrix account: {error:?}");
loop {
let name = name.clone();
if let Err(error) = matrix::login(&state, &options, &globals, name).await {
error!("failed to log into matrix: {error:?}");
}
sleep(Duration::from_secs(10)).await;
}
});
}

View File

@ -99,10 +99,7 @@ pub async fn on_stripped_state_member(
{
debug!("joining room {}", room.room_id());
while let Err(error) = room.join().await {
error!(
"failed to join room {}: {error:?}, retrying...",
room.room_id()
);
error!("failed to join room {}: {error:?}", room.room_id());
sleep(Duration::from_secs(10)).await;
}
debug!("successfully joined room {}", room.room_id());

View File

@ -56,7 +56,7 @@ async fn persist_sync_token(
Ok(())
}
pub async fn login(state: State, options: Table, globals: Table, name: String) -> Result<()> {
pub async fn login(state: &State, options: &Table, globals: &Table, name: String) -> Result<()> {
let (homeserver_url, username, password) = (
options.get::<String>("homeserver_url")?,
options.get::<String>("username")?,
@ -106,7 +106,10 @@ pub async fn login(state: State, options: Table, globals: Table, name: String) -
fs::write(&session_file, serde_json::to_string(&new_session)?).await?;
}
client.add_event_handler_context(Context { state, name });
client.add_event_handler_context(Context {
state: state.to_owned(),
name,
});
client.add_event_handler(on_stripped_state_member);
loop {
match client.sync_once(sync_settings.clone()).await {