filter: add kind blacklist filter
Signed-off-by: William Casarin <jb55@jb55.com>
This commit is contained in:
parent
f08e805673
commit
c85f9cbc3d
5 changed files with 74 additions and 5 deletions
29
src/filters/kinds.rs
Normal file
29
src/filters/kinds.rs
Normal file
|
|
@ -0,0 +1,29 @@
|
|||
use crate::{Action, InputMessage, NoteFilter, OutputMessage};
|
||||
use serde::Deserialize;
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
pub struct Kinds {
|
||||
kinds: Vec<i64>,
|
||||
messages: Option<HashMap<String, String>>,
|
||||
}
|
||||
|
||||
impl NoteFilter for Kinds {
|
||||
fn filter_note(&mut self, input: &InputMessage) -> OutputMessage {
|
||||
let kind = input.event.kind;
|
||||
if self.kinds.contains(&kind) {
|
||||
let msg = self
|
||||
.messages
|
||||
.as_ref()
|
||||
.and_then(|msgs| msgs.get(&kind.to_string()).cloned())
|
||||
.unwrap_or_else(|| "blocked: note kind is not allowed here".to_string());
|
||||
OutputMessage::new(input.event.id.clone(), Action::Reject, Some(msg))
|
||||
} else {
|
||||
OutputMessage::new(input.event.id.clone(), Action::Accept, None)
|
||||
}
|
||||
}
|
||||
|
||||
fn name(&self) -> &'static str {
|
||||
"kinds"
|
||||
}
|
||||
}
|
||||
|
|
@ -1,7 +1,9 @@
|
|||
mod kinds;
|
||||
mod protected_events;
|
||||
mod ratelimit;
|
||||
mod whitelist;
|
||||
|
||||
pub use kinds::Kinds;
|
||||
pub use protected_events::ProtectedEvents;
|
||||
pub use ratelimit::RateLimit;
|
||||
pub use whitelist::Whitelist;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue