forked from hummusbird/northstar-bot
-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup.go
106 lines (97 loc) · 2.59 KB
/
setup.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
package main
import (
"log"
"northstar-bot/commands"
"northstar-bot/messages"
"github.com/bwmarrin/discordgo"
)
var (
commandsList = []*discordgo.ApplicationCommand{
{
Name: "status", // Implemented
Description: "A general overview of northstar.tf",
},
{
Name: "search", // Implemented
Description: "Search all running Northstar servers",
Options: commands.SearchOpts,
},
{
Name: "host", // Implemented
Description: "Link to hummusbird's server tutorial",
},
{
Name: "wiki", // Implemented
Description: "Link to Northstar Wiki",
},
{
Name: "github", // Implemented
Description: "Link to Northstar Github",
},
{
Name: "info", // Implemented
Description: "Display information about the bot",
},
{
Name: "redeem",
Description: "Redeem your ScorchBucks",
},
{
Name: "list", // Implemented
Description: "List various things about Northstar",
Options: commands.ListOpts,
},
{
Name: "link", // Implemented
Description: "Easy send URL of various Northstar things",
Options: commands.LinkOpts,
},
{
Name: "redeem",
Description: "Redeem ScorchBucks",
},
}
commandHandlers = map[string]func(s *discordgo.Session, i *discordgo.InteractionCreate){
"status": commands.StatusHandler,
"info": commands.InfoHandler,
"list": commands.ListCmdHandler,
"link": commands.LinkCmdHandler,
"search": commands.SearchHandler,
"redeem": commands.RedeemHandler,
}
)
func registerCommands(s *discordgo.Session) {
regCmd := make([]*discordgo.ApplicationCommand, len(commandsList))
for i, v := range commandsList {
cmd, err := s.ApplicationCommandCreate(s.State.User.ID, s.State.Application.GuildID, v)
if err != nil {
log.Fatal(err)
}
regCmd[i] = cmd
}
log.Println("[INFO] All commands registered")
}
func setupAllHandlers(s *discordgo.Session) {
// Attach type-specific handlers
s.AddHandler(func(s *discordgo.Session, i *discordgo.InteractionCreate) {
switch i.Type {
// Attach command handlers for slash commands
case discordgo.InteractionApplicationCommand:
if h, ok := commandHandlers[i.ApplicationCommandData().Name]; ok {
h(s, i)
}
/* Attach component handlers, such as handlers for buttons
case discordgo.InteractionMessageComponent:
if h, ok := componentHandlers[i.MessageComponentData().CustomID]; ok {
h(s, i)
}
*/
}
})
s.AddHandler(messages.MessageCreateHandler)
log.Println("[INFO] All handlers attached")
}
func Setup(s *discordgo.Session) {
registerCommands(s)
setupAllHandlers(s)
}