-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.go
More file actions
56 lines (44 loc) · 1.31 KB
/
main.go
File metadata and controls
56 lines (44 loc) · 1.31 KB
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
package main
import (
"log"
"math/rand"
"os"
"os/signal"
"syscall"
"time"
"github.com/bwmarrin/discordgo"
"github.com/opolobot/Opolo/pieces"
"github.com/opolobot/Opolo/utils"
)
func main() {
// Seed math/rand.
rand.Seed(time.Now().UnixNano())
config := utils.GetConfig()
log.Printf("Staring Opolo (%v)", config.Version)
session, err := discordgo.New("Bot " + config.Token)
if err != nil {
log.Fatal("Failed to create discord session:", err)
}
// We need information about guilds (which includes their channels) and msgs.
session.Identify.Intents = discordgo.MakeIntent(discordgo.IntentsGuilds | discordgo.IntentsGuildMessages)
startTime := time.Now()
pieces.RegisterHandlers(session)
pieces.RegisterCommandCategories()
// Measure bootstrap speed.
log.Printf("Bootstap time was %v", time.Since(startTime))
// Open the websocket and begin listening.
err = session.Open()
if err != nil {
log.Fatal("Failed to establish ws connection:", err)
}
// Wait here until CTRL-C or other term signal is received.
log.Println("Opened WS connection. Use 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.
err = session.Close()
if err != nil {
log.Fatalf("Failed to close session")
}
}