-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
88 lines (73 loc) · 1.93 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
package main
import (
"io"
"log"
"os"
"time"
"github.com/joho/godotenv"
skippy "skippybot/skippy"
openai "github.com/sashabaranov/go-openai"
)
const (
DEBOUNCE_DELAY = 100 * time.Millisecond
MIN_GAME_SESSION_DURATION = 10 * time.Minute
)
func main() {
// Create or open a file for logging
file, err := os.OpenFile("skippy.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0o666)
if err != nil {
log.Fatalf("Failed to open log file: %v", err)
}
defer file.Close()
log.SetFlags(log.Ltime | log.Lshortfile | log.Ldate)
log.Println("Initializing...")
// Create a multi-writer to write to both the file and stdout
mw := io.MultiWriter(file, os.Stdout)
log.SetOutput(mw)
err = godotenv.Load()
if err != nil {
log.Fatalln("Unable to load env variables")
}
openAIKey := os.Getenv("OPEN_AI_KEY")
if openAIKey == "" {
log.Fatalln("Unable to get Open AI API Key")
}
token := os.Getenv("DISCORD_TOKEN")
if token == "" {
log.Fatalln("could not read discord token")
}
assistantID := os.Getenv("ASSISTANT_ID")
if assistantID == "" {
log.Fatalln("could not read Assistant ID")
}
stockPriceAPIKey := os.Getenv("ALPHA_VANTAGE_API_KEY")
weatherAPIKey := os.Getenv("WEATHER_API_KEY")
clientConfig := openai.DefaultConfig(openAIKey)
clientConfig.AssistantVersion = "v2"
client := openai.NewClientWithConfig(clientConfig)
log.Println("Connecting to db")
db, err := skippy.NewDB("sqlite", "skippy.db")
if err != nil {
log.Fatalln("Unable to get database connection", err)
}
config := &skippy.Config{
PresenceUpdateDebouncDelay: DEBOUNCE_DELAY,
MinGameSessionDuration: MIN_GAME_SESSION_DURATION,
ReminderDurations: []time.Duration{
time.Minute * 10,
time.Minute * 30,
time.Minute * 90,
time.Hour * 3,
},
OpenAIModel: openai.GPT4o,
UserConfigMap: make(map[string]skippy.UserConfig),
}
skippy.RunDiscord(
token,
assistantID,
stockPriceAPIKey,
weatherAPIKey,
client,
config,
db)
}