From 0ad33f78f15efcc61610629ddd58348d6a3c792a Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Sat, 4 Nov 2023 18:21:26 -0300 Subject: [PATCH] PreventTimestampsInThePast() and PreventTimestampsInTheFuture() helpers. --- plugins/events.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/plugins/events.go b/plugins/events.go index 1c6e748..e997891 100644 --- a/plugins/events.go +++ b/plugins/events.go @@ -56,3 +56,21 @@ func RestrictToSpecifiedKinds(kinds ...uint16) func(context.Context, *nostr.Even return true, "event kind not allowed" } } + +func PreventTimestampsInThePast(thresholdSeconds nostr.Timestamp) func(context.Context, *nostr.Event) (bool, string) { + return func(ctx context.Context, event *nostr.Event) (reject bool, msg string) { + if nostr.Now()-event.CreatedAt > thresholdSeconds { + return true, "event too old" + } + return false, "" + } +} + +func PreventTimestampsInTheFuture(thresholdSeconds nostr.Timestamp) func(context.Context, *nostr.Event) (bool, string) { + return func(ctx context.Context, event *nostr.Event) (reject bool, msg string) { + if event.CreatedAt-nostr.Now() > thresholdSeconds { + return true, "event too much in the future" + } + return false, "" + } +}