-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
129 lines (109 loc) · 2.98 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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
package main
import (
"flag"
"fmt"
"os"
"os/signal"
"github.com/diamondburned/arikawa/v2/gateway"
"github.com/diamondburned/arikawa/v2/state"
"github.com/diamondburned/arikawa/v2/utils/handler"
"github.com/diamondburned/arikawa/v2/voice"
)
var token = flag.String("t", "", "Set the token (overrides $BOT_TOKEN)")
var botname = flag.String("n", "eto", "Set the bot's name")
var prefix = flag.String("p", "!", "Set the bot's prefix")
var gittoken = flag.String("T", "", "Set the git token (overrides $GIT_TOKEN)")
var s *state.State
var u *gateway.ReadyEvent
func main() {
flag.Parse()
if *token == "" {
toke := os.Getenv("BOT_TOKEN")
if toke == "" {
fmt.Println("No BOT_TOKEN: Set $BOT_TOKEN or use '-t'")
os.Exit(1)
}
token = &toke
}
if *gittoken == "" {
toke := os.Getenv("GIT_TOKEN")
if toke == "" {
fmt.Println("No GIT_TOKEN: Set $GIT_TOKEN or use '-T'")
}
gittoken = &toke
}
var err error
s, err = state.New(fmt.Sprintf("Bot %s", *token))
if err != nil {
fmt.Printf("Session failed: %s\n", err)
os.Exit(1)
}
addPreHandlers()
addHandlers()
addIntents()
if err := loggerSetup(); err != nil {
fmt.Printf("Failed to setup logger: %s\n", err)
}
if err := basicSetup(); err != nil {
fmt.Printf("%s\n", err)
}
// if *gittoken != "" {
// if err := gitSetup(); err != nil {
// fmt.Printf("%s\n", err)
// }
// }
if err := s.Open(); err != nil {
fmt.Printf("Failed to connect: %s\n", err)
os.Exit(1)
}
defer s.Close()
me, err := s.Me()
if err != nil {
fmt.Printf("Failed to get bot user: %s\n", err)
os.Exit(1)
}
fmt.Printf("Started as %s\n", me.Username)
sigChan := make(chan os.Signal)
signal.Notify(sigChan, os.Interrupt)
<-sigChan // block
}
func addHandlers() {
// setup
s.AddHandler(func(m *gateway.ReadyEvent) {
u = m // info used globally
})
// logger
s.AddHandler(sent)
// basic
s.AddHandler(help)
s.AddHandler(setPrefix)
// music
s.AddHandler(play)
s.AddHandler(kill)
s.AddHandler(skip)
s.AddHandler(queue)
}
func addPreHandlers() {
// setup
s.PreHandler = handler.New()
s.PreHandler.Synchronous = true
s.PreHandler.AddHandler(unsent)
}
func addIntents() {
s.Gateway.AddIntents(gateway.IntentGuilds)
// s.Gateway.AddIntents(gateway.IntentGuildMembers)
// s.Gateway.AddIntents(gateway.IntentGuildBans)
// s.Gateway.AddIntents(gateway.IntentGuildEmojis)
// s.Gateway.AddIntents(gateway.IntentGuildIntegrations)
// s.Gateway.AddIntents(gateway.IntentGuildWebhooks)
// s.Gateway.AddIntents(gateway.IntentGuildInvites)
s.Gateway.AddIntents(gateway.IntentGuildVoiceStates)
// s.Gateway.AddIntents(gateway.IntentGuildPresences)
s.Gateway.AddIntents(gateway.IntentGuildMessages)
// s.Gateway.AddIntents(gateway.IntentGuildMessageReactions)
// s.Gateway.AddIntents(gateway.IntentGuildMessageTyping)
s.Gateway.AddIntents(gateway.IntentDirectMessages)
// s.Gateway.AddIntents(gateway.IntentDirectMessageReactions)
// s.Gateway.AddIntents(gateway.IntentDirectMessageTyping)
voice.AddIntents(s.Gateway) // for voice
}