Run Matrix commands in a task

This commit is contained in:
ErrorNoInternet 2023-02-23 17:47:14 +08:00
parent 04cd440c50
commit 771057925d
Signed by untrusted user who does not match committer: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3

View File

@ -97,7 +97,7 @@ async fn room_message_handler(
.contains(&event.sender.to_string()) .contains(&event.sender.to_string())
&& text_content.body.starts_with(&state.display_name) && text_content.body.starts_with(&state.display_name)
{ {
let bot_state = &state.bot_state; let bot_state = state.bot_state.clone();
let client = bot_state.client.lock().unwrap().to_owned(); let client = bot_state.client.lock().unwrap().to_owned();
let mut client = match client { let mut client = match client {
Some(client) => client, Some(client) => client,
@ -114,7 +114,7 @@ async fn room_message_handler(
return; return;
} }
}; };
let command = &text_content let command = text_content
.body .body
.trim_start_matches(&state.display_name) .trim_start_matches(&state.display_name)
.trim_start_matches(":") .trim_start_matches(":")
@ -128,21 +128,23 @@ async fn room_message_handler(
command command
), ),
); );
log_error( tokio::task::spawn(async move {
room.send( log_error(
RoomMessageEventContent::text_plain( room.send(
&crate::bot::process_command( RoomMessageEventContent::text_plain(
&command, &crate::bot::process_command(
&event.sender.to_string(), &command,
&mut client, &event.sender.to_string(),
bot_state.clone(), &mut client,
) bot_state.clone(),
.await, )
), .await,
None, ),
) None,
.await, )
); .await,
);
});
} }
} }
} }