filter: add content filter

Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
William Casarin 2024-07-29 23:56:17 -05:00
parent 8e1bb0363f
commit cae0393ed0
5 changed files with 77 additions and 20 deletions

23
src/filters/content.rs Normal file
View file

@ -0,0 +1,23 @@
use crate::{Action, InputMessage, NoteFilter, OutputMessage};
use serde::Deserialize;
#[derive(Deserialize, Default)]
pub struct Content {
filters: Vec<String>,
}
impl NoteFilter for Content {
fn filter_note(&mut self, msg: &InputMessage) -> OutputMessage {
for filter in &self.filters {
if msg.event.content.contains(filter) {
return OutputMessage::new(msg.event.id.clone(), Action::ShadowReject, None);
}
}
OutputMessage::new(msg.event.id.clone(), Action::Accept, None)
}
fn name(&self) -> &'static str {
"content"
}
}

View file

@ -1,3 +1,4 @@
mod content;
mod kinds;
mod protected_events;
mod ratelimit;
@ -6,6 +7,7 @@ mod whitelist;
#[cfg(feature = "forwarder")]
mod forwarder;
pub use content::Content;
pub use kinds::Kinds;
pub use protected_events::ProtectedEvents;
pub use ratelimit::RateLimit;