feat(matrix): respond based on client username
This commit is contained in:
parent
ee82685b4e
commit
c7358fd4c0
@ -1,4 +1,4 @@
|
||||
use super::{COMMAND_PREFIX, MatrixContext};
|
||||
use super::MatrixContext;
|
||||
use crate::{
|
||||
events::call_listeners,
|
||||
lua::{self, matrix::room::Room as LuaRoom},
|
||||
@ -35,9 +35,9 @@ pub async fn on_regular_room_message(
|
||||
.get::<Vec<String>>("MatrixOwners")
|
||||
.unwrap_or_default()
|
||||
.contains(&event.sender.to_string())
|
||||
&& text_content.body.starts_with(COMMAND_PREFIX)
|
||||
&& text_content.body.starts_with(&ctx.name)
|
||||
{
|
||||
let body = text_content.body[COMMAND_PREFIX.len()..]
|
||||
let body = text_content.body[ctx.name.len()..]
|
||||
.trim_start_matches(':')
|
||||
.trim();
|
||||
let split = body.split_once(char::is_whitespace).unzip();
|
||||
|
@ -17,6 +17,7 @@ use verification::{on_device_key_verification_request, on_room_message_verificat
|
||||
#[derive(Clone)]
|
||||
pub struct MatrixContext {
|
||||
state: State,
|
||||
name: String,
|
||||
}
|
||||
|
||||
#[derive(Clone, Serialize, Deserialize)]
|
||||
@ -87,7 +88,7 @@ pub async fn login(
|
||||
fs::write(&session_file, serde_json::to_string(&new_session)?).await?;
|
||||
}
|
||||
|
||||
client.add_event_handler_context(MatrixContext { state });
|
||||
client.add_event_handler_context(MatrixContext { state, name });
|
||||
client.add_event_handler(on_stripped_state_member);
|
||||
loop {
|
||||
match client.sync_once(sync_settings.clone()).await {
|
||||
|
Loading…
x
Reference in New Issue
Block a user