/
interaction.go
127 lines (111 loc) · 7.17 KB
/
interaction.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
package tempest
import "net/http"
// https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-interaction-type
type InteractionType uint8
const (
PING_INTERACTION_TYPE InteractionType = iota + 1
APPLICATION_COMMAND_INTERACTION_TYPE
MESSAGE_COMPONENT_INTERACTION_TYPE
APPLICATION_COMMAND_AUTO_COMPLETE_INTERACTION_TYPE
MODAL_SUBMIT_INTERACTION_TYPE
)
// Used only for partial JSON parsing.
type InteractionTypeExtractor struct {
Type InteractionType `json:"type"`
}
// https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
type CommandInteraction struct {
ID Snowflake `json:"id"`
ApplicationID Snowflake `json:"application_id"`
Type InteractionType `json:"type"`
Data CommandInteractionData `json:"data"`
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"` // Temporary token used for responding to the interaction. It's not the same as bot/app token.
Version uint8 `json:"version"` // Read-only property, always = 1.
PermissionFlags uint64 `json:"app_permissions,string"` // Bitwise set of permissions the app or bot has within the channel the interaction was sent from.
Locale string `json:"locale,omitempty"` // Selected language of the invoking user.
GuildLocale string `json:"guild_locale,omitempty"` // Guild's preferred locale, available if invoked in a guild.
Client *Client `json:"-"`
}
// https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
type ComponentInteraction struct {
ID Snowflake `json:"id"`
ApplicationID Snowflake `json:"application_id"`
Type InteractionType `json:"type"`
Data ComponentInteractionData `json:"data"`
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"` // Temporary token used for responding to the interaction. It's not the same as bot/app token.
Version uint8 `json:"version"` // Read-only property, always = 1.
Message Message `json:"message"`
PermissionFlags uint64 `json:"app_permissions,string"` // Bitwise set of permissions the app or bot has within the channel the interaction was sent from.
Locale string `json:"locale,omitempty"` // Selected language of the invoking user.
GuildLocale string `json:"guild_locale,omitempty"` // Guild's preferred locale, available if invoked in a guild.
Client *Client `json:"-"`
w http.ResponseWriter `json:"-"`
}
// https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object
type ModalInteraction struct {
ID Snowflake `json:"id"`
ApplicationID Snowflake `json:"application_id"`
Type InteractionType `json:"type"`
Data ModalInteractionData `json:"data"`
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"` // Temporary token used for responding to the interaction. It's not the same as bot/app token.
Version uint8 `json:"version"` // Read-only property, always = 1.
PermissionFlags uint64 `json:"app_permissions,string"` // Bitwise set of permissions the app or bot has within the channel the interaction was sent from.
Locale string `json:"locale,omitempty"` // Selected language of the invoking user.
GuildLocale string `json:"guild_locale,omitempty"` // Guild's preferred locale, available if invoked in a guild.
Client *Client `json:"-"`
w http.ResponseWriter `json:"-"`
}
// https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-application-command-data-structure
type CommandInteractionData struct {
ID Snowflake `json:"id,omitempty"`
Name string `json:"name"`
Type CommandType `json:"type"`
Resolved *InteractionDataResolved `json:"resolved,omitempty"`
Options []*CommandInteractionOption `json:"options,omitempty"`
GuildID Snowflake `json:"guild_id,omitempty"`
TargetID Snowflake `json:"target_id,omitempty"` // ID of either user or message targeted. Depends whether it was user command or message command.
}
// https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-application-command-interaction-data-option-structure
type CommandInteractionOption struct {
Name string `json:"name"`
Type OptionType `json:"type"`
Value any `json:"value,omitempty"` // string, float64 (double or integer) or bool
Options []*CommandInteractionOption `json:"options,omitempty"`
Focused bool `json:"focused,omitempty"`
}
// https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-resolved-data-structure
type InteractionDataResolved struct {
Users map[Snowflake]*User `json:"users,omitempty"`
Members map[Snowflake]*Member `json:"members,omitempty"`
Roles map[Snowflake]*Role `json:"roles,omitempty"`
Channels map[Snowflake]*PartialChannel `json:"channels,omitempty"`
}
// https://discord.com/developers/docs/interactions/application-commands#application-command-object-application-command-option-choice-structure
type Choice struct {
Name string `json:"name"`
NameLocalizations map[string]string `json:"name_localizations,omitempty"` // https://discord.com/developers/docs/reference#locales
Value any `json:"value"` // string, float64 (double or integer) or bool
}
// https://discord.com/developers/docs/interactions/receiving-and-responding#interaction-object-message-component-data-structure
type ComponentInteractionData struct {
CustomID string `json:"custom_id"`
Type ComponentType `json:"component_type"`
Values []string `json:"values,omitempty"`
Resolved *InteractionDataResolved `json:"resolved,omitempty"`
}
type ModalInteractionData struct {
CustomID string `json:"custom_id"`
Components []ComponentRow `json:"components"`
}