From 77c2a8906c0505b5e8a21f08d77282c89a08e2ce Mon Sep 17 00:00:00 2001 From: Daniel Saxton Date: Mon, 23 Sep 2024 21:23:51 -0500 Subject: [PATCH] ratelimit: make message configurable Changelog-Added: Make ratelimit message configurable Closes: https://github.com/damus-io/noteguard/pull/15 --- noteguard.toml | 1 + src/filters/ratelimit.rs | 7 ++++++- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/noteguard.toml b/noteguard.toml index d3445bd..467693c 100644 --- a/noteguard.toml +++ b/noteguard.toml @@ -4,6 +4,7 @@ pipeline = ["protected_events", "kinds", "content", "whitelist", "ratelimit"] [filters.ratelimit] posts_per_minute = 8 whitelist = ["127.0.0.1"] +message = "rate-limited: you note too much" [filters.content] filters = ["https://cdn.nostr.build/i/some-spammy-or-abusive-image-image.png"] diff --git a/src/filters/ratelimit.rs b/src/filters/ratelimit.rs index 4279f24..44cb514 100644 --- a/src/filters/ratelimit.rs +++ b/src/filters/ratelimit.rs @@ -12,6 +12,7 @@ pub struct Tokens { pub struct RateLimit { pub posts_per_minute: i32, pub whitelist: Option>, + pub message: Option, #[serde(skip)] pub sources: HashMap, @@ -65,7 +66,11 @@ impl NoteFilter for RateLimit { return OutputMessage::new( msg.event.id.clone(), Action::Reject, - Some("rate-limited: you are noting too much".to_string()), + Some( + self.message + .clone() + .unwrap_or("rate-limited: you are noting too much".to_string()), + ), ); }