diff --git a/src/bot/filters/message_fitlers.rs b/src/bot/filters/message_fitlers.rs index f5d82d78b3b52f7521d4c16023a83cc7715c93b1..71140ad692805a4b0005a800f7a846272becfe3d 100644 --- a/src/bot/filters/message_fitlers.rs +++ b/src/bot/filters/message_fitlers.rs @@ -45,6 +45,13 @@ pub struct MessageDirectionFilter(pub MessageDirection); #[derive(Clone)] pub struct TextFilter<'a>(pub &'a [&'a str], pub TextMatchMethod); +/// Filters text by predicate. +#[derive(Clone)] +pub struct ReverseTextFilter<'a>(pub &'a [&'a str], pub TextMatchMethod); + +#[derive(Clone)] +pub struct NotFilter<T: Filter + Clone>(pub T); + #[derive(Clone)] pub struct OnlyFromId(pub i64); @@ -155,3 +162,9 @@ impl<'a> Filter for UpdateTypeFilter<'a> { Ok(false) } } + +impl<T: Filter + Clone> Filter for NotFilter<T> { + fn filter(&self, update: &Update) -> anyhow::Result<bool> { + Ok(!self.0.filter(update)?) + } +} diff --git a/src/bot/main.rs b/src/bot/main.rs index 1af6d50c210db8dd221a857335416e3a6be6e646..fa85274572ca5603dc05cfa498e9009aa2d24230 100644 --- a/src/bot/main.rs +++ b/src/bot/main.rs @@ -11,8 +11,8 @@ use super::{ filters::{ filtered_handler::FilteredHandler, message_fitlers::{ - ExcludedChatsFilter, MessageDirection, MessageDirectionFilter, OnlyFromId, RegexFilter, - SilentFilter, TextFilter, TextMatchMethod, UpdateType, UpdateTypeFilter, + ExcludedChatsFilter, MessageDirection, MessageDirectionFilter, NotFilter, OnlyFromId, + RegexFilter, SilentFilter, TextFilter, TextMatchMethod, UpdateType, UpdateTypeFilter, }, }, handlers::{ @@ -163,7 +163,12 @@ async fn run(args: BotConfig, client: Client) -> anyhow::Result<()> { .add_filter(ExcludedChatsFilter(args.excluded_chats.clone())) .add_filter(UpdateTypeFilter(&[UpdateType::New])) .add_filter(SilentFilter) - .add_filter(TextFilter(&[".c"], TextMatchMethod::StartsWith)), + .add_filter(TextFilter(&[".c"], TextMatchMethod::StartsWith)) + .add_filter(NotFilter(TextFilter( + &[".cid"], + TextMatchMethod::StartsWith, + ))), + // .add_filter(TextFilter(&[".cid"], TextMatchMethod::)), // Notify all. FilteredHandler::new(NotifyAll) .add_filter(ExcludedChatsFilter(args.excluded_chats.clone()))