-
Notifications
You must be signed in to change notification settings - Fork 0
/
bot.go
78 lines (63 loc) · 1.75 KB
/
bot.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
package main
import (
"context"
"log"
"os"
"os/signal"
"github.com/diamondburned/arikawa/v3/gateway"
"github.com/diamondburned/arikawa/v3/state"
"github.com/diamondburned/arikawa/v3/utils/handler"
"github.com/twoscott/haseul-bot-2/config"
"github.com/twoscott/haseul-bot-2/modules"
"github.com/twoscott/haseul-bot-2/router"
"github.com/twoscott/haseul-bot-2/utils/dctools"
)
func main() {
log.Println("Haseul Bot starting...")
cfg := config.GetInstance()
token := cfg.Discord.Token
if token == "" {
log.Fatalln("No token found in config file")
}
botToken := dctools.BotToken(token)
st := state.New(botToken)
rt := router.New(st)
hnd := router.NewHandler(rt)
setIntents(st)
setHandlers(st, hnd)
modules.Init(rt)
rt.MustRegisterCommandHandlers()
err := st.Open(context.Background())
if err != nil {
log.Fatalln("Failed to connect to Discord:", err)
}
_, err = st.Me()
if err != nil {
log.Fatalln("Failed to fetch myself:", err)
}
err = rt.AddCommandsToDiscord()
if err != nil {
log.Fatalln("Failed to add commands to Discord:", err)
}
log.Print("Haseul Bot is now running. Press Ctrl-C to exit. ")
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt)
<-sigs
}
func setIntents(st *state.State) {
st.AddIntents(gateway.IntentGuilds)
st.AddIntents(gateway.IntentGuildMembers)
st.AddIntents(gateway.IntentGuildInvites)
st.AddIntents(gateway.IntentGuildMessages)
}
func setHandlers(st *state.State, h *router.Handler) {
st.PreHandler = handler.New()
st.PreHandler.AddSyncHandler(h.MessageDelete)
st.PreHandler.AddSyncHandler(h.MessageUpdate)
st.AddHandler(h.GuildJoin)
st.AddHandler(h.MessageCreate)
st.AddHandler(h.Ready)
st.AddHandler(h.InteractionCreate)
st.AddHandler(h.MemberJoin)
st.AddHandler(h.MemberLeave)
}