From 4145ba8a1caccec6a62ae40acca916a34e87ff09 Mon Sep 17 00:00:00 2001 From: Mike Dilger Date: Fri, 20 Sep 2024 12:04:13 +1200 Subject: [PATCH] Send tags into spam filter --- filter.example.rhai | 5 +++-- gossip-lib/src/spam_filter.rs | 8 +++++++- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/filter.example.rhai b/filter.example.rhai index 2bfdd195..b5f6abe5 100644 --- a/filter.example.rhai +++ b/filter.example.rhai @@ -29,16 +29,17 @@ // caller - a string that is one of "Process", "Thread", // "Inbox" or "Global" indicating which part of // the code is running your script -// content - the event content as a string // id - the event ID, as a hex string +// pubkey - the event author public key, as a hex string // kind - the event kind as an integer +// tags - the event tags (array of array of strings) +// content - the event content as a string // muted - if the author is in your mute list // name - if we have it, the name of the author (or your // petname), else an empty string // nip05valid - whether nip05 is valid for the author, as a // boolean // pow - the Proof of Work on the event -// pubkey - the event author public key, as a hex string // seconds_known - the number of seconds that the author of the // event has been known to gossip // spamsafe - true only if the event came in from a relay diff --git a/gossip-lib/src/spam_filter.rs b/gossip-lib/src/spam_filter.rs index e7c420e5..98b592d4 100644 --- a/gossip-lib/src/spam_filter.rs +++ b/gossip-lib/src/spam_filter.rs @@ -2,7 +2,7 @@ use crate::globals::GLOBALS; use crate::people::PersonList; use crate::profile::Profile; use crate::storage::{PersonTable, Table}; -use nostr_types::{Event, EventKind, Id, PublicKey, Unixtime}; +use nostr_types::{Event, EventKind, Id, PublicKey, Tag, Unixtime}; use rhai::{CallFnOptions, Engine, Scope, AST}; use std::fs; @@ -68,6 +68,7 @@ pub fn filter_event(event: Event, caller: EventFilterCaller, spamsafe: bool) -> rumor.pubkey, rumor.kind, rumor.content, + rumor.tags, pow, caller, spamsafe, @@ -81,6 +82,7 @@ pub fn filter_event(event: Event, caller: EventFilterCaller, spamsafe: bool) -> event.pubkey, event.kind, event.content, + event.tags, pow, caller, spamsafe, @@ -93,6 +95,7 @@ fn inner_filter( pubkey: PublicKey, kind: EventKind, content: String, + mut tags: Vec, pow: u8, caller: EventFilterCaller, spamsafe: bool, @@ -117,6 +120,8 @@ fn inner_filter( return EventFilterAction::Allow; } + let tags: Vec> = tags.drain(..).map(|t| t.into_inner()).collect(); + // NOTE numbers in rhai are i64 or f32 let mut scope = Scope::new(); scope @@ -124,6 +129,7 @@ fn inner_filter( .push_constant("pubkey", pubkey.as_hex_string()) .push_constant("kind", >::into(kind) as i64) .push_constant("content", content) + .push_constant("tags", tags) .push_constant( "nip05valid", match &author {