-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
50 lines (41 loc) · 838 Bytes
/
main.go
File metadata and controls
50 lines (41 loc) · 838 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
47
48
49
50
package main
import (
"fmt"
"os"
"os/signal"
"runtime"
"syscall"
dg "github.com/bwmarrin/discordgo"
)
var helpcommand = "$gamehelp"
func main() {
runtime.GOMAXPROCS(2)
if err := readJSON(&cfg, "config.json"); err != nil {
return
}
if err := readJSON(&mem, "memory.json"); err != nil {
return
}
commandSetup()
defer writeJSON(&mem, "memory.json")
session, err := dg.New(cfg["BotID"])
if err != nil {
fmt.Println(err)
return
}
defer session.Close()
if err = session.Open(); err != nil {
fmt.Println(err)
return
}
session.AddHandler(newMessage)
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, syscall.SIGSEGV, syscall.SIGHUP)
fmt.Println("Setup Complete")
<-sc
}
func newMessage(s *dg.Session, m *dg.MessageCreate) {
if !m.Author.Bot {
parseCommand(s, m)
}
}