-
Notifications
You must be signed in to change notification settings - Fork 2
/
main.go
46 lines (39 loc) · 962 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
package main
import (
"log"
"os"
"os/signal"
"syscall"
"github.com/bwmarrin/discordgo"
"github.com/zeroidentidad/gopherbot/botservice/messages"
"github.com/zeroidentidad/gopherbot/global"
"github.com/zeroidentidad/gopherbot/webservice"
"github.com/zeroidentidad/gopherbot/webservice/storage"
)
func main() {
dg, err := discordgo.New("Bot " + global.TOKEN)
if err != nil {
log.Fatal("Session error:", err.Error())
return
}
// dg.Debug = true
// Register bot handlers.
dg.AddHandler(messages.MessageCmd)
dg.AddHandler(messages.SetStatus)
err = dg.Open()
if err != nil {
log.Fatal("Websocket error,", err.Error())
return
}
// Register web handlers.
go func() {
storage.Migrate()
webservice.Start(global.Port())
}()
// Until CTRL-C or another term signal.
log.Println("Bot running. Press CTRL-C to exit.")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt)
<-sc
dg.Close()
}