-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
50 lines (38 loc) · 964 Bytes
/
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
package main
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/ReeceDonovan/uni-bot/config"
"github.com/ReeceDonovan/uni-bot/handlers"
"github.com/ReeceDonovan/uni-bot/models"
"github.com/bwmarrin/discordgo"
"github.com/spf13/viper"
)
func main() {
exitError(config.InitConfig())
models.InitModels()
// Discord connection
token := viper.GetString("discord.token")
session, err := discordgo.New("Bot " + token)
session.Identify.Intents = discordgo.MakeIntent(discordgo.IntentsAll)
exitError(err)
// Add handlers
handlers.RegisterHandlers(session)
// Open websocket
err = session.Open()
exitError(err)
defer session.Close()
log.Println("Bot is Running")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
log.Println("Exiting")
// TODO: Cleanup commands on shutdown?
}
func exitError(err error) {
if err != nil {
log.Fatalf("Failed to start bot: %v", err)
}
}