/
add.go
81 lines (75 loc) · 2.86 KB
/
add.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
package counting
import (
"github.com/skifli/creft/database"
"github.com/skifli/creft/utils"
"github.com/skifli/golog"
"github.com/switchupcb/disgo"
)
func HandleAdd(bot *disgo.Client, logger *golog.Logger, interaction *disgo.InteractionCreate, channel string) {
var response *disgo.CreateInteractionResponse
response = nil
if !utils.HasAdminPerms(interaction.Member.User.ID) {
response = &disgo.CreateInteractionResponse{
InteractionID: interaction.ID,
InteractionToken: interaction.Token,
InteractionResponse: &disgo.InteractionResponse{
Type: disgo.FlagInteractionCallbackTypeCHANNEL_MESSAGE_WITH_SOURCE,
Data: &disgo.Messages{
Embeds: []*disgo.Embed{
{
Title: disgo.Pointer("Missing Permissions"),
Description: disgo.Pointer("You do not have **sufficient permissions** to run this command.\nYou need to be on the **admins list**."),
Color: disgo.Pointer(13789294),
Footer: &disgo.EmbedFooter{Text: "Run /about for more information about the bot."},
},
},
},
},
}
} else {
if _, ok := database.DatabaseJSON["counting"].(map[string]any)[channel]; ok {
response = &disgo.CreateInteractionResponse{
InteractionID: interaction.ID,
InteractionToken: interaction.Token,
InteractionResponse: &disgo.InteractionResponse{
Type: disgo.FlagInteractionCallbackTypeCHANNEL_MESSAGE_WITH_SOURCE,
Data: &disgo.Messages{
Embeds: []*disgo.Embed{
{
Title: disgo.Pointer("Error"),
Description: disgo.Pointer("The specified channel has **already been added**.\nRun **`/counting remove {channel}`** to remove it."),
Color: disgo.Pointer(13789294),
Footer: &disgo.EmbedFooter{Text: "Run /about for more information about the bot."},
},
},
},
},
}
} else {
response = &disgo.CreateInteractionResponse{
InteractionID: interaction.ID,
InteractionToken: interaction.Token,
InteractionResponse: &disgo.InteractionResponse{
Type: disgo.FlagInteractionCallbackTypeCHANNEL_MESSAGE_WITH_SOURCE,
Data: &disgo.Messages{
Embeds: []*disgo.Embed{
{
Title: disgo.Pointer("Success"),
Description: disgo.Pointer("The specified channel was **successfully** added."),
Color: disgo.Pointer(5082199),
Footer: &disgo.EmbedFooter{Text: "Run /about for more information about the bot."},
},
},
},
},
}
database.DatabaseJSON["counting"].(map[string]any)[channel] = map[string]any{"count": 0.0, "countMax": 0.0, "lastCountUserID": "", "lastCountMessageID": "", "resetsCount": 0.0}
database.Changed = true
}
}
if err := response.Send(bot); err != nil {
logger.Errorf("Failed to respond to an interaction: %s", err)
} else {
logger.Infof("Responded to an interaction from %s.", interaction.Member.User.Username)
}
}