-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
92 lines (73 loc) · 2.09 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package main
import (
"context"
"log"
"strings"
"time"
"github.com/gbl08ma/keybox"
"github.com/palantir/stacktrace"
"github.com/underlx/disturbancesbsky/underlxclient"
)
func main() {
ctx := context.Background()
log.Println("Starting, opening keybox...")
secrets, err := keybox.Open("secrets.json")
if err != nil {
log.Fatalln(stacktrace.Propagate(err, ""))
}
log.Println("Keybox opened")
underlxEndpoint, ok := secrets.Get("underlxEndpoint")
if !ok {
log.Fatalln("underlxEndpoint secret not found in keybox")
}
bskyBox, ok := secrets.GetBox("bsky")
if !ok {
log.Fatalln("bsky box not found in keybox")
}
bskyEndpoint, ok := bskyBox.Get("endpoint")
if !ok {
log.Fatalln("endpoint secret not found in bsky keybox")
}
bskyHandle, ok := bskyBox.Get("handle")
if !ok {
log.Fatalln("handle secret not found in bsky keybox")
}
bskyAppPassword, ok := bskyBox.Get("password")
if !ok {
log.Fatalln("password secret not found in bsky keybox")
}
underlxClient, err := underlxclient.NewClientWithResponses(underlxEndpoint)
if err != nil {
panic(stacktrace.Propagate(err, ""))
}
bskyClient := NewBskyClient(ctx, bskyEndpoint, bskyHandle, bskyAppPassword)
err = bskyClient.Connect(ctx)
if err != nil {
panic(stacktrace.Propagate(err, ""))
}
storageFilename, ok := secrets.Get("storageFilename")
if !ok {
log.Fatalln("storageFilename secret not found in keybox")
}
storage := NewBotStorage(storageFilename)
messageTimezone, ok := secrets.Get("messageTimezone")
if !ok {
log.Fatalln("messageTimezone secret not found in keybox")
}
location := time.FixedZone(messageTimezone, 0)
websiteLinkTemplate, ok := secrets.Get("websiteLinkTemplate")
if !ok {
log.Fatalln("websiteLinkTemplate secret not found in keybox")
}
postLangs, ok := secrets.Get("postLangs")
if !ok {
log.Fatalln("postLangs secret not found in keybox")
}
bot := NewBot(underlxClient, bskyClient, storage, location, websiteLinkTemplate, strings.Split(postLangs, ","))
for {
err = bot.Run(ctx, 10*time.Second, 2*time.Minute)
if err != nil {
log.Println(stacktrace.Propagate(err, ""))
}
}
}