This repository has been archived by the owner on Dec 21, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 95
/
Copy pathutils.go
48 lines (39 loc) · 1.55 KB
/
utils.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
package aternos_discord_bot
import (
"github.com/bwmarrin/discordgo"
"github.com/sleeyax/aternos-discord-bot/message"
"log"
)
func respond(s *discordgo.Session, i *discordgo.InteractionCreate, data *discordgo.InteractionResponseData) error {
return s.InteractionRespond(i.Interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: data,
})
}
func respondWithText(s *discordgo.Session, i *discordgo.InteractionCreate, content string) error {
return respond(s, i, &discordgo.InteractionResponseData{
Content: content,
})
}
func respondWithHiddenText(s *discordgo.Session, i *discordgo.InteractionCreate, content string) error {
return respond(s, i, &discordgo.InteractionResponseData{
Content: message.FormatDefault(content),
Flags: discordgo.MessageFlagsEphemeral,
})
}
func respondWithEmbeds(s *discordgo.Session, i *discordgo.InteractionCreate, embeds []*discordgo.MessageEmbed) error {
return respond(s, i, &discordgo.InteractionResponseData{
Embeds: embeds,
})
}
func respondWithError(s *discordgo.Session, i *discordgo.InteractionCreate, content string, err error) error {
log.Printf("%s: %s\n", content, err)
return respondWithText(s, i, message.FormatError(content))
}
func optionsToMap(options []*discordgo.ApplicationCommandInteractionDataOption) map[string]*discordgo.ApplicationCommandInteractionDataOption {
optionMap := make(map[string]*discordgo.ApplicationCommandInteractionDataOption, len(options))
for _, opt := range options {
optionMap[opt.Name] = opt
}
return optionMap
}