forked from npub1337/nostr-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
63 lines (52 loc) · 1.2 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package main
import (
"log"
"os"
"path/filepath"
"time"
"nostr-bot/config"
"nostr-bot/internal/bot"
"nostr-bot/internal/database"
)
func main() {
log.SetFlags(log.Ldate | log.Ltime | log.Lshortfile)
log.Println("Starting Nostr Bot...")
cfg, err := config.Load()
if err != nil {
log.Fatal("Error loading config:", err)
}
log.Printf("Loaded configuration: %d bots configured", len(cfg.Bots))
os.MkdirAll(filepath.Dir(cfg.DatabasePath), 0755)
db, err := database.InitDB(cfg.DatabasePath)
if err != nil {
log.Fatal("Error initializing database:", err)
}
defer db.Close()
bots := make([]*bot.Bot, 0, len(cfg.Bots))
for _, botConfig := range cfg.Bots {
log.Printf("Initializing bot: %s", botConfig.Name)
b, err := bot.NewBot(
botConfig.Name,
botConfig.NostrPrivateKey,
cfg.RelayURL,
botConfig.RSSFeeds,
db,
botConfig.Timeout,
)
if err != nil {
log.Printf("Error initializing bot %s: %v", botConfig.Name, err)
continue
}
bots = append(bots, b)
}
log.Printf("All bots initialized. Running...")
ticker := time.NewTicker(5 * time.Second)
defer ticker.Stop()
for {
for _, b := range bots {
log.Printf("Running bot: %s", b.Name)
b.Run()
}
<-ticker.C
}
}