summary refs log tree commit diff
diff options
context:
space:
mode:
authorAshelyn Rose <git@ashen.earth>2024-11-07 17:33:13 -0700
committerAshelyn Rose <git@ashen.earth>2024-11-07 17:33:13 -0700
commitba9362908d2defa784a45c16bc142c66c3fab9a3 (patch)
treeb27570c2b37fc6cb448dda27584818c48b4b158c
parentc6d21f541d511f095b4e0dfc1f5a47a98c9ee6e0 (diff)
don't crash on regex failing to parse
-rw-r--r--src/system/message_parser.rs17
1 files changed, 12 insertions, 5 deletions
diff --git a/src/system/message_parser.rs b/src/system/message_parser.rs
index 5c848e9..349ce0e 100644
--- a/src/system/message_parser.rs
+++ b/src/system/message_parser.rs
@@ -134,13 +134,20 @@ impl MessageParser {
                 _ => {return None;},
             }};
 
-            let regex = regex.build().unwrap();
-
+            let valid_regex = regex.build();
             let original_content = &secondary_message.as_ref().unwrap().content;
-            let new_content = if global {
-                regex.replace_all(original_content.as_str(), *replacement)
+
+            // If the regex parses, replace with that
+            let new_content = if let Ok(regex) = valid_regex {
+                if global {
+                    regex.replace_all(original_content.as_str(), *replacement).to_string()
+                } else {
+                    regex.replace(original_content.as_str(), *replacement).to_string()
+                }
+
+            // Else attempt replace as string
             } else {
-                regex.replace(original_content.as_str(), *replacement)
+                original_content.replace(pattern, replacement)
             };
 
             let editing_member = Self::get_member_id_from_user_id(secondary_message.as_ref().unwrap().author.id, system_config).unwrap();