-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
46 lines (37 loc) · 911 Bytes
/
main.go
File metadata and controls
46 lines (37 loc) · 911 Bytes
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
package main
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/ProjectCeleste/faq-bot/internal/bot"
)
const (
exitMissingToken = 1
exitConnectError = 2
exitCloseError = 3
)
func main() {
logger := log.New(os.Stdout, "", log.LstdFlags)
errLogger := log.New(os.Stderr, "", log.LstdFlags)
token, ok := os.LookupEnv("TOKEN")
if !ok {
errLogger.Println("Missing TOKEN env variable")
os.Exit(exitMissingToken)
}
bot := bot.NewFAQBot()
if err := bot.Connect(token); err != nil {
errLogger.Println(err)
os.Exit(exitConnectError)
}
// Wait here until CTRL-C or other term signal is received.
logger.Println("FAQ-Bot is running. Press CTRL-C to exit.")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM)
<-sc
// Cleanly close down the Discord session.
if err := bot.Close(); err != nil {
errLogger.Println(err)
os.Exit(exitCloseError)
}
}