summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/config.rs26
-rw-r--r--src/system.rs8
2 files changed, 22 insertions, 12 deletions
diff --git a/src/config.rs b/src/config.rs
index 794e477..27911ea 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -1,7 +1,7 @@
 use std::collections::HashMap;
 
-use regex::Regex;
-use serde::Deserialize;
+use regex::{Regex, RegexBuilder};
+use serde::{Deserialize, Deserializer, de::Error};
 
 #[derive(Deserialize)]
 pub enum AutoProxyScope {
@@ -40,7 +40,7 @@ pub enum AutoproxyLatchScope {
 
 #[derive(Deserialize, Clone)]
 pub struct PluralkitConfig {
-    #[serde(with = "serde_regex")]
+    #[serde(deserialize_with = "parse_regex")]
     pub message_pattern: Regex,
     pub api_token: String,
 }
@@ -64,7 +64,7 @@ pub type MemberName = String;
 #[derive(Deserialize, Clone)]
 pub struct Member {
     pub name: MemberName,
-    #[serde(with = "serde_regex")]
+    #[serde(deserialize_with = "parse_regex")]
     pub message_pattern: Regex,
     pub discord_token: String,
     pub presence: Option<PresenceMode>,
@@ -99,3 +99,21 @@ impl Config {
         return config
     }
 }
+
+fn parse_regex<'de, D: Deserializer<'de>> (deserializer: D) -> Result<Regex, D::Error> {
+    let mut pattern = String::deserialize(deserializer)?;
+
+    if !pattern.starts_with("^") {
+        pattern.insert(0, '^');
+    }
+
+    if !pattern.ends_with("$") {
+        pattern.push('$');
+    }
+
+    RegexBuilder::new(&pattern)
+        .multi_line(true)
+        .case_insensitive(true)
+        .build()
+        .map_err(|e| D::Error::custom(e))
+}
diff --git a/src/system.rs b/src/system.rs
index 6aebf39..fa44946 100644
--- a/src/system.rs
+++ b/src/system.rs
@@ -74,8 +74,6 @@ impl System {
                                 println!("Autoproxy timeout has expired: {} (last sent), {} (timeout scheduled)", current_last_message.as_secs(), last_message.as_secs());
                                 self.latch_state = None;
                                 self.update_status_of_system();
-                            } else {
-                                println!("Autoproxy timeout called but not expired: {} (last sent), {} (timeout scheduled)", current_last_message.as_secs(), last_message.as_secs());
                             }
                         }
                     },
@@ -278,12 +276,6 @@ impl crate::config::Member {
         match self.message_pattern.captures(message.content.as_str()) {
             None => None,
             Some(captures) => {
-                let full_match = captures.get(0).unwrap();
-
-                if full_match.len() != message.content.len() {
-                    return None
-                }
-
                 match captures.name("content") {
                     None => None,
                     Some(matched_content) => Some(matched_content.as_str()),