@ -45,6 +45,13 @@ pub struct MessageDirectionFilter(pub MessageDirection);
|
|||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
pub struct TextFilter<'a>(pub &'a [&'a str], pub TextMatchMethod);
|
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)]
|
#[derive(Clone)]
|
||||||
pub struct OnlyFromId(pub i64);
|
pub struct OnlyFromId(pub i64);
|
||||||
|
|
||||||
@ -155,3 +162,9 @@ impl<'a> Filter for UpdateTypeFilter<'a> {
|
|||||||
Ok(false)
|
Ok(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: Filter + Clone> Filter for NotFilter<T> {
|
||||||
|
fn filter(&self, update: &Update) -> anyhow::Result<bool> {
|
||||||
|
Ok(!self.0.filter(update)?)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -11,8 +11,8 @@ use super::{
|
|||||||
filters::{
|
filters::{
|
||||||
filtered_handler::FilteredHandler,
|
filtered_handler::FilteredHandler,
|
||||||
message_fitlers::{
|
message_fitlers::{
|
||||||
ExcludedChatsFilter, MessageDirection, MessageDirectionFilter, OnlyFromId, RegexFilter,
|
ExcludedChatsFilter, MessageDirection, MessageDirectionFilter, NotFilter, OnlyFromId,
|
||||||
SilentFilter, TextFilter, TextMatchMethod, UpdateType, UpdateTypeFilter,
|
RegexFilter, SilentFilter, TextFilter, TextMatchMethod, UpdateType, UpdateTypeFilter,
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
handlers::{
|
handlers::{
|
||||||
@ -163,7 +163,12 @@ async fn run(args: BotConfig, client: Client) -> anyhow::Result<()> {
|
|||||||
.add_filter(ExcludedChatsFilter(args.excluded_chats.clone()))
|
.add_filter(ExcludedChatsFilter(args.excluded_chats.clone()))
|
||||||
.add_filter(UpdateTypeFilter(&[UpdateType::New]))
|
.add_filter(UpdateTypeFilter(&[UpdateType::New]))
|
||||||
.add_filter(SilentFilter)
|
.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.
|
// Notify all.
|
||||||
FilteredHandler::new(NotifyAll)
|
FilteredHandler::new(NotifyAll)
|
||||||
.add_filter(ExcludedChatsFilter(args.excluded_chats.clone()))
|
.add_filter(ExcludedChatsFilter(args.excluded_chats.clone()))
|
||||||
|
Reference in New Issue
Block a user