1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-27 17:23:00 +00:00

discord: Add select component type (#260)

This commit is contained in:
starshines 2021-08-10 23:02:30 +02:00 committed by GitHub
parent 3753794fad
commit f7880b91ee
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 41 additions and 1 deletions

View file

@ -14,6 +14,7 @@ type ComponentType uint
const (
ActionRowComponentType ComponentType = iota + 1
ButtonComponentType
SelectComponentType
)
// ComponentWrap wraps Component for the purpose of JSON unmarshalling.
@ -187,6 +188,42 @@ func (b ButtonComponent) MarshalJSON() ([]byte, error) {
})
}
// Select is a clickable button that may be added to an interaction response.
type SelectComponent struct {
CustomID string `json:"custom_id"`
Options []SelectComponentOption `json:"options"`
Placeholder string `json:"placeholder,omitempty"`
MinValues int `json:"min_values,omitempty"`
MaxValues int `json:"max_values,omitempty"`
Disabled bool `json:"disabled,omitempty"`
}
type SelectComponentOption struct {
Label string `json:"label"`
Value string `json:"value"`
Description string `json:"description,omitempty"`
Emoji *ButtonEmoji `json:"emoji,omitempty"`
Default bool `json:"default,omitempty"`
}
// Type implements the Component interface.
func (SelectComponent) Type() ComponentType {
return SelectComponentType
}
// MarshalJSON marshals the select in the format Discord expects.
func (s SelectComponent) MarshalJSON() ([]byte, error) {
type selectComponent SelectComponent
return json.Marshal(struct {
selectComponent
Type ComponentType `json:"type"`
}{
selectComponent: selectComponent(s),
Type: SelectComponentType,
})
}
// UnknownComponent is reserved for components with unknown or not yet
// implemented components types.
type UnknownComponent struct {

View file

@ -435,9 +435,12 @@ type InteractionData struct {
Name string `json:"name"`
Options []InteractionOption `json:"options"`
// Button
// Button and select
CustomID string `json:"custom_id"`
ComponentType discord.ComponentType `json:"component_type"`
// Select
Values []string `json:"values"`
}
type InteractionOption struct {