@ -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)?)
|
||||
}
|
||||
}
|
||||
|
@ -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()))
|
||||
|
Reference in New Issue
Block a user