-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathinteractions.go
181 lines (155 loc) · 5.42 KB
/
interactions.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
package corde
const (
// RouteInteractionSubcommandGroup represents the map key for a subcommand group route
RouteInteractionSubcommandGroup = "$group"
// RouteInteractionSubcommand reprensents the map key for a subcommand route
RouteInteractionSubcommand = "$command"
// RouteInteractionFocused represents the map key for a focused route.
// This is useful for autocomplete interactions so we can route on focused keys
// Such, we route on `$group/$command/$focused`,
RouteInteractionFocused = "$focused"
)
// InteractionType is the type of interaction
type InteractionType int
const (
INTERACTION_TYPE_PING InteractionType = iota + 1
INTERACTION_TYPE_APPLICATION_COMMAND
INTERACTION_TYPE_MESSAGE_COMPONENT
INTERACTION_TYPE_APPLICATION_COMMAND_AUTOCOMPLETE
INTERACTION_TYPE_MODAL
)
// InnerInteractionType is the inner type of interactions,
// and not just command, component, autocomplete etc.
type InnerInteractionType int
const (
// components
ActionRowInteraction InnerInteractionType = iota + 1
ButtonInteraction
SelectMenuInteraction
TextInputInteraction
// autocomplete
AutocompleteInteraction
// commands
SlashCommandInteraction
UserCommandInteraction
MessageCommandInteraction
ModalInteraction
)
// Interaction is a Discord Interaction
// https://discord.com/developers/docs/interactions/receiving-and-responding#interactions
type Interaction[T InteractionDataConstraint] struct {
ID Snowflake `json:"id"`
ApplicationID Snowflake `json:"application_id"`
Type InteractionType `json:"type"`
Data T `json:"data,omitempty"`
GuildID Snowflake `json:"guild_id,omitempty"`
ChannelID Snowflake `json:"channel_id,omitempty"`
Member Member `json:"member,omitempty"`
User *User `json:"user,omitempty"`
Token string `json:"token"`
Version int `json:"version"`
Message *Message `json:"message,omitempty"`
Locale string `json:"locale,omitempty"`
GuildLocale string `json:"guild_locale,omitempty"`
Route string `json:"-"`
InnerInteractionType InnerInteractionType `json:"-"`
}
type (
_basicT struct {
Type InteractionType `json:"type"`
Data []byte `json:"data,omitempty"`
}
_appCommandT struct {
Type int `json:"type"`
Name string `json:"name"`
Options OptionsInteractions `json:"options"`
}
_messageComponentT struct {
Type int `json:"type"`
Name string `json:"name"`
Options OptionsInteractions `json:"options"`
}
)
type (
// InteractionDataConstraint is the constraint for the interaction data
// It contains all the possible values for interaction data
InteractionDataConstraint interface {
JsonRaw |
ButtonInteractionData |
SelectInteractionData |
TextInputInteractionData |
ModalInteractionData |
UserCommandInteractionData |
MessageCommandInteractionData |
SlashCommandInteractionData |
AutocompleteInteractionData |
PartialCommandInteraction
}
resolvedInteractionWithOptions struct {
Resolved Resolved `json:"resolved,omitempty"`
Options OptionsInteractions `json:"options,omitempty"`
}
AutocompleteInteractionData struct {
ID Snowflake `json:"id"`
Name string `json:"name"`
Type int `json:"type"`
Options OptionsInteractions `json:"options,omitempty"`
}
ButtonInteractionData struct {
CustomID string `json:"custom_id,omitempty"`
ComponentType ComponentType `json:"component_type"`
}
SelectInteractionData struct {
CustomID string `json:"custom_id,omitempty"`
ComponentType ComponentType `json:"component_type"`
Values []any `json:"values,omitempty"`
}
TextInputInteractionData struct {
CustomID string `json:"custom_id"`
Title string `json:"title"`
Style int `json:"style"`
Label string `json:"label"`
MinLenght int `json:"min_length,omitempty"`
MaxLenght int `json:"max_length,omitempty"`
Required bool `json:"required,omitempty"`
Value string `json:"value,omitempty"`
Placeholder string `json:"placeholder,omitempty"`
Components []Component `json:"components"`
}
ModalInteractionData struct {
CustomID string `json:"custom_id,omitempty"`
Components []Component `json:"components,omitempty"`
}
PartialCommandInteraction struct {
Type int `json:"type"`
JsonRaw
}
UserCommandInteractionData struct {
ID Snowflake `json:"id"`
TargetID Snowflake `json:"target_id,omitempty"`
Name string `json:"name"`
Type int `json:"type"`
resolvedInteractionWithOptions
}
MessageCommandInteractionData struct {
ID Snowflake `json:"id"`
TargetID Snowflake `json:"target_id,omitempty"`
Name string `json:"name"`
Type int `json:"type"`
resolvedInteractionWithOptions
}
SlashCommandInteractionData struct {
ID Snowflake `json:"id"`
Name string `json:"name"`
Type int `json:"type"`
resolvedInteractionWithOptions
}
PartialRoutingType struct {
ID Snowflake `json:"id"`
Type int `json:"type"`
ComponentType int `json:"component_type"`
Name string `json:"name"`
CustomID string `json:"custom_id"`
resolvedInteractionWithOptions
}
)