diff --git a/src/bot.rs b/src/bot.rs index aa97d32..d48801e 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -100,11 +100,18 @@ impl BadNewsBot { const KEY_MESSAGE: &str = "MESSAGE"; if let Some(unit) = record.get(KEY_UNIT) { - if !self.config.units.iter().map(|u| &u.name).any(|name| name == unit) { - return; - } + let unit_config = match self.config.units.iter().find(|u| &u.name == unit) { + Some(config) => config, + None => return, + }; let message = record.get(KEY_MESSAGE); + if let Some(filter) = &unit_config.filter { + if message.is_none() || !filter.is_match(message.unwrap()) { + return; + } + } + let message = format!( "[{}] {}", unit.strip_suffix(".service").unwrap_or(unit), diff --git a/src/config.rs b/src/config.rs index 0a4e40b..ffa367b 100644 --- a/src/config.rs +++ b/src/config.rs @@ -24,12 +24,12 @@ pub struct Config { /// invitations to this room. pub room_id: RoomId, /// Units to watch for logs + #[serde(deserialize_with = "list_of_units")] pub units: Vec, } /// Holds a single unit's configuration. #[derive(Clone, Debug, Deserialize)] -#[serde(from = "SerializedUnit")] pub struct Unit { /// Can be serialized from a string only instead of a map. pub name: String, @@ -67,6 +67,14 @@ impl FromStr for Unit { } } +fn list_of_units<'de, D>(deserializer: D) -> Result, D::Error> +where + D: Deserializer<'de>, +{ + let units: Vec = Deserialize::deserialize(deserializer)?; + Ok(units.into_iter().map(From::from).collect()) +} + fn unit_name_or_struct<'de, T, D>(deserializer: D) -> Result where T: Deserialize<'de> + FromStr,