-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcomponents.go
More file actions
266 lines (219 loc) · 4.9 KB
/
components.go
File metadata and controls
266 lines (219 loc) · 4.9 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
package webhooks
import "encoding/json"
// Not all components are supported by webhooks.
//
// Since this library is purely just for basic webhooks and not application ones,
// some components are not implemented to be used.
type ComponentType int
const (
ComponentTypeActionRow ComponentType = iota + 1
ComponentTypeButton
_
_
_
_
_
_
ComponentTypeSection
ComponentTypeTextDisplay
ComponentTypeThumbnail
ComponentTypeMediaGallery
ComponentTypeFile
ComponentTypeSeparator
_
_
ComponentTypeContainer
_
_
)
type Component interface {
json.Marshaler
Type() ComponentType
}
type ActionRow struct {
ID int `json:"id,omitempty"`
Components []Component `json:"components"`
}
func (a *ActionRow) Type() ComponentType {
return ComponentTypeActionRow
}
func (a *ActionRow) MarshalJSON() ([]byte, error) {
type ar ActionRow
return json.Marshal(struct {
ar
Type ComponentType `json:"type"`
}{
ar: ar(*a),
Type: a.Type(),
})
}
type ButtonStyle int
const (
_ ButtonStyle = iota + 1
_
_
_
ButtonStyleLink
_
)
type Button struct {
ID int `json:"id,omitempty"`
Style ButtonStyle `json:"style"`
Label string `json:"label,omitempty"`
CustomID string `json:"custom_id,omitempty"`
SKUID string `json:"sku_id,omitempty"`
URL string `json:"url,omitempty"`
Disabled bool `json:"disabled,omitempty"`
}
func (b *Button) Type() ComponentType {
return ComponentTypeButton
}
func (b *Button) MarshalJSON() ([]byte, error) {
type bu Button
return json.Marshal(struct {
bu
Type ComponentType `json:"type"`
}{
bu: bu(*b),
Type: b.Type(),
})
}
type Section struct {
ID int `json:"id,omitempty"`
Components []Component `json:"components"`
Accessory Component `json:"accessory"`
}
func (s *Section) Type() ComponentType {
return ComponentTypeSection
}
func (s *Section) MarshalJSON() ([]byte, error) {
type se Section
return json.Marshal(struct {
se
Type ComponentType `json:"type"`
}{
se: se(*s),
Type: s.Type(),
})
}
type TextDisplay struct {
ID int `json:"id,omitempty"`
Content string `json:"content"`
}
func (t *TextDisplay) Type() ComponentType {
return ComponentTypeTextDisplay
}
func (t *TextDisplay) MarshalJSON() ([]byte, error) {
type td TextDisplay
return json.Marshal(struct {
td
Type ComponentType `json:"type"`
}{
td: td(*t),
Type: t.Type(),
})
}
type UnfurledMediaItem struct {
URL string `json:"url"`
}
type Thumbnail struct {
ID int `json:"id,omitempty"`
Description string `json:"description,omitempty"`
Media UnfurledMediaItem `json:"media"`
Spoiler bool `json:"spoiler,omitempty"`
}
func (t *Thumbnail) Type() ComponentType {
return ComponentTypeThumbnail
}
func (t *Thumbnail) MarshalJSON() ([]byte, error) {
type th Thumbnail
return json.Marshal(struct {
th
Type ComponentType `json:"type"`
}{
th: th(*t),
Type: t.Type(),
})
}
type MediaGalleryItem struct {
Media UnfurledMediaItem `json:"media"`
Description string `json:"description,omitempty"`
Spoiler bool `json:"spoiler,omitempty"`
}
type MediaGallery struct {
ID int `json:"id,omitempty"`
Items []MediaGalleryItem `json:"items"`
}
func (m *MediaGallery) Type() ComponentType {
return ComponentTypeMediaGallery
}
func (m *MediaGallery) MarshalJSON() ([]byte, error) {
type mg MediaGallery
return json.Marshal(struct {
mg
Type ComponentType `json:"type"`
}{
mg: mg(*m),
Type: m.Type(),
})
}
type File struct {
ID int `json:"id,omitempty"`
File UnfurledMediaItem `json:"file"`
Spoiler bool `json:"spoiler,omitempty"`
}
func (f *File) Type() ComponentType {
return ComponentTypeFile
}
func (f *File) MarshalJSON() ([]byte, error) {
type fi File
return json.Marshal(struct {
fi
Type ComponentType `json:"type"`
}{
fi: fi(*f),
Type: f.Type(),
})
}
type SeparatorSpacing int
const (
SeparatorSpacingSmall SeparatorSpacing = iota + 1
SeparatorSpacingLarge
)
type Separator struct {
ID int `json:"id,omitempty"`
Divider bool `json:"divider,omitempty"`
Spacing SeparatorSpacing
}
func (s *Separator) Type() ComponentType {
return ComponentTypeSeparator
}
func (s *Separator) MarshalJSON() ([]byte, error) {
type se Separator
return json.Marshal(struct {
se
Type ComponentType `json:"type"`
}{
se: se(*s),
Type: s.Type(),
})
}
type Container struct {
ID int `json:"id,omitempty"`
Components []Component `json:"components"`
AccentColor *int `json:"accent_color,omitempty"`
Spoiler bool `json:"spoiler,omitempty"`
}
func (c *Container) Type() ComponentType {
return ComponentTypeContainer
}
func (c *Container) MarshalJSON() ([]byte, error) {
type co Container
return json.Marshal(struct {
co
Type ComponentType `json:"type"`
}{
co: co(*c),
Type: c.Type(),
})
}