-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
handlers.go
72 lines (63 loc) · 1.83 KB
/
handlers.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
package main
import (
"slices"
"strings"
"github.com/disgoorg/disgo/events"
"github.com/vaporvee/acecore/shared"
)
var commands []shared.Command
func applicationCommandInteractionCreate(e *events.ApplicationCommandInteractionCreate) {
for _, command := range commands {
if command.Interact != nil && e.Data.CommandName() == command.Definition.CommandName() {
command.Interact(e)
}
}
}
func autocompleteInteractionCreate(e *events.AutocompleteInteractionCreate) {
for _, command := range commands {
if command.Autocomplete != nil && e.Data.CommandName == command.Definition.CommandName() {
command.Autocomplete(e)
}
}
}
func componentInteractionCreate(e *events.ComponentInteractionCreate) {
for _, command := range commands {
if command.ComponentInteract != nil {
if slices.Contains(command.ComponentIDs, e.Data.CustomID()) || slices.ContainsFunc(command.DynamicComponentIDs(), func(id string) bool {
var customID string
if strings.ContainsAny(e.Data.CustomID(), ";") {
customID = strings.TrimSuffix(e.Data.CustomID(), ";"+strings.Split(e.Data.CustomID(), ";")[1])
} else {
customID = e.Data.CustomID()
}
return id == customID
}) {
command.ComponentInteract(e)
}
}
}
}
func modalSubmitInteractionCreate(e *events.ModalSubmitInteractionCreate) {
for _, command := range commands {
if command.ModalSubmit != nil {
var hasID bool = false
var modalIDs []string
if command.ModalIDs != nil {
modalIDs = command.ModalIDs
}
if command.DynamicModalIDs != nil {
modalIDs = append(command.ModalIDs, command.DynamicModalIDs()...)
}
for _, modalID := range modalIDs {
if strings.HasPrefix(e.Data.CustomID, modalID) {
hasID = true
break
}
}
if hasID {
command.ModalSubmit(e)
return // I have no idea why it crashes without that return
}
}
}
}