forked from andersfylling/disgord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
channel.go
818 lines (697 loc) · 23 KB
/
channel.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
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
package disgord
import (
"errors"
"strconv"
"strings"
"time"
"github.com/andersfylling/disgord/constant"
)
// Channel types
// https://discordapp.com/developers/docs/resources/channel#channel-object-channel-types
const (
ChannelTypeGuildText uint = iota
ChannelTypeDM
ChannelTypeGuildVoice
ChannelTypeGroupDM
ChannelTypeGuildCategory
)
// Attachment https://discordapp.com/developers/docs/resources/channel#attachment-object
type Attachment struct {
ID Snowflake `json:"id"`
Filename string `json:"filename"`
Size uint `json:"size"`
URL string `json:"url"`
ProxyURL string `json:"proxy_url"`
Height uint `json:"height"`
Width uint `json:"width"`
SpoilerTag bool `json:"-"`
}
func (a *Attachment) updateInternals() {
a.SpoilerTag = strings.HasPrefix(a.Filename, AttachmentSpoilerPrefix)
}
// DeepCopy see interface at struct.go#DeepCopier
func (a *Attachment) DeepCopy() (copy interface{}) {
copy = &Attachment{
ID: a.ID,
Filename: a.Filename,
Size: a.Size,
URL: a.URL,
ProxyURL: a.ProxyURL,
Height: a.Height,
Width: a.Width,
}
return
}
// PermissionOverwrite https://discordapp.com/developers/docs/resources/channel#overwrite-object
type PermissionOverwrite struct {
ID Snowflake `json:"id"` // role or user id
Type string `json:"type"` // either `role` or `member`
Allow int `json:"allow"` // permission bit set
Deny int `json:"deny"` // permission bit set
}
// NewChannel ...
func NewChannel() *Channel {
return &Channel{}
}
// ChannelMessager Methods required to create a new DM (or use an existing one) and send a DM.
// type ChannelMessager interface {CreateMessage(*Message) error}
// ChannelFetcher holds the single method for fetching a channel from the Discord REST API
type ChannelFetcher interface {
GetChannel(id Snowflake) (ret *Channel, err error)
}
// type ChannelDeleter interface { DeleteChannel(id Snowflake) (err error) }
// type ChannelUpdater interface {}
// PartialChannel ...
// example of partial channel
// // "channel": {
// // "id": "165176875973476352",
// // "name": "illuminati",
// // "type": 0
// // }
type PartialChannel struct {
Lockable `json:"-"`
ID Snowflake `json:"id"`
Name string `json:"name"`
Type uint `json:"type"`
}
// Channel ...
type Channel struct {
Lockable `json:"-"`
ID Snowflake `json:"id"`
Type uint `json:"type"`
GuildID Snowflake `json:"guild_id,omitempty"` // ?|
Position uint `json:"position,omitempty"` // ?|
PermissionOverwrites []PermissionOverwrite `json:"permission_overwrites,omitempty"` // ?|
Name string `json:"name,omitempty"` // ?|
Topic string `json:"topic,omitempty"` // ?|?
NSFW bool `json:"nsfw,omitempty"` // ?|
LastMessageID Snowflake `json:"last_message_id,omitempty"` // ?|?
Bitrate uint `json:"bitrate,omitempty"` // ?|
UserLimit uint `json:"user_limit,omitempty"` // ?|
RateLimitPerUser uint `json:"rate_limit_per_user,omitempty"` // ?|
Recipients []*User `json:"recipient,omitempty"` // ?| , empty if not DM/GroupDM
Icon *string `json:"icon,omitempty"` // ?|?
OwnerID Snowflake `json:"owner_id,omitempty"` // ?|
ApplicationID Snowflake `json:"application_id,omitempty"` // ?|
ParentID Snowflake `json:"parent_id,omitempty"` // ?|?
LastPinTimestamp Timestamp `json:"last_pin_timestamp,omitempty"` // ?|
// set to true when the object is not incomplete. Used in situations
// like cacheLink to avoid overwriting correct information.
// A partial or incomplete channel can be
// "channel": {
// "id": "165176875973476352",
// "name": "illuminati",
// "type": 0
// }
complete bool
recipientsIDs []Snowflake
}
func (c *Channel) valid() bool {
if c.RateLimitPerUser > 120 {
return false
}
if len(c.Topic) > 1024 {
return false
}
if c.Name != "" && (len(c.Name) > 100 || len(c.Name) < 2) {
return false
}
return true
}
// Mention creates a channel mention string. Mention format is according the Discord protocol.
func (c *Channel) Mention() string {
return "<#" + c.ID.String() + ">"
}
// Compare checks if channel A is the same as channel B
func (c *Channel) Compare(other *Channel) bool {
// eh
return (c == nil && other == nil) || (other != nil && c.ID == other.ID)
}
func (c *Channel) saveToDiscord(session Session, changes discordSaver) (err error) {
var updated *Channel
// verify discord request
defer func() {
if err != nil {
return
}
*c = *updated
}()
if c.ID.Empty() {
if c.Type != ChannelTypeDM && c.Type != ChannelTypeGroupDM {
// create
if c.Name == "" {
err = newErrorEmptyValue("must have a channel name before creating channel")
}
params := CreateGuildChannelParams{
Name: c.Name,
PermissionOverwrites: c.PermissionOverwrites,
}
// specific
if c.Type == ChannelTypeGuildText {
params.NSFW = c.NSFW
params.Topic = c.Topic
params.RateLimitPerUser = c.RateLimitPerUser
} else if c.Type == ChannelTypeGuildVoice {
params.Bitrate = c.Bitrate
params.UserLimit = c.UserLimit
}
// shared
if c.Type == ChannelTypeGuildVoice || c.Type == ChannelTypeGuildText {
params.ParentID = c.ParentID
}
updated, err = session.CreateGuildChannel(c.GuildID, ¶ms)
} else if c.Type == ChannelTypeDM {
if len(c.Recipients) != 1 {
err = errors.New("must have only one recipient in Channel.Recipient (with ID) for creating a DM. Got " + strconv.Itoa(len(c.Recipients)))
return
}
updated, err = session.CreateDM(c.Recipients[0].ID)
} else if c.Type == ChannelTypeGroupDM {
err = errors.New("creating group DM using SaveToDiscord has not been implemented")
//if len(c.Recipients) == 0 {
// err = errors.New("must have at least one recipient in Channel.Recipient (with access token) for creating a group DM. Got 0")
// return
//}
//total := len(c.Recipients)
//params := CreateGroupDMParams{}
//params.AccessTokens = make([]string, total)
//params.Nicks = make(map[Snowflake]string, total)
//
//for i := 0; i < total; i++ {
// params.AccessTokens[i] = c.Recipients[i].
//}
//
//updated, err = session.CreateGroupDM()
} else {
err = errors.New("cannot save to discord. Does not recognise what needs to be saved")
}
return err
}
return errors.New("updating discord objects are not yet implemented - only saving new ones")
//
//
//// modify / update channel
//changes := ModifyChannelParams{}
//
//// specific
//if c.Type == ChannelTypeDM {
// // nothing to change
//} else if c.Type == ChannelTypeGroupDM {
// // nothing to change
//} else if c.Type == ChannelTypeGuildText {
// changes.SetNSFW(c.NSFW)
// changes.SetTopic(c.Topic)
// changes.SetRateLimitPerUser(c.RateLimitPerUser)
//} else if c.Type == ChannelTypeGuildVoice {
// changes.SetBitrate(c.Bitrate)
// changes.SetUserLimit(c.UserLimit)
//}
//
//// shared
//if c.Type == ChannelTypeGuildVoice || c.Type == ChannelTypeGuildText {
// if c.ParentID.Empty() {
// changes.RemoveParentID()
// } else {
// changes.SetParentID(c.ParentID)
// }
//}
//
//// for all
//changes.SetName(c.Name)
//changes.SetPosition(c.Position)
//changes.SetPermissionOverwrites(c.PermissionOverwrites)
//
//updated, err = session.ModifyChannel(c.ID, &changes)
//return
}
func (c *Channel) deleteFromDiscord(session Session) (err error) {
if c.ID.Empty() {
err = newErrorMissingSnowflake("channel id/snowflake is empty or missing")
return
}
var deleted *Channel
deleted, err = session.DeleteChannel(c.ID)
if err != nil {
return
}
*c = *deleted
return
}
// DeepCopy see interface at struct.go#DeepCopier
func (c *Channel) DeepCopy() (copy interface{}) {
copy = NewChannel()
c.CopyOverTo(copy)
return
}
// CopyOverTo see interface at struct.go#Copier
func (c *Channel) CopyOverTo(other interface{}) (err error) {
var channel *Channel
var valid bool
if channel, valid = other.(*Channel); !valid {
err = newErrorUnsupportedType("argument given is not a *Channel type")
return
}
if constant.LockedMethods {
c.RWMutex.RLock()
channel.RWMutex.Lock()
}
channel.ID = c.ID
channel.Type = c.Type
channel.GuildID = c.GuildID
channel.Position = c.Position
channel.PermissionOverwrites = c.PermissionOverwrites // TODO: check for pointer
channel.Name = c.Name
channel.Topic = c.Topic
channel.NSFW = c.NSFW
channel.LastMessageID = c.LastMessageID
channel.Bitrate = c.Bitrate
channel.UserLimit = c.UserLimit
channel.RateLimitPerUser = c.RateLimitPerUser
channel.Icon = c.Icon
channel.OwnerID = c.OwnerID
channel.ApplicationID = c.ApplicationID
channel.ParentID = c.ParentID
channel.LastPinTimestamp = c.LastPinTimestamp
channel.LastMessageID = c.LastMessageID
// add recipients if it's a DM
for _, recipient := range c.Recipients {
channel.Recipients = append(channel.Recipients, recipient.DeepCopy().(*User))
}
if constant.LockedMethods {
c.RWMutex.RUnlock()
channel.RWMutex.Unlock()
}
return
}
func (c *Channel) copyOverToCache(other interface{}) (err error) {
channel := other.(*Channel)
if constant.LockedMethods {
channel.Lock()
c.RLock()
}
channel.ID = c.ID
channel.Type = c.Type
if c.Type == ChannelTypeGroupDM || c.Type == ChannelTypeDM {
if c.Type == ChannelTypeGroupDM {
channel.Icon = c.Icon
channel.OwnerID = c.OwnerID
channel.Name = c.Name
channel.LastPinTimestamp = c.LastPinTimestamp
}
channel.LastMessageID = c.LastMessageID
if len(c.recipientsIDs) == len(c.Recipients) {
channel.recipientsIDs = c.recipientsIDs
} else {
channel.recipientsIDs = make([]Snowflake, len(c.Recipients))
for i := range c.Recipients {
channel.recipientsIDs[i] = c.Recipients[i].ID
}
}
} else if c.Type == ChannelTypeGuildText {
channel.NSFW = c.NSFW
channel.Name = c.Name
channel.Position = c.Position
channel.PermissionOverwrites = c.PermissionOverwrites
channel.Topic = c.Topic
channel.LastMessageID = c.LastMessageID
channel.RateLimitPerUser = c.RateLimitPerUser
channel.LastPinTimestamp = c.LastPinTimestamp
channel.ParentID = c.ParentID
channel.GuildID = c.GuildID
} else if c.Type == ChannelTypeGuildVoice {
channel.Name = c.Name
channel.Position = c.Position
channel.PermissionOverwrites = c.PermissionOverwrites
channel.ParentID = c.ParentID
channel.Bitrate = c.Bitrate
channel.UserLimit = c.UserLimit
channel.GuildID = c.GuildID
}
// TODO: evaluate
channel.ApplicationID = c.ApplicationID
if constant.LockedMethods {
channel.Unlock()
c.RUnlock()
}
return
}
//func (c *Channel) Clear() {
// // TODO
//}
// Fetch check if there are any updates to the channel values
//func (c *Channel) Fetch(client ChannelFetcher) (err error) {
// if c.ID.Empty() {
// err = errors.New("missing channel ID")
// return
// }
//
// client.GetChannel(c.ID)
//}
// SendMsgString same as SendMsg, however this only takes the message content (string) as a argument for the message
func (c *Channel) SendMsgString(client MessageSender, content string) (msg *Message, err error) {
if c.ID.Empty() {
err = newErrorMissingSnowflake("snowflake ID not set for channel")
return
}
params := &CreateChannelMessageParams{
Content: content,
}
msg, err = client.CreateChannelMessage(c.ID, params)
return
}
// SendMsg sends a message to a channel
func (c *Channel) SendMsg(client MessageSender, message *Message) (msg *Message, err error) {
if c.ID.Empty() {
err = newErrorMissingSnowflake("snowflake ID not set for channel")
return
}
message.RLock()
params := &CreateChannelMessageParams{
Content: message.Content,
Nonce: message.Nonce,
Tts: message.Tts,
// File: ...
// Embed: ...
}
if len(message.Embeds) > 0 {
params.Embed = message.Embeds[0]
}
message.RUnlock()
msg, err = client.CreateChannelMessage(c.ID, params)
return
}
// -----------------
// Embed
// limitations: https://discordapp.com/developers/docs/resources/channel#embed-limits
// TODO: implement NewEmbedX functions that ensures limitations
// ChannelEmbed https://discordapp.com/developers/docs/resources/channel#embed-object
type ChannelEmbed struct {
Lockable `json:"-"`
Title string `json:"title"` // title of embed
Type string `json:"type"` // type of embed (always "rich" for webhook embeds)
Description string `json:"description"` // description of embed
URL string `json:"url"` // url of embed
Timestamp time.Time `json:"timestamp"` // timestamp timestamp of embed content
Color int `json:"color"` // color code of the embed
Footer *ChannelEmbedFooter `json:"footer"` // embed footer object footer information
Image *ChannelEmbedImage `json:"image"` // embed image object image information
Thumbnail *ChannelEmbedThumbnail `json:"thumbnail"` // embed thumbnail object thumbnail information
Video *ChannelEmbedVideo `json:"video"` // embed video object video information
Provider *ChannelEmbedProvider `json:"provider"` // embed provider object provider information
Author *ChannelEmbedAuthor `json:"author"` // embed author object author information
Fields []*ChannelEmbedField `json:"fields"` // array of embed field objects fields information
}
// DeepCopy see interface at struct.go#DeepCopier
func (c *ChannelEmbed) DeepCopy() (copy interface{}) {
copy = &ChannelEmbed{}
c.CopyOverTo(copy)
return
}
// CopyOverTo see interface at struct.go#Copier
func (c *ChannelEmbed) CopyOverTo(other interface{}) (err error) {
var embed *ChannelEmbed
var valid bool
if embed, valid = other.(*ChannelEmbed); !valid {
err = newErrorUnsupportedType("given interface{} is not of type *ChannelEmbed")
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().(*ChannelEmbedFooter)
}
if c.Image != nil {
embed.Image = c.Image.DeepCopy().(*ChannelEmbedImage)
}
if c.Thumbnail != nil {
embed.Thumbnail = c.Thumbnail.DeepCopy().(*ChannelEmbedThumbnail)
}
if c.Video != nil {
embed.Video = c.Video.DeepCopy().(*ChannelEmbedVideo)
}
if c.Provider != nil {
embed.Provider = c.Provider.DeepCopy().(*ChannelEmbedProvider)
}
if c.Author != nil {
embed.Author = c.Author.DeepCopy().(*ChannelEmbedAuthor)
}
embed.Fields = make([]*ChannelEmbedField, len(c.Fields))
for i, field := range c.Fields {
embed.Fields[i] = field.DeepCopy().(*ChannelEmbedField)
}
if constant.LockedMethods {
c.RUnlock()
embed.Unlock()
}
return
}
// ChannelEmbedThumbnail https://discordapp.com/developers/docs/resources/channel#embed-object-embed-thumbnail-structure
type ChannelEmbedThumbnail 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 *ChannelEmbedThumbnail) DeepCopy() (copy interface{}) {
copy = &ChannelEmbedThumbnail{}
c.CopyOverTo(copy)
return
}
// CopyOverTo see interface at struct.go#Copier
func (c *ChannelEmbedThumbnail) CopyOverTo(other interface{}) (err error) {
var embed *ChannelEmbedThumbnail
var valid bool
if embed, valid = other.(*ChannelEmbedThumbnail); !valid {
err = newErrorUnsupportedType("given interface{} is not of type *ChannelEmbedThumbnail")
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
}
// ChannelEmbedVideo https://discordapp.com/developers/docs/resources/channel#embed-object-embed-video-structure
type ChannelEmbedVideo 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 *ChannelEmbedVideo) DeepCopy() (copy interface{}) {
copy = &ChannelEmbedVideo{}
c.CopyOverTo(copy)
return
}
// CopyOverTo see interface at struct.go#Copier
func (c *ChannelEmbedVideo) CopyOverTo(other interface{}) (err error) {
var embed *ChannelEmbedVideo
var valid bool
if embed, valid = other.(*ChannelEmbedVideo); !valid {
err = newErrorUnsupportedType("given interface{} is not of type *ChannelEmbedVideo")
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
}
// ChannelEmbedImage https://discordapp.com/developers/docs/resources/channel#embed-object-embed-image-structure
type ChannelEmbedImage 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 *ChannelEmbedImage) DeepCopy() (copy interface{}) {
copy = &ChannelEmbedImage{}
c.CopyOverTo(copy)
return
}
// CopyOverTo see interface at struct.go#Copier
func (c *ChannelEmbedImage) CopyOverTo(other interface{}) (err error) {
var embed *ChannelEmbedImage
var valid bool
if embed, valid = other.(*ChannelEmbedImage); !valid {
err = newErrorUnsupportedType("given interface{} is not of type *ChannelEmbedImage")
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
}
// ChannelEmbedProvider https://discordapp.com/developers/docs/resources/channel#embed-object-embed-provider-structure
type ChannelEmbedProvider 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 *ChannelEmbedProvider) DeepCopy() (copy interface{}) {
copy = &ChannelEmbedProvider{}
c.CopyOverTo(copy)
return
}
// CopyOverTo see interface at struct.go#Copier
func (c *ChannelEmbedProvider) CopyOverTo(other interface{}) (err error) {
var embed *ChannelEmbedProvider
var valid bool
if embed, valid = other.(*ChannelEmbedProvider); !valid {
err = newErrorUnsupportedType("given interface{} is not of type *ChannelEmbedProvider")
return
}
if constant.LockedMethods {
c.RLock()
embed.Lock()
}
embed.URL = c.URL
embed.Name = c.Name
if constant.LockedMethods {
c.RUnlock()
embed.Unlock()
}
return
}
// ChannelEmbedAuthor https://discordapp.com/developers/docs/resources/channel#embed-object-embed-author-structure
type ChannelEmbedAuthor 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 *ChannelEmbedAuthor) DeepCopy() (copy interface{}) {
copy = &ChannelEmbedAuthor{}
c.CopyOverTo(copy)
return
}
// CopyOverTo see interface at struct.go#Copier
func (c *ChannelEmbedAuthor) CopyOverTo(other interface{}) (err error) {
var embed *ChannelEmbedAuthor
var valid bool
if embed, valid = other.(*ChannelEmbedAuthor); !valid {
err = newErrorUnsupportedType("given interface{} is not of type *ChannelEmbedAuthor")
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
}
// ChannelEmbedFooter https://discordapp.com/developers/docs/resources/channel#embed-object-embed-footer-structure
type ChannelEmbedFooter 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 *ChannelEmbedFooter) DeepCopy() (copy interface{}) {
copy = &ChannelEmbedFooter{}
c.CopyOverTo(copy)
return
}
// CopyOverTo see interface at struct.go#Copier
func (c *ChannelEmbedFooter) CopyOverTo(other interface{}) (err error) {
var embed *ChannelEmbedFooter
var valid bool
if embed, valid = other.(*ChannelEmbedFooter); !valid {
err = newErrorUnsupportedType("given interface{} is not of type *ChannelEmbedFooter")
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
}
// ChannelEmbedField https://discordapp.com/developers/docs/resources/channel#embed-object-embed-field-structure
type ChannelEmbedField struct {
Lockable `json:"-"`
Name string `json:"name"` // | , name of the field
Value string `json:"value"` // | , value of the field
Inline bool `json:"bool,omitempty"` // ?| , whether or not this field should display inline
}
// DeepCopy see interface at struct.go#DeepCopier
func (c *ChannelEmbedField) DeepCopy() (copy interface{}) {
copy = &ChannelEmbedField{}
c.CopyOverTo(copy)
return
}
// CopyOverTo see interface at struct.go#Copier
func (c *ChannelEmbedField) CopyOverTo(other interface{}) (err error) {
var embed *ChannelEmbedField
var valid bool
if embed, valid = other.(*ChannelEmbedField); !valid {
err = newErrorUnsupportedType("given interface{} is not of type *ChannelEmbedField")
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
}