mirror of
https://github.com/diamondburned/arikawa.git
synced 2025-12-02 09:47:52 +00:00
discord: Add select component type (#260)
This commit is contained in:
parent
3753794fad
commit
f7880b91ee
|
|
@ -14,6 +14,7 @@ type ComponentType uint
|
||||||
const (
|
const (
|
||||||
ActionRowComponentType ComponentType = iota + 1
|
ActionRowComponentType ComponentType = iota + 1
|
||||||
ButtonComponentType
|
ButtonComponentType
|
||||||
|
SelectComponentType
|
||||||
)
|
)
|
||||||
|
|
||||||
// ComponentWrap wraps Component for the purpose of JSON unmarshalling.
|
// 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
|
// UnknownComponent is reserved for components with unknown or not yet
|
||||||
// implemented components types.
|
// implemented components types.
|
||||||
type UnknownComponent struct {
|
type UnknownComponent struct {
|
||||||
|
|
|
||||||
|
|
@ -435,9 +435,12 @@ type InteractionData struct {
|
||||||
Name string `json:"name"`
|
Name string `json:"name"`
|
||||||
Options []InteractionOption `json:"options"`
|
Options []InteractionOption `json:"options"`
|
||||||
|
|
||||||
// Button
|
// Button and select
|
||||||
CustomID string `json:"custom_id"`
|
CustomID string `json:"custom_id"`
|
||||||
ComponentType discord.ComponentType `json:"component_type"`
|
ComponentType discord.ComponentType `json:"component_type"`
|
||||||
|
|
||||||
|
// Select
|
||||||
|
Values []string `json:"values"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type InteractionOption struct {
|
type InteractionOption struct {
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue