feat(matrix): respond based on client username

This commit is contained in:
Ryan 2025-03-15 23:06:21 -04:00
parent ee82685b4e
commit c7358fd4c0
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
2 changed files with 5 additions and 4 deletions

View File

@ -1,4 +1,4 @@
use super::{COMMAND_PREFIX, MatrixContext}; use super::MatrixContext;
use crate::{ use crate::{
events::call_listeners, events::call_listeners,
lua::{self, matrix::room::Room as LuaRoom}, lua::{self, matrix::room::Room as LuaRoom},
@ -35,9 +35,9 @@ pub async fn on_regular_room_message(
.get::<Vec<String>>("MatrixOwners") .get::<Vec<String>>("MatrixOwners")
.unwrap_or_default() .unwrap_or_default()
.contains(&event.sender.to_string()) .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_start_matches(':')
.trim(); .trim();
let split = body.split_once(char::is_whitespace).unzip(); let split = body.split_once(char::is_whitespace).unzip();

View File

@ -17,6 +17,7 @@ use verification::{on_device_key_verification_request, on_room_message_verificat
#[derive(Clone)] #[derive(Clone)]
pub struct MatrixContext { pub struct MatrixContext {
state: State, state: State,
name: String,
} }
#[derive(Clone, Serialize, Deserialize)] #[derive(Clone, Serialize, Deserialize)]
@ -87,7 +88,7 @@ pub async fn login(
fs::write(&session_file, serde_json::to_string(&new_session)?).await?; 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); client.add_event_handler(on_stripped_state_member);
loop { loop {
match client.sync_once(sync_settings.clone()).await { match client.sync_once(sync_settings.clone()).await {