-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathboot.go
96 lines (79 loc) · 2.27 KB
/
boot.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
//
// Boot and authentication module
//
package main
import (
"flag"
"fmt"
"log"
"os"
"os/signal"
"syscall"
"github.com/bwmarrin/discordgo"
)
var (
s *discordgo.Session
token = os.Getenv("TOKEN_CARA")
register = flag.Bool("r", false, "Register (or re-register) bot commands on startup")
unregister = flag.Bool("u", false, "Unregister bot commands on shutdown")
)
func init() {
// Print boot "splash"
fmt.Println("╔═══════════════════════╗")
fmt.Println("║ Cara by cyckl ║")
fmt.Println(fmt.Sprintf("║ Running version %s ║", version))
fmt.Println("╚═══════════════════════╝")
log.Println("[Info] Minimum permissions are 8")
// Pass args in
flag.Parse()
configParse()
}
func main() {
// Declare error here so it can be set without :=
var err error
// Create bot client session
log.Println("[Info] Logging in")
s, err = discordgo.New("Bot " + token)
if err != nil {
log.Fatalf("[Fatal] Error creating session: %v", err)
}
// Pass on command events to functions
s.AddHandler(guildInfo)
s.AddHandler(about)
s.AddHandler(help)
s.AddHandler(sticks)
s.AddHandler(avatar)
s.AddHandler(tweet)
s.AddHandler(restore)
s.AddHandler(kick)
s.AddHandler(respond)
s.AddHandler(selfEsteem)
s.AddHandler(status)
s.AddHandler(gutEnable)
s.AddHandler(gutSpam)
// We only care about integration (command) intents
s.Identify.Intents = discordgo.MakeIntent(discordgo.IntentsGuildIntegrations | discordgo.IntentsGuilds | discordgo.IntentsGuildMessages | discordgo.IntentsGuildMembers | discordgo.IntentsGuildVoiceStates)
// Open websocket connection to Discord and listen
err = s.Open()
if err != nil {
log.Fatalf("[Fatal] Error opening connection: %v", err)
}
// Default status
err = s.UpdateStatusComplex(*newUpdateStatusData(0, 3, "you", "https://cara.cyckl.net"))
if err != nil {
log.Println("[Error][Boot] Failed to set status:", err)
return
}
if *register == true {
registerCmd(s)
}
// Close Discord session cleanly
defer s.Close()
stop := make(chan os.Signal)
signal.Notify(stop, syscall.SIGINT, syscall.SIGTERM, os.Interrupt, os.Kill)
<-stop
if *unregister == true {
unregisterCmd(s)
}
log.Println("[Info] Shutting down")
}