Add a loop to Matrix login

This commit is contained in:
ErrorNoInternet 2023-01-29 13:59:18 +08:00
parent 2e229b70d9
commit 70108247d4
Signed by untrusted user who does not match committer: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
2 changed files with 64 additions and 62 deletions

View File

@ -126,6 +126,7 @@ async fn main() {
let matrix_configuration = bot_configuration.matrix.to_owned(); let matrix_configuration = bot_configuration.matrix.to_owned();
if matrix_configuration.enabled { if matrix_configuration.enabled {
log_message(Matrix, &"Matrix is enabled! Logging in...".to_string());
tokio::spawn(login_and_sync(matrix_configuration, state.clone())); tokio::spawn(login_and_sync(matrix_configuration, state.clone()));
} }

View File

@ -16,7 +16,7 @@ struct MatrixState {
} }
pub async fn login_and_sync(matrix_configuration: MatrixConfiguration, bot_state: Arc<State>) { pub async fn login_and_sync(matrix_configuration: MatrixConfiguration, bot_state: Arc<State>) {
log_message(Matrix, &"Matrix is enabled! Logging in...".to_string()); loop {
let client_builder = let client_builder =
matrix_sdk::Client::builder().homeserver_url(&matrix_configuration.homeserver_url); matrix_sdk::Client::builder().homeserver_url(&matrix_configuration.homeserver_url);
let client = match client_builder.build().await { let client = match client_builder.build().await {
@ -67,7 +67,7 @@ pub async fn login_and_sync(matrix_configuration: MatrixConfiguration, bot_state
&format!("Successfully logged in as {}!", display_name), &format!("Successfully logged in as {}!", display_name),
); );
let matrix_state = MatrixState { let matrix_state = MatrixState {
bot_state, bot_state: bot_state.clone(),
matrix_configuration: matrix_configuration.clone(), matrix_configuration: matrix_configuration.clone(),
display_name, display_name,
}; };
@ -78,6 +78,7 @@ pub async fn login_and_sync(matrix_configuration: MatrixConfiguration, bot_state
Ok(_) => (), Ok(_) => (),
Err(error) => log_message(MatrixError, &format!("Unable to synchronize: {}", error)), Err(error) => log_message(MatrixError, &format!("Unable to synchronize: {}", error)),
}; };
}
} }
async fn room_message_handler( async fn room_message_handler(