@@ -32,18 +32,32 @@ const (
32
32
type Component interface {
33
33
json.Marshaler
34
34
Type () ComponentType
35
+ GetID () int
36
+ component ()
35
37
}
36
38
39
+ type InteractiveComponent interface {
40
+ Component
41
+ GetCustomID () string
42
+ interactiveComponent ()
43
+ }
44
+
45
+ // LayoutComponent is an interface for all components that can be present as a top level component in a [Message].
46
+ // [ActionRowComponent]
47
+ // [SectionComponent]
48
+ // [TextDisplayComponent]
49
+ // [MediaGalleryComponent]
50
+ // [FileComponent]
51
+ // [SeparatorComponent]
52
+ // [ContainerComponent]
37
53
type LayoutComponent interface {
38
54
Component
39
- Components () []Component
40
- containerComponent ()
55
+ layoutComponent ()
41
56
}
42
57
43
- type InteractiveComponent interface {
58
+ type MessageComponent interface {
44
59
Component
45
- ComponentCustomID () string
46
- interactiveComponent ()
60
+ messageComponent ()
47
61
}
48
62
49
63
type UnmarshalComponent struct {
@@ -187,6 +201,17 @@ func (ActionRowComponent) Type() ComponentType {
187
201
return ComponentTypeActionRow
188
202
}
189
203
204
+ func (c ActionRowComponent ) GetID () int {
205
+ return c .ID
206
+ }
207
+
208
+ func (c ActionRowComponent ) GetComponents () []Component {
209
+ return c .Components
210
+ }
211
+
212
+ func (ActionRowComponent ) component () {}
213
+ func (ActionRowComponent ) layoutComponent () {}
214
+
190
215
// Buttons returns all ButtonComponent(s) in the ActionRowComponent
191
216
func (c ActionRowComponent ) Buttons () []ButtonComponent {
192
217
var buttons []ButtonComponent
@@ -353,6 +378,17 @@ func (ButtonComponent) Type() ComponentType {
353
378
return ComponentTypeButton
354
379
}
355
380
381
+ func (c ButtonComponent ) GetID () int {
382
+ return c .ID
383
+ }
384
+
385
+ func (c ButtonComponent ) GetCustomID () string {
386
+ return c .CustomID
387
+ }
388
+
389
+ func (ButtonComponent ) component () {}
390
+ func (ButtonComponent ) interactiveComponent () {}
391
+
356
392
// WithStyle returns a new ButtonComponent with the provided style
357
393
func (c ButtonComponent ) WithStyle (style ButtonStyle ) ButtonComponent {
358
394
c .Style = style
@@ -454,6 +490,17 @@ func (TextInputComponent) Type() ComponentType {
454
490
return ComponentTypeTextInput
455
491
}
456
492
493
+ func (c TextInputComponent ) GetID () int {
494
+ return c .ID
495
+ }
496
+
497
+ func (c TextInputComponent ) GetCustomID () string {
498
+ return c .CustomID
499
+ }
500
+
501
+ func (TextInputComponent ) component () {}
502
+ func (TextInputComponent ) interactiveComponent () {}
503
+
457
504
// WithCustomID returns a new SelectMenuComponent with the provided customID
458
505
func (c TextInputComponent ) WithCustomID (customID string ) TextInputComponent {
459
506
c .CustomID = customID
@@ -509,10 +556,12 @@ type UnfurledMediaItem struct {
509
556
}
510
557
511
558
var (
512
- _ Component = (* SectionComponent )(nil )
559
+ _ Component = (* SectionComponent )(nil )
560
+ _ LayoutComponent = (* SectionComponent )(nil )
513
561
)
514
562
515
563
type SectionComponent struct {
564
+ ID int `json:"id,omitempty"`
516
565
Components []Component `json:"components"`
517
566
Accessory Component `json:"accessory"`
518
567
}
@@ -532,11 +581,23 @@ func (SectionComponent) Type() ComponentType {
532
581
return ComponentTypeSection
533
582
}
534
583
584
+ func (c SectionComponent ) GetID () int {
585
+ return c .ID
586
+ }
587
+
588
+ func (c SectionComponent ) GetComponents () []Component {
589
+ return c .Components
590
+ }
591
+
592
+ func (SectionComponent ) component () {}
593
+ func (SectionComponent ) layoutComponent () {}
594
+
535
595
var (
536
596
_ Component = (* TextDisplayComponent )(nil )
537
597
)
538
598
539
599
type TextDisplayComponent struct {
600
+ ID int `json:"id,omitempty"`
540
601
Content string `json:"content"`
541
602
}
542
603
@@ -555,11 +616,18 @@ func (TextDisplayComponent) Type() ComponentType {
555
616
return ComponentTypeTextDisplay
556
617
}
557
618
619
+ func (c TextDisplayComponent ) GetID () int {
620
+ return c .ID
621
+ }
622
+
623
+ func (TextDisplayComponent ) component () {}
624
+
558
625
var (
559
626
_ Component = (* ThumbnailComponent )(nil )
560
627
)
561
628
562
629
type ThumbnailComponent struct {
630
+ ID int `json:"id,omitempty"`
563
631
Media UnfurledMediaItem `json:"media"`
564
632
Description string `json:"description,omitempty"`
565
633
Spoiler bool `json:"spoiler,omitempty"`
@@ -580,6 +648,12 @@ func (ThumbnailComponent) Type() ComponentType {
580
648
return ComponentTypeThumbnail
581
649
}
582
650
651
+ func (c ThumbnailComponent ) GetID () int {
652
+ return c .ID
653
+ }
654
+
655
+ func (ThumbnailComponent ) component () {}
656
+
583
657
type MediaGalleryItem struct {
584
658
Media UnfurledMediaItem `json:"media"`
585
659
Description string `json:"description,omitempty"`
@@ -591,6 +665,7 @@ var (
591
665
)
592
666
593
667
type MediaGalleryComponent struct {
668
+ ID int `json:"id,omitempty"`
594
669
Items []MediaGalleryItem `json:"items"`
595
670
}
596
671
@@ -609,6 +684,12 @@ func (MediaGalleryComponent) Type() ComponentType {
609
684
return ComponentTypeMediaGallery
610
685
}
611
686
687
+ func (c MediaGalleryComponent ) GetID () int {
688
+ return c .ID
689
+ }
690
+
691
+ func (MediaGalleryComponent ) component () {}
692
+
612
693
type SeparatorSpacingSize int
613
694
614
695
const (
@@ -622,6 +703,7 @@ var (
622
703
)
623
704
624
705
type SeparatorComponent struct {
706
+ ID int `json:"id,omitempty"`
625
707
Divider bool `json:"divider,omitempty"`
626
708
Spacing SeparatorSpacingSize `json:"spacing,omitempty"`
627
709
}
@@ -641,11 +723,18 @@ func (SeparatorComponent) Type() ComponentType {
641
723
return ComponentTypeSeparator
642
724
}
643
725
726
+ func (c SeparatorComponent ) GetID () int {
727
+ return c .ID
728
+ }
729
+
730
+ func (SeparatorComponent ) component () {}
731
+
644
732
var (
645
733
_ Component = (* FileComponent )(nil )
646
734
)
647
735
648
736
type FileComponent struct {
737
+ ID int `json:"id,omitempty"`
649
738
// File only supports attachment://<filename> references
650
739
File UnfurledMediaItem `json:"file"`
651
740
Spoiler bool `json:"spoiler,omitempty"`
@@ -666,11 +755,19 @@ func (FileComponent) Type() ComponentType {
666
755
return ComponentTypeFile
667
756
}
668
757
758
+ func (c FileComponent ) GetID () int {
759
+ return c .ID
760
+ }
761
+
762
+ func (FileComponent ) component () {}
763
+
669
764
var (
670
- _ Component = (* ContainerComponent )(nil )
765
+ _ Component = (* ContainerComponent )(nil )
766
+ _ LayoutComponent = (* ContainerComponent )(nil )
671
767
)
672
768
673
769
type ContainerComponent struct {
770
+ ID int `json:"id,omitempty"`
674
771
AccentColor * int `json:"accent_color,omitempty"`
675
772
Spoiler bool `json:"spoiler,omitempty"`
676
773
Components []Component `json:"components"`
@@ -691,23 +788,37 @@ func (ContainerComponent) Type() ComponentType {
691
788
return ComponentTypeContainer
692
789
}
693
790
791
+ func (c ContainerComponent ) GetID () int {
792
+ return c .ID
793
+ }
794
+
795
+ func (c ContainerComponent ) GetComponents () []Component {
796
+ return c .Components
797
+ }
798
+
799
+ func (ContainerComponent ) component () {}
800
+ func (ContainerComponent ) layoutComponent () {}
801
+
694
802
var (
695
- _ Component = (* UnknownComponent )(nil )
803
+ _ Component = (* UnknownComponent )(nil )
804
+ _ InteractiveComponent = (* UnknownComponent )(nil )
805
+ _ LayoutComponent = (* UnknownComponent )(nil )
806
+ _ SelectMenuComponent = (* UnknownComponent )(nil )
696
807
)
697
808
698
809
type UnknownComponent struct {
699
- type_ ComponentType
700
- id int
701
- Data json.RawMessage
810
+ ComponentType ComponentType
811
+ ID int
812
+ Data json.RawMessage
702
813
}
703
814
704
815
func (c UnknownComponent ) MarshalJSON () ([]byte , error ) {
705
816
data , err := json .Marshal (struct {
706
817
Type ComponentType `json:"type"`
707
818
ID int `json:"id,omitempty"`
708
819
}{
709
- Type : c .type_ ,
710
- ID : c .id ,
820
+ Type : c .ComponentType ,
821
+ ID : c .ID ,
711
822
})
712
823
if err != nil {
713
824
return nil , err
@@ -725,12 +836,47 @@ func (c *UnknownComponent) UnmarshalJSON(data []byte) error {
725
836
return err
726
837
}
727
838
728
- c .type_ = unknownComponent .Type
729
- c .id = unknownComponent .ID
839
+ c .ComponentType = unknownComponent .Type
840
+ c .ID = unknownComponent .ID
730
841
c .Data = data
731
842
return nil
732
843
}
733
844
734
845
func (c UnknownComponent ) Type () ComponentType {
735
- return c .type_
846
+ return c .ComponentType
847
+ }
848
+
849
+ func (c UnknownComponent ) GetID () int {
850
+ return c .ID
851
+ }
852
+
853
+ func (c UnknownComponent ) GetCustomID () string {
854
+ var data struct {
855
+ CustomID string `json:"custom_id"`
856
+ }
857
+ if err := json .Unmarshal (c .Data , & data ); err != nil {
858
+ return ""
859
+ }
860
+
861
+ return data .CustomID
736
862
}
863
+
864
+ func (c UnknownComponent ) GetComponents () []Component {
865
+ var data struct {
866
+ Components []UnmarshalComponent `json:"components"`
867
+ }
868
+ if err := json .Unmarshal (c .Data , & data ); err != nil {
869
+ return nil
870
+ }
871
+
872
+ var components []Component
873
+ for _ , component := range data .Components {
874
+ components = append (components , component .Component )
875
+ }
876
+ return components
877
+ }
878
+
879
+ func (UnknownComponent ) component () {}
880
+ func (UnknownComponent ) interactiveComponent () {}
881
+ func (UnknownComponent ) layoutComponent () {}
882
+ func (UnknownComponent ) selectMenuComponent () {}
0 commit comments