From 1e1ca5d5ac42b250fd9bed826b8e1618c4aceb20 Mon Sep 17 00:00:00 2001 From: Iru Sensei Date: Sun, 23 Nov 2025 19:15:10 +0100 Subject: [PATCH] add modules --- nostr.go | 46 ++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 nostr.go diff --git a/nostr.go b/nostr.go new file mode 100644 index 0000000..88e5e02 --- /dev/null +++ b/nostr.go @@ -0,0 +1,46 @@ +package main + +import ( + "context" + "fiatjaf.com/nostr" + "log" + "time" +) + +func sendAlerts(config Config, alert string) error { + + pool := nostr.NewPool(nostr.PoolOptions{ + PenaltyBox: true, + }) + for _, relayurl := range config.Relays { + if !nostr.IsValidRelayURL(relayurl) { + log.Fatalf("%s is not a valid relay URL.") + } + relay, err := pool.EnsureRelay(relayurl) + check(err) + log.Printf("Connected to relay: %s", relay.URL) + } + event := &nostr.Event{ + CreatedAt: nostr.Now(), + Kind: nostr.KindTextNote, + Tags: nostr.Tags{}, + Content: alert, + } + + event.Sign(config.SecretKey) + ctx, cancel := context.WithTimeout(context.Background(), 15*time.Second) + defer cancel() + results := pool.PublishMany(ctx, config.Relays, *event) + + successCount := 0 + for result := range results { + if result.Error != nil { + log.Printf("Failed on %s: %v\n", result.RelayURL, result.Error) + } else { + log.Printf("Succeeded on %s\n", result.RelayURL) + successCount++ + } + } + + return nil +}