forked from andersfylling/disgord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathembed.go
385 lines (317 loc) · 10.4 KB
/
embed.go
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
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
package disgord
import (
"github.com/andersfylling/disgord/internal/constant"
)
// limitations: https://discord.com/developers/docs/resources/channel#embed-limits
// TODO: implement NewEmbedX functions that ensures limitations
// Embed https://discord.com/developers/docs/resources/channel#embed-object
type Embed struct {
Lockable `json:"-"`
Title string `json:"title,omitempty"` // title of embed
Type string `json:"type,omitempty"` // type of embed (always "rich" for webhook embeds)
Description string `json:"description,omitempty"` // description of embed
URL string `json:"url,omitempty"` // url of embed
Timestamp Time `json:"timestamp,omitempty"` // timestamp timestamp of embed content
Color int `json:"color,omitempty"` // color code of the embed
Footer *EmbedFooter `json:"footer,omitempty"` // embed footer object footer information
Image *EmbedImage `json:"image,omitempty"` // embed image object image information
Thumbnail *EmbedThumbnail `json:"thumbnail,omitempty"` // embed thumbnail object thumbnail information
Video *EmbedVideo `json:"video,omitempty"` // embed video object video information
Provider *EmbedProvider `json:"provider,omitempty"` // embed provider object provider information
Author *EmbedAuthor `json:"author,omitempty"` // embed author object author information
Fields []*EmbedField `json:"fields,omitempty"` // array of embed field objects fields information
}
// DeepCopy see interface at struct.go#DeepCopier
func (c *Embed) DeepCopy() (copy interface{}) {
copy = &Embed{}
c.CopyOverTo(copy)
return
}
// CopyOverTo see interface at struct.go#Copier
func (c *Embed) CopyOverTo(other interface{}) (err error) {
var embed *Embed
var valid bool
if embed, valid = other.(*Embed); !valid {
err = newErrorUnsupportedType("given interface{} is not of type *Embed")
return
}
if constant.LockedMethods {
c.RLock()
embed.Lock()
}
embed.Title = c.Title
embed.Type = c.Type
embed.Description = c.Description
embed.URL = c.URL
embed.Timestamp = c.Timestamp
embed.Color = c.Color
if c.Footer != nil {
embed.Footer = c.Footer.DeepCopy().(*EmbedFooter)
}
if c.Image != nil {
embed.Image = c.Image.DeepCopy().(*EmbedImage)
}
if c.Thumbnail != nil {
embed.Thumbnail = c.Thumbnail.DeepCopy().(*EmbedThumbnail)
}
if c.Video != nil {
embed.Video = c.Video.DeepCopy().(*EmbedVideo)
}
if c.Provider != nil {
embed.Provider = c.Provider.DeepCopy().(*EmbedProvider)
}
if c.Author != nil {
embed.Author = c.Author.DeepCopy().(*EmbedAuthor)
}
embed.Fields = make([]*EmbedField, len(c.Fields))
for i, field := range c.Fields {
embed.Fields[i] = field.DeepCopy().(*EmbedField)
}
if constant.LockedMethods {
c.RUnlock()
embed.Unlock()
}
return nil
}
// EmbedThumbnail https://discord.com/developers/docs/resources/channel#embed-object-embed-thumbnail-structure
type EmbedThumbnail struct {
Lockable `json:"-"`
URL string `json:"url,omitempty"` // ?| , source url of image (only supports http(s) and attachments)
ProxyURL string `json:"proxy_url,omitempty"` // ?| , a proxied url of the image
Height int `json:"height,omitempty"` // ?| , height of image
Width int `json:"width,omitempty"` // ?| , width of image
}
// DeepCopy see interface at struct.go#DeepCopier
func (c *EmbedThumbnail) DeepCopy() (copy interface{}) {
copy = &EmbedThumbnail{}
c.CopyOverTo(copy)
return
}
// CopyOverTo see interface at struct.go#Copier
func (c *EmbedThumbnail) CopyOverTo(other interface{}) (err error) {
var embed *EmbedThumbnail
var valid bool
if embed, valid = other.(*EmbedThumbnail); !valid {
err = newErrorUnsupportedType("given interface{} is not of type *EmbedThumbnail")
return
}
if constant.LockedMethods {
c.RLock()
embed.Lock()
}
embed.URL = c.URL
embed.ProxyURL = c.ProxyURL
embed.Height = c.Height
embed.Width = c.Width
if constant.LockedMethods {
c.RUnlock()
embed.Unlock()
}
return
}
// EmbedVideo https://discord.com/developers/docs/resources/channel#embed-object-embed-video-structure
type EmbedVideo struct {
Lockable `json:"-"`
URL string `json:"url,omitempty"` // ?| , source url of video
Height int `json:"height,omitempty"` // ?| , height of video
Width int `json:"width,omitempty"` // ?| , width of video
}
// DeepCopy see interface at struct.go#DeepCopier
func (c *EmbedVideo) DeepCopy() (copy interface{}) {
copy = &EmbedVideo{}
c.CopyOverTo(copy)
return
}
// CopyOverTo see interface at struct.go#Copier
func (c *EmbedVideo) CopyOverTo(other interface{}) (err error) {
var embed *EmbedVideo
var valid bool
if embed, valid = other.(*EmbedVideo); !valid {
err = newErrorUnsupportedType("given interface{} is not of type *EmbedVideo")
return
}
if constant.LockedMethods {
c.RLock()
embed.Lock()
}
embed.URL = c.URL
embed.Height = c.Height
embed.Width = c.Width
if constant.LockedMethods {
c.RUnlock()
embed.Unlock()
}
return nil
}
// EmbedImage https://discord.com/developers/docs/resources/channel#embed-object-embed-image-structure
type EmbedImage struct {
Lockable `json:"-"`
URL string `json:"url,omitempty"` // ?| , source url of image (only supports http(s) and attachments)
ProxyURL string `json:"proxy_url,omitempty"` // ?| , a proxied url of the image
Height int `json:"height,omitempty"` // ?| , height of image
Width int `json:"width,omitempty"` // ?| , width of image
}
// DeepCopy see interface at struct.go#DeepCopier
func (c *EmbedImage) DeepCopy() (copy interface{}) {
copy = &EmbedImage{}
c.CopyOverTo(copy)
return
}
// CopyOverTo see interface at struct.go#Copier
func (c *EmbedImage) CopyOverTo(other interface{}) (err error) {
var embed *EmbedImage
var valid bool
if embed, valid = other.(*EmbedImage); !valid {
err = newErrorUnsupportedType("given interface{} is not of type *EmbedImage")
return
}
if constant.LockedMethods {
c.RLock()
embed.Lock()
}
embed.URL = c.URL
embed.ProxyURL = c.ProxyURL
embed.Height = c.Height
embed.Width = c.Width
if constant.LockedMethods {
c.RUnlock()
embed.Unlock()
}
return nil
}
// EmbedProvider https://discord.com/developers/docs/resources/channel#embed-object-embed-provider-structure
type EmbedProvider struct {
Lockable `json:"-"`
Name string `json:"name,omitempty"` // ?| , name of provider
URL string `json:"url,omitempty"` // ?| , url of provider
}
// DeepCopy see interface at struct.go#DeepCopier
func (c *EmbedProvider) DeepCopy() (copy interface{}) {
copy = &EmbedProvider{}
c.CopyOverTo(copy)
return
}
// CopyOverTo see interface at struct.go#Copier
func (c *EmbedProvider) CopyOverTo(other interface{}) (err error) {
var embed *EmbedProvider
var valid bool
if embed, valid = other.(*EmbedProvider); !valid {
err = newErrorUnsupportedType("given interface{} is not of type *EmbedProvider")
return
}
if constant.LockedMethods {
c.RLock()
embed.Lock()
}
embed.URL = c.URL
embed.Name = c.Name
if constant.LockedMethods {
c.RUnlock()
embed.Unlock()
}
return nil
}
// EmbedAuthor https://discord.com/developers/docs/resources/channel#embed-object-embed-author-structure
type EmbedAuthor struct {
Lockable `json:"-"`
Name string `json:"name,omitempty"` // ?| , name of author
URL string `json:"url,omitempty"` // ?| , url of author
IconURL string `json:"icon_url,omitempty"` // ?| , url of author icon (only supports http(s) and attachments)
ProxyIconURL string `json:"proxy_icon_url,omitempty"` // ?| , a proxied url of author icon
}
// DeepCopy see interface at struct.go#DeepCopier
func (c *EmbedAuthor) DeepCopy() (copy interface{}) {
copy = &EmbedAuthor{}
c.CopyOverTo(copy)
return
}
// CopyOverTo see interface at struct.go#Copier
func (c *EmbedAuthor) CopyOverTo(other interface{}) (err error) {
var embed *EmbedAuthor
var valid bool
if embed, valid = other.(*EmbedAuthor); !valid {
err = newErrorUnsupportedType("given interface{} is not of type *EmbedAuthor")
return
}
if constant.LockedMethods {
c.RLock()
embed.Lock()
}
embed.Name = c.Name
embed.URL = c.URL
embed.IconURL = c.IconURL
embed.ProxyIconURL = c.ProxyIconURL
if constant.LockedMethods {
c.RUnlock()
embed.Unlock()
}
return nil
}
// EmbedFooter https://discord.com/developers/docs/resources/channel#embed-object-embed-footer-structure
type EmbedFooter struct {
Lockable `json:"-"`
Text string `json:"text"` // | , url of author
IconURL string `json:"icon_url,omitempty"` // ?| , url of footer icon (only supports http(s) and attachments)
ProxyIconURL string `json:"proxy_icon_url,omitempty"` // ?| , a proxied url of footer icon
}
// DeepCopy see interface at struct.go#DeepCopier
func (c *EmbedFooter) DeepCopy() (copy interface{}) {
copy = &EmbedFooter{}
c.CopyOverTo(copy)
return
}
// CopyOverTo see interface at struct.go#Copier
func (c *EmbedFooter) CopyOverTo(other interface{}) (err error) {
var embed *EmbedFooter
var valid bool
if embed, valid = other.(*EmbedFooter); !valid {
err = newErrorUnsupportedType("given interface{} is not of type *EmbedFooter")
return
}
if constant.LockedMethods {
c.RLock()
embed.Lock()
}
embed.Text = c.Text
embed.IconURL = c.IconURL
embed.ProxyIconURL = c.ProxyIconURL
if constant.LockedMethods {
c.RUnlock()
embed.Unlock()
}
return nil
}
// EmbedField https://discord.com/developers/docs/resources/channel#embed-object-embed-field-structure
type EmbedField struct {
Lockable `json:"-"`
Name string `json:"name"` // | , name of the field
Value string `json:"value"` // | , value of the field
Inline bool `json:"inline,omitempty"` // ?| , whether or not this field should display inline
}
// DeepCopy see interface at struct.go#DeepCopier
func (c *EmbedField) DeepCopy() (copy interface{}) {
copy = &EmbedField{}
c.CopyOverTo(copy)
return
}
// CopyOverTo see interface at struct.go#Copier
func (c *EmbedField) CopyOverTo(other interface{}) (err error) {
var embed *EmbedField
var valid bool
if embed, valid = other.(*EmbedField); !valid {
err = newErrorUnsupportedType("given interface{} is not of type *EmbedField")
return
}
if constant.LockedMethods {
c.RLock()
embed.Lock()
}
embed.Name = c.Name
embed.Value = c.Value
embed.Inline = c.Inline
if constant.LockedMethods {
c.RUnlock()
embed.Unlock()
}
return nil
}