-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
60 lines (48 loc) · 1.28 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
package main
import (
"flag"
"log"
"os"
"os/signal"
"syscall"
"f1-discord-bot/handlers"
dgo "github.com/bwmarrin/discordgo"
)
// BOT_TOKEN represents the discord authentication token
var BOT_TOKEN string
var session *dgo.Session
// Read in all configuration options from both environment variables and
// command line arguments.
func init() {
// Discord Authentication Token
BOT_TOKEN = os.Getenv("DISCORD_BOT_TOKEN")
if BOT_TOKEN == "" {
flag.StringVar(&BOT_TOKEN, "bot-token", "", "Discord Authentication Token")
}
flag.Parse()
}
func main() {
var err error
if BOT_TOKEN == "" {
log.Print("No bot token specified. Please specify one using the DISCORD_BOT_TOKEN environment variable or the -bot-token flag.")
return
}
session, err = dgo.New("Bot " + BOT_TOKEN)
if err != nil {
log.Printf("error getting new session: %v", err)
return
}
err = session.Open()
if err != nil {
log.Printf("error opening connection to Discord, %s\n", err)
return
}
defer session.Close()
session.UpdateGameStatus(0, "!f1 help")
session.AddHandler(handlers.CreateMessage)
// Wait for a CTRL-C
log.Printf("It's lights out and away we go! Bot now running. (CTRL-C to exit)")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc
}