-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
utils.go
71 lines (59 loc) · 1.7 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
import (
"fmt"
"net/http"
"github.com/bwmarrin/discordgo"
)
func newRequest(endpoint string) (*http.Request, error) {
req, err := http.NewRequest("GET", endpoint, nil)
if err != nil {
return nil, err
}
req.Header.Set("User-Agent", "discord-esports-bot - https://github.com/Kyagara/discord-esports")
return req, nil
}
func hasPermissions(interaction *discordgo.InteractionCreate) bool {
if len(client.config.ModRoles) == 0 {
return true
}
for _, memberRole := range interaction.Member.Roles {
for _, modRole := range client.config.ModRoles {
if memberRole == modRole {
return true
}
}
}
respondWithMessage(interaction.Interaction, "You don't have permission to run this command.")
return false
}
func respondWithEmbed(interaction *discordgo.Interaction, embed []*discordgo.MessageEmbed) {
err := client.session.InteractionRespond(interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Embeds: embed,
},
})
if err != nil {
client.logger.Error(fmt.Sprintf("Error responding with embed: %v", err))
}
}
func respondWithMessage(interaction *discordgo.Interaction, message string) {
err := client.session.InteractionRespond(interaction, &discordgo.InteractionResponse{
Type: discordgo.InteractionResponseChannelMessageWithSource,
Data: &discordgo.InteractionResponseData{
Content: message,
Flags: discordgo.MessageFlagsEphemeral,
},
})
if err != nil {
client.logger.Error(fmt.Sprintf("Error responding with message: %v", err))
}
}
func contains(ids []string, str string) bool {
for _, id := range ids {
if id == str {
return true
}
}
return false
}