-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
67 lines (56 loc) · 1.38 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
package main
import (
"net/http"
"os"
"github.com/Postcord/interactions"
"github.com/SocialFeedsBot/interactions/commands"
"github.com/SocialFeedsBot/interactions/internal/gateway"
"github.com/SocialFeedsBot/interactions/internal/logger"
"github.com/go-redis/redis/v8"
env "github.com/joho/godotenv"
"github.com/sirupsen/logrus"
)
func main() {
logger.Format()
// Load config
if os.Getenv("DEV") == "true" {
logrus.Debug("Running in development environment")
e := env.Load(".env.dev")
if e != nil {
logrus.Error(e)
return
}
} else {
logrus.Debug("Running in production environment")
e := env.Load()
if e != nil {
logrus.Error(e)
return
}
}
gateway := gateway.Gateway{
Address: os.Getenv("GATEWAY_ADDRESS"),
Secret: os.Getenv("GATEWAY_SECRET"),
}
app, err := interactions.New(&interactions.Config{
PublicKey: os.Getenv("PUBLIC_KEY"),
Token: "Bot " + os.Getenv("TOKEN"),
})
if err != nil {
logrus.Error(err)
return
}
redis := redis.NewClient(&redis.Options{
Addr: os.Getenv("REDIS_URL"),
Password: os.Getenv("REDIS_PASS"),
DB: 2,
})
session := gateway.CreateSession()
go commands.RegisterCommands(app, redis, session)
logrus.Infof("Starting on %s", os.Getenv("PORT"))
if err := http.ListenAndServe(os.Getenv("PORT"), app.HTTPHandler()); err != nil {
logrus.Fatal(err)
}
// Shutdown
logrus.Info("Shutting down")
}