-
Notifications
You must be signed in to change notification settings - Fork 1
/
remove.go
84 lines (77 loc) · 2.83 KB
/
remove.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
package admins
import (
"github.com/skifli/creft/database"
"github.com/skifli/creft/utils"
"github.com/skifli/golog"
"github.com/switchupcb/disgo"
)
func HandleRemove(bot *disgo.Client, logger *golog.Logger, interaction *disgo.InteractionCreate) {
subCommands := interaction.ApplicationCommand().Options
userID := subCommands[0].Options[0].Value.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["admins"].(map[string]any)[userID]; 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("Success"),
Description: disgo.Pointer("The specified user was **successfully** removed."),
Color: disgo.Pointer(5082199),
Footer: &disgo.EmbedFooter{Text: "Run /about for more information about the bot."},
},
},
},
},
}
delete(database.DatabaseJSON["admins"].(map[string]any), userID)
database.Changed = true
} 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("Error"),
Description: disgo.Pointer("The specified user has **not been added**.\nRun **`/admins add {user}`** to add them."),
Color: disgo.Pointer(13789294),
Footer: &disgo.EmbedFooter{Text: "Run /about for more information about the bot."},
},
},
},
},
}
}
}
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)
}
}