-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcommand.go
45 lines (39 loc) · 1.17 KB
/
command.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
package serendip
import (
"github.com/bwmarrin/discordgo"
)
func OnSlashCommand(s *discordgo.Session, i *discordgo.InteractionCreate) {
n := i.ApplicationCommandData().Name
if n == "wiki" {
// generate title, summary and URL for a random Wikipedia page
content, err := GenerateRandomArticleMessage()
if err != nil {
return
}
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: content,
},
})
} else if n == "search" {
options := i.ApplicationCommandData().Options
// convert the slice into a map
optionMap := make(map[string]*discordgo.ApplicationCommandInteractionDataOption, len(options))
for _, opt := range options {
optionMap[opt.Name] = opt
}
if query, ok := optionMap["query"]; ok {
content, err := GenerateSearchResultMessage(query.StringValue())
if err != nil {
return
}
s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: content,
},
})
}
}
}