From 7d9dee7a4dcf7e2b41bee37d2aebaa6ef48a5ba2 Mon Sep 17 00:00:00 2001 From: Shayne Hartford Date: Mon, 11 Aug 2025 02:18:38 -0400 Subject: Improve System Chat Regex & Add System Whisper Regex (#233) * Refactor the system message regex to use a static RwLock for customization * Add customizable whisper regex for system messages * Remove global regex locks * Oops invalid unnamed capture format --- azalea-client/src/plugins/chat/mod.rs | 30 ++++++++++++++++++++++++------ 1 file changed, 24 insertions(+), 6 deletions(-) diff --git a/azalea-client/src/plugins/chat/mod.rs b/azalea-client/src/plugins/chat/mod.rs index 603dea60..2e98fdf8 100644 --- a/azalea-client/src/plugins/chat/mod.rs +++ b/azalea-client/src/plugins/chat/mod.rs @@ -63,13 +63,14 @@ impl ChatPacket { match self { ChatPacket::System(p) => { let message = p.content.to_string(); + // Overlay messages aren't in chat if p.overlay { return (None, message); } - // It's a system message, so we'll have to match the content - // with regex - if let Some(m) = regex!("^<([a-zA-Z_0-9]{1,16})> (.+)$").captures(&message) { + + // It's a system message, so we'll have to match the content with regex + if let Some(m) = regex!("^<([a-zA-Z_0-9]{1,16})> (?:-> me)?(.+)$").captures(&message) { return (Some(m[1].to_string()), m[2].to_string()); } @@ -128,9 +129,26 @@ impl ChatPacket { /// dm'd the bot with /msg). It works by checking the translation key, so it /// won't work on servers that use their own whisper system. pub fn is_whisper(&self) -> bool { - match self.message() { - FormattedText::Text(_) => false, - FormattedText::Translatable(t) => t.key == "commands.message.display.incoming", + match self { + ChatPacket::System(p) => { + let message = p.content.to_string(); + + // Overlay messages aren't in chat + if p.overlay { + return false; + } + + // It's a system message, so we'll have to match the content with regex + if let Some(m) = regex!("^(-> me)?(?:.+)$").captures(&message) { + return m.get(1).is_some(); + } + + false + } + _ => match self.message() { + FormattedText::Text(_) => false, + FormattedText::Translatable(t) => t.key == "commands.message.display.incoming", + }, } } } -- cgit v1.2.3