-
-
Notifications
You must be signed in to change notification settings - Fork 23
/
main.go
58 lines (44 loc) · 1.13 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
package main
import (
"fmt"
"log"
"net/http"
"os"
"os/signal"
"sync"
_ "time/tzdata"
"github.com/bwmarrin/discordgo"
"github.com/senchabot-opensource/monorepo/apps/discord-bot/internal/handler"
"github.com/senchabot-opensource/monorepo/apps/discord-bot/internal/service"
twsrvc "github.com/senchabot-opensource/monorepo/packages/gosenchabot/service/twitch"
)
func main() {
token := twsrvc.InitTwitchOAuth2Token()
discordClient, _ := discordgo.New("Bot " + os.Getenv("TOKEN"))
var wg sync.WaitGroup
service := service.New()
handler := handler.New(discordClient, service)
handler.InitBotEventHandlers(token)
go func() {
err := discordClient.Open()
if err != nil {
log.Fatal("Cannot open the session: ", err)
}
defer discordClient.Close()
stop := make(chan os.Signal, 1)
signal.Notify(stop, os.Interrupt)
<-stop
wg.Done()
log.Println("Graceful shutdown")
}()
go func() {
fmt.Println("Starting HTTP server...")
mux := http.NewServeMux()
handler.InitHttpHandlers(mux)
error := http.ListenAndServe(":8080", mux)
if error != nil {
log.Fatal("ListenAndServe Error:", error)
}
}()
select {}
}