workgroups/vendor/github.com/DisgoOrg/disgohook/api/component.go
Marvin Preuss 1d4ae27878
All checks were successful
continuous-integration/drone/push Build is passing
ci: drone yaml with reusable anchors
2021-09-24 17:34:17 +02:00

55 lines
1.4 KiB
Go

package api
// ComponentType defines different Component(s)
type ComponentType int
// Supported ComponentType(s)
const (
ComponentTypeActionRow = iota + 1
ComponentTypeButton
ComponentTypeSelectMenu
)
// Component is a general interface each Component needs to implement
type Component interface {
Type() ComponentType
}
func newComponentImpl(componentType ComponentType) ComponentImpl {
return ComponentImpl{ComponentType: componentType}
}
// ComponentImpl is used to embed in each different ComponentType
type ComponentImpl struct {
ComponentType ComponentType `json:"type"`
}
// Type returns the ComponentType of this Component
func (t ComponentImpl) Type() ComponentType {
return t.ComponentType
}
// UnmarshalComponent is used for easier unmarshalling of different Component(s)
type UnmarshalComponent struct {
ComponentType ComponentType `json:"type"`
// Button && SelectMenu
CustomID string `json:"custom_id"`
// Button
Style ButtonStyle `json:"style"`
Label string `json:"label"`
Emoji *Emoji `json:"emoji"`
URL string `json:"url"`
Disabled bool `json:"disabled"`
// ActionRow
Components []UnmarshalComponent `json:"components"`
// SelectMenu
Placeholder string `json:"placeholder"`
MinValues int `json:"min_values,omitempty"`
MaxValues int `json:"max_values,omitempty"`
Options []SelectOption `json:"options"`
}