From 1e1dff9ab01c937cddf358a5b595e733831ff758 Mon Sep 17 00:00:00 2001 From: Antoine Martin Date: Sat, 10 Apr 2021 02:17:10 +0200 Subject: [PATCH] bot: don't bother processing empty messages --- src/bot.rs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/bot.rs b/src/bot.rs index d48801e..f95a07c 100644 --- a/src/bot.rs +++ b/src/bot.rs @@ -105,9 +105,13 @@ impl BadNewsBot { None => return, }; - let message = record.get(KEY_MESSAGE); + let message = match record.get(KEY_MESSAGE) { + Some(msg) => msg, + None => return, + }; + if let Some(filter) = &unit_config.filter { - if message.is_none() || !filter.is_match(message.unwrap()) { + if !filter.is_match(message) { return; } } @@ -115,7 +119,7 @@ impl BadNewsBot { let message = format!( "[{}] {}", unit.strip_suffix(".service").unwrap_or(unit), - message.map(|m| m.as_ref()).unwrap_or("") + message, ); let content = AnyMessageEventContent::RoomMessage(MessageEventContent::Text( TextMessageEventContent::plain(message),