bot: don't bother processing empty messages

This commit is contained in:
Antoine Martin 2021-04-10 02:17:10 +02:00
parent 87604b38d3
commit 1e1dff9ab0

View file

@ -105,9 +105,13 @@ impl BadNewsBot {
None => return, 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 let Some(filter) = &unit_config.filter {
if message.is_none() || !filter.is_match(message.unwrap()) { if !filter.is_match(message) {
return; return;
} }
} }
@ -115,7 +119,7 @@ impl BadNewsBot {
let message = format!( let message = format!(
"[{}] {}", "[{}] {}",
unit.strip_suffix(".service").unwrap_or(unit), unit.strip_suffix(".service").unwrap_or(unit),
message.map(|m| m.as_ref()).unwrap_or("<EMPTY MESSAGE>") message,
); );
let content = AnyMessageEventContent::RoomMessage(MessageEventContent::Text( let content = AnyMessageEventContent::RoomMessage(MessageEventContent::Text(
TextMessageEventContent::plain(message), TextMessageEventContent::plain(message),