-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
69 lines (57 loc) · 1.53 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
61
62
63
64
65
66
67
68
package main
import (
"./cmd"
"./config"
"fmt"
"github.com/bwmarrin/discordgo"
"io/ioutil"
"os"
"os/signal"
"syscall"
)
func main() {
/*
TODO:
- Merge progress / prolab
- add writeup
- Add new roles when connecting
- remove user from users.json when he leaves discord (it breaks user.mention())
- modify PrintBoxInfo to get box name as parameter, so we can print it in the Shoutbox function
- see https://github.com/bwmarrin/discordgo/wiki/FAQ#sending-embeds
- add challs in progress
- add roles
- add retired challs
*/
// Create json files if doesn't exist
files := []string{"users", "challs", "boxes", "progress", "ippsec"}
for _, f := range files{
_, err := ioutil.ReadFile(f + ".json")
if err != nil{
ioutil.WriteFile(f + ".json", nil, 0644)
}
}
// Discord Bot
bot, err := discordgo.New("Bot " + config.Discord.Token)
if err != nil {
panic(err.Error())
}
// Register handlers
bot.AddHandler(cmd.Ready)
bot.AddHandler(cmd.CommandHandler)
bot.AddHandler(cmd.ReactionsHandler)
// Open a websocket connection to Discord and begin listening.
err = bot.Open()
defer bot.Close()
if err != nil {
fmt.Println("Could not connect to discord", err)
return
}
// Wait here until CTRL-C or other term signal is received.
fmt.Println("Discord bot is now running. Press CTRL-C to exit.")
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-sc
// Cleanly close down the Discord session.
fmt.Println("Closing connection")
bot.Close()
}