feat: components v2 structures
This commit is contained in:
parent
49980810d5
commit
9600402fc1
2 changed files with 117 additions and 3 deletions
116
components.go
116
components.go
|
@ -22,7 +22,7 @@ const (
|
|||
TextDisplayComponent ComponentType = 10
|
||||
ThumbnailComponent ComponentType = 11
|
||||
MediaGalleryComponent ComponentType = 12
|
||||
FileComponent ComponentType = 13
|
||||
FileComponentType ComponentType = 13
|
||||
SeparatorComponent ComponentType = 14
|
||||
ContentInventoryEntryComponent ComponentType = 16
|
||||
ContainerComponent ComponentType = 17
|
||||
|
@ -311,3 +311,117 @@ const (
|
|||
TextInputShort TextInputStyle = 1
|
||||
TextInputParagraph TextInputStyle = 2
|
||||
)
|
||||
|
||||
type Section struct {
|
||||
// Unique identifier for the component; auto populated through increment if not provided.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Array of text display components; max of 3.
|
||||
Components []MessageComponent `json:"components"`
|
||||
// Can be Button or Thumbnail
|
||||
Accessory MessageComponent `json:"accessory"`
|
||||
}
|
||||
|
||||
// Type is a method to get the type of a component.
|
||||
func (Section) Type() ComponentType {
|
||||
return SectionComponent
|
||||
}
|
||||
|
||||
// TextDisplay component allows you to send text.
|
||||
type TextDisplay struct {
|
||||
Content string `json:"content"`
|
||||
}
|
||||
|
||||
// Type is a method to get the type of a component.
|
||||
func (TextDisplay) Type() ComponentType {
|
||||
return TextDisplayComponent
|
||||
}
|
||||
|
||||
// Thumbnail component can be used as an accessory for a section component.
|
||||
type Thumbnail struct {
|
||||
// Unique identifier for the component; auto populated through increment if not provided.
|
||||
ID int `json:"id,omitempty"`
|
||||
Media UnfurledMediaItem `json:"media"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Spoiler bool `json:"spoiler,omitemoty"`
|
||||
}
|
||||
|
||||
// Type is a method to get the type of a component.
|
||||
func (Thumbnail) Type() ComponentType {
|
||||
return ThumbnailComponent
|
||||
}
|
||||
|
||||
// MediaGallery component allows you to group images, videos or gifs into a gallery grid.
|
||||
type MediaGallery struct {
|
||||
// Unique identifier for the component; auto populated through increment if not provided.
|
||||
ID int `json:"id,omitempty"`
|
||||
// Array of media gallery items; max of 10.
|
||||
Items []MediaGalleryItem `json:"items"`
|
||||
}
|
||||
|
||||
// Type is a method to get the type of a component.
|
||||
func (MediaGallery) Type() ComponentType {
|
||||
return MediaGalleryComponent
|
||||
}
|
||||
|
||||
type MediaGalleryItem struct {
|
||||
Media UnfurledMediaItem `json:"media"`
|
||||
Description *string `json:"description,omitempty"`
|
||||
Spoiler bool `json:"spoiler"`
|
||||
}
|
||||
|
||||
type FileComponent struct {
|
||||
// Unique identifier for the component; auto populated through increment if not provided.
|
||||
ID int `json:"id,omitempty"`
|
||||
File UnfurledMediaItem `json:"file"`
|
||||
Spoiler bool `json:"spoiler"`
|
||||
}
|
||||
|
||||
// Type is a method to get the type of a component.
|
||||
func (FileComponent) Type() ComponentType {
|
||||
return FileComponentType
|
||||
}
|
||||
|
||||
type SeparatorSpacingSize uint
|
||||
|
||||
const (
|
||||
SeparatorSpacingSizeSmall SeparatorSpacingSize = 1
|
||||
SeparatorSpacingSizeLarge SeparatorSpacingSize = 2
|
||||
)
|
||||
|
||||
// Separator components allow you to divide components with a divider. You can make the divider big or small, and make it invisible if needed.
|
||||
type Separator struct {
|
||||
// Unique identifier for the component; auto populated through increment if not provided.
|
||||
ID int `json:"id,omitempty"`
|
||||
|
||||
Divider *bool `json:"divider,omitempty"`
|
||||
Spacing *SeparatorSpacingSize `json:"spacing,omitempty"`
|
||||
}
|
||||
|
||||
type Container struct {
|
||||
// Unique identifier for the component; auto populated through increment if not provided.
|
||||
ID int `json:"id,omitempty"`
|
||||
AccentColor *int `json:"accent_color,omitempty"`
|
||||
Spoiler bool `json:"spoiler"`
|
||||
Components []MessageComponent `json:"components"`
|
||||
}
|
||||
|
||||
type UnfurledMediaItem struct {
|
||||
URL string `json:"url"`
|
||||
}
|
||||
|
||||
type UnfurledMediaItemLoadingState uint
|
||||
|
||||
const (
|
||||
UnfurledMediaItemLoadingStateUnknown UnfurledMediaItemLoadingState = 0
|
||||
UnfurledMediaItemLoadingStateLoading UnfurledMediaItemLoadingState = 1
|
||||
UnfurledMediaItemLoadingStateLoadingSuccess UnfurledMediaItemLoadingState = 2
|
||||
UnfurledMediaItemLoadingStateLoadedNotFound UnfurledMediaItemLoadingState = 3
|
||||
)
|
||||
|
||||
type ResolvedUnfurledMediaItem struct {
|
||||
URL string `json:"url"`
|
||||
ProxyURL string `json:"proxy_url"`
|
||||
Width int `json:"width"`
|
||||
Height int `json:"height"`
|
||||
ContentType string `json:"content_type"`
|
||||
}
|
||||
|
|
|
@ -230,8 +230,8 @@ const (
|
|||
MessageFlagsSuppressNotifications MessageFlags = 1 << 12
|
||||
// MessageFlagsIsVoiceMessage this message is a voice message.
|
||||
MessageFlagsIsVoiceMessage MessageFlags = 1 << 13
|
||||
// MessageFlagsComponentsV2 this message uses the new components system. Disables the ability of sending `content` & `embeds`
|
||||
MessageFlagsComponentsV2 MessageFlags = 1 << 15
|
||||
// MessageFlagsIsComponentsV2 this message uses the new components system. Disables the ability of sending `content` & `embeds`
|
||||
MessageFlagsIsComponentsV2 MessageFlags = 1 << 15
|
||||
)
|
||||
|
||||
// File stores info about files you e.g. send in messages.
|
||||
|
|
Loading…
Reference in a new issue