forked from bwmarrin/discordgo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
structs.go
2463 lines (2097 loc) · 103 KB
/
structs.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
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// Discordgo - Discord bindings for Go
// Available at https://github.com/bwmarrin/discordgo
// Copyright 2015-2016 Bruce Marriner <bruce@sqls.net>. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// This file contains all structures for the discordgo package. These
// may be moved about later into separate files but I find it easier to have
// them all located together.
package discordgo
import (
"encoding/json"
"fmt"
"math"
"net/http"
"regexp"
"sync"
"time"
"github.com/gorilla/websocket"
)
// A Session represents a connection to the Discord API.
type Session struct {
sync.RWMutex
// General configurable settings.
// Authentication token for this session
// TODO: Remove Below, Deprecated, Use Identify struct
Token string
MFA bool
// Debug for printing JSON request/responses
Debug bool // Deprecated, will be removed.
LogLevel int
// Should the session reconnect the websocket on errors.
ShouldReconnectOnError bool
// Should voice connections reconnect on a session reconnect.
ShouldReconnectVoiceOnSessionError bool
// Should the session retry requests when rate limited.
ShouldRetryOnRateLimit bool
// Identify is sent during initial handshake with the discord gateway.
// https://discord.com/developers/docs/topics/gateway#identify
Identify Identify
// TODO: Remove Below, Deprecated, Use Identify struct
// Should the session request compressed websocket data.
Compress bool
// Sharding
ShardID int
ShardCount int
// Should state tracking be enabled.
// State tracking is the best way for getting the users
// active guilds and the members of the guilds.
StateEnabled bool
// Whether or not to call event handlers synchronously.
// e.g. false = launch event handlers in their own goroutines.
SyncEvents bool
// Exposed but should not be modified by User.
// Whether the Data Websocket is ready
DataReady bool // NOTE: Maye be deprecated soon
// Max number of REST API retries
MaxRestRetries int
// Status stores the current status of the websocket connection
// this is being tested, may stay, may go away.
status int32
// Whether the Voice Websocket is ready
VoiceReady bool // NOTE: Deprecated.
// Whether the UDP Connection is ready
UDPReady bool // NOTE: Deprecated
// Stores a mapping of guild id's to VoiceConnections
VoiceConnections map[string]*VoiceConnection
// Managed state object, updated internally with events when
// StateEnabled is true.
State *State
// The http client used for REST requests
Client *http.Client
// The dialer used for WebSocket connection
Dialer *websocket.Dialer
// The user agent used for REST APIs
UserAgent string
// Stores the last HeartbeatAck that was received (in UTC)
LastHeartbeatAck time.Time
// Stores the last Heartbeat sent (in UTC)
LastHeartbeatSent time.Time
// used to deal with rate limits
Ratelimiter *RateLimiter
// Event handlers
handlersMu sync.RWMutex
handlers map[string][]*eventHandlerInstance
onceHandlers map[string][]*eventHandlerInstance
// The websocket connection.
wsConn *websocket.Conn
// When nil, the session is not listening.
listening chan interface{}
// sequence tracks the current gateway api websocket sequence number
sequence *int64
// stores sessions current Discord Gateway
gateway string
// stores session ID of current Gateway connection
sessionID string
// used to make sure gateway websocket writes do not happen concurrently
wsMutex sync.Mutex
}
// Application stores values for a Discord Application
type Application struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Icon string `json:"icon,omitempty"`
Description string `json:"description,omitempty"`
RPCOrigins []string `json:"rpc_origins,omitempty"`
BotPublic bool `json:"bot_public,omitempty"`
BotRequireCodeGrant bool `json:"bot_require_code_grant,omitempty"`
TermsOfServiceURL string `json:"terms_of_service_url"`
PrivacyProxyURL string `json:"privacy_policy_url"`
Owner *User `json:"owner"`
Summary string `json:"summary"`
VerifyKey string `json:"verify_key"`
Team *Team `json:"team"`
GuildID string `json:"guild_id"`
PrimarySKUID string `json:"primary_sku_id"`
Slug string `json:"slug"`
CoverImage string `json:"cover_image"`
Flags int `json:"flags,omitempty"`
}
// ApplicationRoleConnectionMetadataType represents the type of application role connection metadata.
type ApplicationRoleConnectionMetadataType int
// Application role connection metadata types.
const (
ApplicationRoleConnectionMetadataIntegerLessThanOrEqual ApplicationRoleConnectionMetadataType = 1
ApplicationRoleConnectionMetadataIntegerGreaterThanOrEqual ApplicationRoleConnectionMetadataType = 2
ApplicationRoleConnectionMetadataIntegerEqual ApplicationRoleConnectionMetadataType = 3
ApplicationRoleConnectionMetadataIntegerNotEqual ApplicationRoleConnectionMetadataType = 4
ApplicationRoleConnectionMetadataDatetimeLessThanOrEqual ApplicationRoleConnectionMetadataType = 5
ApplicationRoleConnectionMetadataDatetimeGreaterThanOrEqual ApplicationRoleConnectionMetadataType = 6
ApplicationRoleConnectionMetadataBooleanEqual ApplicationRoleConnectionMetadataType = 7
ApplicationRoleConnectionMetadataBooleanNotEqual ApplicationRoleConnectionMetadataType = 8
)
// ApplicationRoleConnectionMetadata stores application role connection metadata.
type ApplicationRoleConnectionMetadata struct {
Type ApplicationRoleConnectionMetadataType `json:"type"`
Key string `json:"key"`
Name string `json:"name"`
NameLocalizations map[Locale]string `json:"name_localizations"`
Description string `json:"description"`
DescriptionLocalizations map[Locale]string `json:"description_localizations"`
}
// ApplicationRoleConnection represents the role connection that an application has attached to a user.
type ApplicationRoleConnection struct {
PlatformName string `json:"platform_name"`
PlatformUsername string `json:"platform_username"`
Metadata map[string]string `json:"metadata"`
}
// UserConnection is a Connection returned from the UserConnections endpoint
type UserConnection struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Revoked bool `json:"revoked"`
Integrations []*Integration `json:"integrations"`
}
// Integration stores integration information
type Integration struct {
ID string `json:"id"`
Name string `json:"name"`
Type string `json:"type"`
Enabled bool `json:"enabled"`
Syncing bool `json:"syncing"`
RoleID string `json:"role_id"`
EnableEmoticons bool `json:"enable_emoticons"`
ExpireBehavior ExpireBehavior `json:"expire_behavior"`
ExpireGracePeriod int `json:"expire_grace_period"`
User *User `json:"user"`
Account IntegrationAccount `json:"account"`
SyncedAt time.Time `json:"synced_at"`
}
// ExpireBehavior of Integration
// https://discord.com/developers/docs/resources/guild#integration-object-integration-expire-behaviors
type ExpireBehavior int
// Block of valid ExpireBehaviors
const (
ExpireBehaviorRemoveRole ExpireBehavior = 0
ExpireBehaviorKick ExpireBehavior = 1
)
// IntegrationAccount is integration account information
// sent by the UserConnections endpoint
type IntegrationAccount struct {
ID string `json:"id"`
Name string `json:"name"`
}
// A VoiceRegion stores data for a specific voice region server.
type VoiceRegion struct {
ID string `json:"id"`
Name string `json:"name"`
}
// InviteTargetType indicates the type of target of an invite
// https://discord.com/developers/docs/resources/invite#invite-object-invite-target-types
type InviteTargetType uint8
// Invite target types
const (
InviteTargetStream InviteTargetType = 1
InviteTargetEmbeddedApplication InviteTargetType = 2
)
// A Invite stores all data related to a specific Discord Guild or Channel invite.
type Invite struct {
Guild *Guild `json:"guild"`
Channel *Channel `json:"channel"`
Inviter *User `json:"inviter"`
Code string `json:"code"`
CreatedAt time.Time `json:"created_at"`
MaxAge int `json:"max_age"`
Uses int `json:"uses"`
MaxUses int `json:"max_uses"`
Revoked bool `json:"revoked"`
Temporary bool `json:"temporary"`
Unique bool `json:"unique"`
TargetUser *User `json:"target_user"`
TargetType InviteTargetType `json:"target_type"`
TargetApplication *Application `json:"target_application"`
// will only be filled when using InviteWithCounts
ApproximatePresenceCount int `json:"approximate_presence_count"`
ApproximateMemberCount int `json:"approximate_member_count"`
ExpiresAt *time.Time `json:"expires_at"`
}
// ChannelType is the type of a Channel
type ChannelType int
// Block contains known ChannelType values
const (
ChannelTypeGuildText ChannelType = 0
ChannelTypeDM ChannelType = 1
ChannelTypeGuildVoice ChannelType = 2
ChannelTypeGroupDM ChannelType = 3
ChannelTypeGuildCategory ChannelType = 4
ChannelTypeGuildNews ChannelType = 5
ChannelTypeGuildStore ChannelType = 6
ChannelTypeGuildNewsThread ChannelType = 10
ChannelTypeGuildPublicThread ChannelType = 11
ChannelTypeGuildPrivateThread ChannelType = 12
ChannelTypeGuildStageVoice ChannelType = 13
ChannelTypeGuildForum ChannelType = 15
)
// ChannelFlags represent flags of a channel/thread.
type ChannelFlags int
// Block containing known ChannelFlags values.
const (
// ChannelFlagPinned indicates whether the thread is pinned in the forum channel.
// NOTE: forum threads only.
ChannelFlagPinned ChannelFlags = 1 << 1
// ChannelFlagRequireTag indicates whether a tag is required to be specified when creating a thread.
// NOTE: forum channels only.
ChannelFlagRequireTag ChannelFlags = 1 << 4
)
// ForumSortOrderType represents sort order of a forum channel.
type ForumSortOrderType int
const (
// ForumSortOrderLatestActivity sorts posts by activity.
ForumSortOrderLatestActivity ForumSortOrderType = 0
// ForumSortOrderCreationDate sorts posts by creation time (from most recent to oldest).
ForumSortOrderCreationDate ForumSortOrderType = 1
)
// ForumLayout represents layout of a forum channel.
type ForumLayout int
const (
// ForumLayoutNotSet represents no default layout.
ForumLayoutNotSet ForumLayout = 0
// ForumLayoutListView displays forum posts as a list.
ForumLayoutListView ForumLayout = 1
// ForumLayoutGalleryView displays forum posts as a collection of tiles.
ForumLayoutGalleryView ForumLayout = 2
)
// A Channel holds all data related to an individual Discord channel.
type Channel struct {
// The ID of the channel.
ID string `json:"id"`
// The ID of the guild to which the channel belongs, if it is in a guild.
// Else, this ID is empty (e.g. DM channels).
GuildID string `json:"guild_id"`
// The name of the channel.
Name string `json:"name"`
// The topic of the channel.
Topic string `json:"topic"`
// The type of the channel.
Type ChannelType `json:"type"`
// The ID of the last message sent in the channel. This is not
// guaranteed to be an ID of a valid message.
LastMessageID string `json:"last_message_id"`
// The timestamp of the last pinned message in the channel.
// nil if the channel has no pinned messages.
LastPinTimestamp *time.Time `json:"last_pin_timestamp"`
// An approximate count of messages in a thread, stops counting at 50
MessageCount int `json:"message_count"`
// An approximate count of users in a thread, stops counting at 50
MemberCount int `json:"member_count"`
// Whether the channel is marked as NSFW.
NSFW bool `json:"nsfw"`
// Icon of the group DM channel.
Icon string `json:"icon"`
// The position of the channel, used for sorting in client.
Position int `json:"position"`
// The bitrate of the channel, if it is a voice channel.
Bitrate int `json:"bitrate"`
// The recipients of the channel. This is only populated in DM channels.
Recipients []*User `json:"recipients"`
// The messages in the channel. This is only present in state-cached channels,
// and State.MaxMessageCount must be non-zero.
Messages []*Message `json:"-"`
// A list of permission overwrites present for the channel.
PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites"`
// The user limit of the voice channel.
UserLimit int `json:"user_limit"`
// The ID of the parent channel, if the channel is under a category. For threads - id of the channel thread was created in.
ParentID string `json:"parent_id"`
// Amount of seconds a user has to wait before sending another message or creating another thread (0-21600)
// bots, as well as users with the permission manage_messages or manage_channel, are unaffected
RateLimitPerUser int `json:"rate_limit_per_user"`
// ID of the creator of the group DM or thread
OwnerID string `json:"owner_id"`
// ApplicationID of the DM creator Zeroed if guild channel or not a bot user
ApplicationID string `json:"application_id"`
// Thread-specific fields not needed by other channels
ThreadMetadata *ThreadMetadata `json:"thread_metadata,omitempty"`
// Thread member object for the current user, if they have joined the thread, only included on certain API endpoints
Member *ThreadMember `json:"thread_member"`
// All thread members. State channels only.
Members []*ThreadMember `json:"-"`
// Channel flags.
Flags ChannelFlags `json:"flags"`
// The set of tags that can be used in a forum channel.
AvailableTags []ForumTag `json:"available_tags"`
// The IDs of the set of tags that have been applied to a thread in a forum channel.
AppliedTags []string `json:"applied_tags"`
// Emoji to use as the default reaction to a forum post.
DefaultReactionEmoji ForumDefaultReaction `json:"default_reaction_emoji"`
// The initial RateLimitPerUser to set on newly created threads in a channel.
// This field is copied to the thread at creation time and does not live update.
DefaultThreadRateLimitPerUser int `json:"default_thread_rate_limit_per_user"`
// The default sort order type used to order posts in forum channels.
// Defaults to null, which indicates a preferred sort order hasn't been set by a channel admin.
DefaultSortOrder *ForumSortOrderType `json:"default_sort_order"`
// The default forum layout view used to display posts in forum channels.
// Defaults to ForumLayoutNotSet, which indicates a layout view has not been set by a channel admin.
DefaultForumLayout ForumLayout `json:"default_forum_layout"`
}
// Mention returns a string which mentions the channel
func (c *Channel) Mention() string {
return fmt.Sprintf("<#%s>", c.ID)
}
// IsThread is a helper function to determine if channel is a thread or not
func (c *Channel) IsThread() bool {
return c.Type == ChannelTypeGuildPublicThread || c.Type == ChannelTypeGuildPrivateThread || c.Type == ChannelTypeGuildNewsThread
}
// A ChannelEdit holds Channel Field data for a channel edit.
type ChannelEdit struct {
Name string `json:"name,omitempty"`
Topic string `json:"topic,omitempty"`
NSFW *bool `json:"nsfw,omitempty"`
Position *int `json:"position,omitempty"`
Bitrate int `json:"bitrate,omitempty"`
UserLimit int `json:"user_limit,omitempty"`
PermissionOverwrites []*PermissionOverwrite `json:"permission_overwrites,omitempty"`
ParentID string `json:"parent_id,omitempty"`
RateLimitPerUser *int `json:"rate_limit_per_user,omitempty"`
Flags *ChannelFlags `json:"flags,omitempty"`
DefaultThreadRateLimitPerUser *int `json:"default_thread_rate_limit_per_user,omitempty"`
// NOTE: threads only
Archived *bool `json:"archived,omitempty"`
AutoArchiveDuration int `json:"auto_archive_duration,omitempty"`
Locked *bool `json:"locked,omitempty"`
Invitable *bool `json:"invitable,omitempty"`
// NOTE: forum channels only
AvailableTags *[]ForumTag `json:"available_tags,omitempty"`
DefaultReactionEmoji *ForumDefaultReaction `json:"default_reaction_emoji,omitempty"`
DefaultSortOrder *ForumSortOrderType `json:"default_sort_order,omitempty"` // TODO: null
DefaultForumLayout *ForumLayout `json:"default_forum_layout,omitempty"`
// NOTE: forum threads only
AppliedTags *[]string `json:"applied_tags,omitempty"`
}
// A ChannelFollow holds data returned after following a news channel
type ChannelFollow struct {
ChannelID string `json:"channel_id"`
WebhookID string `json:"webhook_id"`
}
// PermissionOverwriteType represents the type of resource on which
// a permission overwrite acts.
type PermissionOverwriteType int
// The possible permission overwrite types.
const (
PermissionOverwriteTypeRole PermissionOverwriteType = 0
PermissionOverwriteTypeMember PermissionOverwriteType = 1
)
// A PermissionOverwrite holds permission overwrite data for a Channel
type PermissionOverwrite struct {
ID string `json:"id"`
Type PermissionOverwriteType `json:"type"`
Deny int64 `json:"deny,string"`
Allow int64 `json:"allow,string"`
}
// ThreadStart stores all parameters you can use with MessageThreadStartComplex or ThreadStartComplex
type ThreadStart struct {
Name string `json:"name"`
AutoArchiveDuration int `json:"auto_archive_duration,omitempty"`
Type ChannelType `json:"type,omitempty"`
Invitable bool `json:"invitable"`
RateLimitPerUser int `json:"rate_limit_per_user,omitempty"`
// NOTE: forum threads only
AppliedTags []string `json:"applied_tags,omitempty"`
}
// ThreadMetadata contains a number of thread-specific channel fields that are not needed by other channel types.
type ThreadMetadata struct {
// Whether the thread is archived
Archived bool `json:"archived"`
// Duration in minutes to automatically archive the thread after recent activity, can be set to: 60, 1440, 4320, 10080
AutoArchiveDuration int `json:"auto_archive_duration"`
// Timestamp when the thread's archive status was last changed, used for calculating recent activity
ArchiveTimestamp time.Time `json:"archive_timestamp"`
// Whether the thread is locked; when a thread is locked, only users with MANAGE_THREADS can unarchive it
Locked bool `json:"locked"`
// Whether non-moderators can add other non-moderators to a thread; only available on private threads
Invitable bool `json:"invitable"`
}
// ThreadMember is used to indicate whether a user has joined a thread or not.
// NOTE: ID and UserID are empty (omitted) on the member sent within each thread in the GUILD_CREATE event.
type ThreadMember struct {
// The id of the thread
ID string `json:"id,omitempty"`
// The id of the user
UserID string `json:"user_id,omitempty"`
// The time the current user last joined the thread
JoinTimestamp time.Time `json:"join_timestamp"`
// Any user-thread settings, currently only used for notifications
Flags int `json:"flags"`
// Additional information about the user.
// NOTE: only present if the withMember parameter is set to true
// when calling Session.ThreadMembers or Session.ThreadMember.
Member *Member `json:"member,omitempty"`
}
// ThreadsList represents a list of threads alongisde with thread member objects for the current user.
type ThreadsList struct {
Threads []*Channel `json:"threads"`
Members []*ThreadMember `json:"members"`
HasMore bool `json:"has_more"`
}
// AddedThreadMember holds information about the user who was added to the thread
type AddedThreadMember struct {
*ThreadMember
Member *Member `json:"member"`
Presence *Presence `json:"presence"`
}
// ForumDefaultReaction specifies emoji to use as the default reaction to a forum post.
// NOTE: Exactly one of EmojiID and EmojiName must be set.
type ForumDefaultReaction struct {
// The id of a guild's custom emoji.
EmojiID string `json:"emoji_id,omitempty"`
// The unicode character of the emoji.
EmojiName string `json:"emoji_name,omitempty"`
}
// ForumTag represents a tag that is able to be applied to a thread in a forum channel.
type ForumTag struct {
ID string `json:"id,omitempty"`
Name string `json:"name"`
Moderated bool `json:"moderated"`
EmojiID string `json:"emoji_id,omitempty"`
EmojiName string `json:"emoji_name,omitempty"`
}
// Emoji struct holds data related to Emoji's
type Emoji struct {
ID string `json:"id"`
Name string `json:"name"`
Roles []string `json:"roles"`
User *User `json:"user"`
RequireColons bool `json:"require_colons"`
Managed bool `json:"managed"`
Animated bool `json:"animated"`
Available bool `json:"available"`
}
// EmojiRegex is the regex used to find and identify emojis in messages
var (
EmojiRegex = regexp.MustCompile(`<(a|):[A-z0-9_~]+:[0-9]{18,20}>`)
)
// MessageFormat returns a correctly formatted Emoji for use in Message content and embeds
func (e *Emoji) MessageFormat() string {
if e.ID != "" && e.Name != "" {
if e.Animated {
return "<a:" + e.APIName() + ">"
}
return "<:" + e.APIName() + ">"
}
return e.APIName()
}
// APIName returns an correctly formatted API name for use in the MessageReactions endpoints.
func (e *Emoji) APIName() string {
if e.ID != "" && e.Name != "" {
return e.Name + ":" + e.ID
}
if e.Name != "" {
return e.Name
}
return e.ID
}
// EmojiParams represents parameters needed to create or update an Emoji.
type EmojiParams struct {
// Name of the emoji
Name string `json:"name,omitempty"`
// A base64 encoded emoji image, has to be smaller than 256KB.
// NOTE: can be only set on creation.
Image string `json:"image,omitempty"`
// Roles for which this emoji will be available.
Roles []string `json:"roles,omitempty"`
}
// StickerFormat is the file format of the Sticker.
type StickerFormat int
// Defines all known Sticker types.
const (
StickerFormatTypePNG StickerFormat = 1
StickerFormatTypeAPNG StickerFormat = 2
StickerFormatTypeLottie StickerFormat = 3
StickerFormatTypeGIF StickerFormat = 4
)
// StickerType is the type of sticker.
type StickerType int
// Defines Sticker types.
const (
StickerTypeStandard StickerType = 1
StickerTypeGuild StickerType = 2
)
// Sticker represents a sticker object that can be sent in a Message.
type Sticker struct {
ID string `json:"id"`
PackID string `json:"pack_id"`
Name string `json:"name"`
Description string `json:"description"`
Tags string `json:"tags"`
Type StickerType `json:"type"`
FormatType StickerFormat `json:"format_type"`
Available bool `json:"available"`
GuildID string `json:"guild_id"`
User *User `json:"user"`
SortValue int `json:"sort_value"`
}
// StickerPack represents a pack of standard stickers.
type StickerPack struct {
ID string `json:"id"`
Stickers []*Sticker `json:"stickers"`
Name string `json:"name"`
SKUID string `json:"sku_id"`
CoverStickerID string `json:"cover_sticker_id"`
Description string `json:"description"`
BannerAssetID string `json:"banner_asset_id"`
}
// VerificationLevel type definition
type VerificationLevel int
// Constants for VerificationLevel levels from 0 to 4 inclusive
const (
VerificationLevelNone VerificationLevel = 0
VerificationLevelLow VerificationLevel = 1
VerificationLevelMedium VerificationLevel = 2
VerificationLevelHigh VerificationLevel = 3
VerificationLevelVeryHigh VerificationLevel = 4
)
// ExplicitContentFilterLevel type definition
type ExplicitContentFilterLevel int
// Constants for ExplicitContentFilterLevel levels from 0 to 2 inclusive
const (
ExplicitContentFilterDisabled ExplicitContentFilterLevel = 0
ExplicitContentFilterMembersWithoutRoles ExplicitContentFilterLevel = 1
ExplicitContentFilterAllMembers ExplicitContentFilterLevel = 2
)
// GuildNSFWLevel type definition
type GuildNSFWLevel int
// Constants for GuildNSFWLevel levels from 0 to 3 inclusive
const (
GuildNSFWLevelDefault GuildNSFWLevel = 0
GuildNSFWLevelExplicit GuildNSFWLevel = 1
GuildNSFWLevelSafe GuildNSFWLevel = 2
GuildNSFWLevelAgeRestricted GuildNSFWLevel = 3
)
// MfaLevel type definition
type MfaLevel int
// Constants for MfaLevel levels from 0 to 1 inclusive
const (
MfaLevelNone MfaLevel = 0
MfaLevelElevated MfaLevel = 1
)
// PremiumTier type definition
type PremiumTier int
// Constants for PremiumTier levels from 0 to 3 inclusive
const (
PremiumTierNone PremiumTier = 0
PremiumTier1 PremiumTier = 1
PremiumTier2 PremiumTier = 2
PremiumTier3 PremiumTier = 3
)
// A Guild holds all data related to a specific Discord Guild. Guilds are also
// sometimes referred to as Servers in the Discord client.
type Guild struct {
// The ID of the guild.
ID string `json:"id"`
// The name of the guild. (2–100 characters)
Name string `json:"name"`
// The hash of the guild's icon. Use Session.GuildIcon
// to retrieve the icon itself.
Icon string `json:"icon"`
// The voice region of the guild.
Region string `json:"region"`
// The ID of the AFK voice channel.
AfkChannelID string `json:"afk_channel_id"`
// The user ID of the owner of the guild.
OwnerID string `json:"owner_id"`
// If we are the owner of the guild
Owner bool `json:"owner"`
// The time at which the current user joined the guild.
// This field is only present in GUILD_CREATE events and websocket
// update events, and thus is only present in state-cached guilds.
JoinedAt time.Time `json:"joined_at"`
// The hash of the guild's discovery splash.
DiscoverySplash string `json:"discovery_splash"`
// The hash of the guild's splash.
Splash string `json:"splash"`
// The timeout, in seconds, before a user is considered AFK in voice.
AfkTimeout int `json:"afk_timeout"`
// The number of members in the guild.
// This field is only present in GUILD_CREATE events and websocket
// update events, and thus is only present in state-cached guilds.
MemberCount int `json:"member_count"`
// The verification level required for the guild.
VerificationLevel VerificationLevel `json:"verification_level"`
// Whether the guild is considered large. This is
// determined by a member threshold in the identify packet,
// and is currently hard-coded at 250 members in the library.
Large bool `json:"large"`
// The default message notification setting for the guild.
DefaultMessageNotifications MessageNotifications `json:"default_message_notifications"`
// A list of roles in the guild.
Roles []*Role `json:"roles"`
// A list of the custom emojis present in the guild.
Emojis []*Emoji `json:"emojis"`
// A list of the custom stickers present in the guild.
Stickers []*Sticker `json:"stickers"`
// A list of the members in the guild.
// This field is only present in GUILD_CREATE events and websocket
// update events, and thus is only present in state-cached guilds.
Members []*Member `json:"members"`
// A list of partial presence objects for members in the guild.
// This field is only present in GUILD_CREATE events and websocket
// update events, and thus is only present in state-cached guilds.
Presences []*Presence `json:"presences"`
// The maximum number of presences for the guild (the default value, currently 25000, is in effect when null is returned)
MaxPresences int `json:"max_presences"`
// The maximum number of members for the guild
MaxMembers int `json:"max_members"`
// A list of channels in the guild.
// This field is only present in GUILD_CREATE events and websocket
// update events, and thus is only present in state-cached guilds.
Channels []*Channel `json:"channels"`
// A list of all active threads in the guild that current user has permission to view
// This field is only present in GUILD_CREATE events and websocket
// update events and thus is only present in state-cached guilds.
Threads []*Channel `json:"threads"`
// A list of voice states for the guild.
// This field is only present in GUILD_CREATE events and websocket
// update events, and thus is only present in state-cached guilds.
VoiceStates []*VoiceState `json:"voice_states"`
// Whether this guild is currently unavailable (most likely due to outage).
// This field is only present in GUILD_CREATE events and websocket
// update events, and thus is only present in state-cached guilds.
Unavailable bool `json:"unavailable"`
// The explicit content filter level
ExplicitContentFilter ExplicitContentFilterLevel `json:"explicit_content_filter"`
// The NSFW Level of the guild
NSFWLevel GuildNSFWLevel `json:"nsfw_level"`
// The list of enabled guild features
Features []GuildFeature `json:"features"`
// Required MFA level for the guild
MfaLevel MfaLevel `json:"mfa_level"`
// The application id of the guild if bot created.
ApplicationID string `json:"application_id"`
// Whether or not the Server Widget is enabled
WidgetEnabled bool `json:"widget_enabled"`
// The Channel ID for the Server Widget
WidgetChannelID string `json:"widget_channel_id"`
// The Channel ID to which system messages are sent (eg join and leave messages)
SystemChannelID string `json:"system_channel_id"`
// The System channel flags
SystemChannelFlags SystemChannelFlag `json:"system_channel_flags"`
// The ID of the rules channel ID, used for rules.
RulesChannelID string `json:"rules_channel_id"`
// the vanity url code for the guild
VanityURLCode string `json:"vanity_url_code"`
// the description for the guild
Description string `json:"description"`
// The hash of the guild's banner
Banner string `json:"banner"`
// The premium tier of the guild
PremiumTier PremiumTier `json:"premium_tier"`
// The total number of users currently boosting this server
PremiumSubscriptionCount int `json:"premium_subscription_count"`
// The preferred locale of a guild with the "PUBLIC" feature; used in server discovery and notices from Discord; defaults to "en-US"
PreferredLocale string `json:"preferred_locale"`
// The id of the channel where admins and moderators of guilds with the "PUBLIC" feature receive notices from Discord
PublicUpdatesChannelID string `json:"public_updates_channel_id"`
// The maximum amount of users in a video channel
MaxVideoChannelUsers int `json:"max_video_channel_users"`
// Approximate number of members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
ApproximateMemberCount int `json:"approximate_member_count"`
// Approximate number of non-offline members in this guild, returned from the GET /guild/<id> endpoint when with_counts is true
ApproximatePresenceCount int `json:"approximate_presence_count"`
// Permissions of our user
Permissions int64 `json:"permissions,string"`
// Stage instances in the guild
StageInstances []*StageInstance `json:"stage_instances"`
}
// A GuildPreview holds data related to a specific public Discord Guild, even if the user is not in the guild.
type GuildPreview struct {
// The ID of the guild.
ID string `json:"id"`
// The name of the guild. (2–100 characters)
Name string `json:"name"`
// The hash of the guild's icon. Use Session.GuildIcon
// to retrieve the icon itself.
Icon string `json:"icon"`
// The hash of the guild's splash.
Splash string `json:"splash"`
// The hash of the guild's discovery splash.
DiscoverySplash string `json:"discovery_splash"`
// A list of the custom emojis present in the guild.
Emojis []*Emoji `json:"emojis"`
// The list of enabled guild features
Features []string `json:"features"`
// Approximate number of members in this guild
// NOTE: this field is only filled when using GuildWithCounts
ApproximateMemberCount int `json:"approximate_member_count"`
// Approximate number of non-offline members in this guild
// NOTE: this field is only filled when using GuildWithCounts
ApproximatePresenceCount int `json:"approximate_presence_count"`
// the description for the guild
Description string `json:"description"`
}
// IconURL returns a URL to the guild's icon.
//
// size: The size of the desired icon image as a power of two
// Image size can be any power of two between 16 and 4096.
func (g *GuildPreview) IconURL(size string) string {
return iconURL(g.Icon, EndpointGuildIcon(g.ID, g.Icon), EndpointGuildIconAnimated(g.ID, g.Icon), size)
}
// GuildScheduledEvent is a representation of a scheduled event in a guild. Only for retrieval of the data.
// https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event
type GuildScheduledEvent struct {
// The ID of the scheduled event
ID string `json:"id"`
// The guild id which the scheduled event belongs to
GuildID string `json:"guild_id"`
// The channel id in which the scheduled event will be hosted, or null if scheduled entity type is EXTERNAL
ChannelID string `json:"channel_id"`
// The id of the user that created the scheduled event
CreatorID string `json:"creator_id"`
// The name of the scheduled event (1-100 characters)
Name string `json:"name"`
// The description of the scheduled event (1-1000 characters)
Description string `json:"description"`
// The time the scheduled event will start
ScheduledStartTime time.Time `json:"scheduled_start_time"`
// The time the scheduled event will end, required only when entity_type is EXTERNAL
ScheduledEndTime *time.Time `json:"scheduled_end_time"`
// The privacy level of the scheduled event
PrivacyLevel GuildScheduledEventPrivacyLevel `json:"privacy_level"`
// The status of the scheduled event
Status GuildScheduledEventStatus `json:"status"`
// Type of the entity where event would be hosted
// See field requirements
// https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-field-requirements-by-entity-type
EntityType GuildScheduledEventEntityType `json:"entity_type"`
// The id of an entity associated with a guild scheduled event
EntityID string `json:"entity_id"`
// Additional metadata for the guild scheduled event
EntityMetadata GuildScheduledEventEntityMetadata `json:"entity_metadata"`
// The user that created the scheduled event
Creator *User `json:"creator"`
// The number of users subscribed to the scheduled event
UserCount int `json:"user_count"`
// The cover image hash of the scheduled event
// see https://discord.com/developers/docs/reference#image-formatting for more
// information about image formatting
Image string `json:"image"`
}
// GuildScheduledEventParams are the parameters allowed for creating or updating a scheduled event
// https://discord.com/developers/docs/resources/guild-scheduled-event#create-guild-scheduled-event
type GuildScheduledEventParams struct {
// The channel id in which the scheduled event will be hosted, or null if scheduled entity type is EXTERNAL
ChannelID string `json:"channel_id,omitempty"`
// The name of the scheduled event (1-100 characters)
Name string `json:"name,omitempty"`
// The description of the scheduled event (1-1000 characters)
Description string `json:"description,omitempty"`
// The time the scheduled event will start
ScheduledStartTime *time.Time `json:"scheduled_start_time,omitempty"`
// The time the scheduled event will end, required only when entity_type is EXTERNAL
ScheduledEndTime *time.Time `json:"scheduled_end_time,omitempty"`
// The privacy level of the scheduled event
PrivacyLevel GuildScheduledEventPrivacyLevel `json:"privacy_level,omitempty"`
// The status of the scheduled event
Status GuildScheduledEventStatus `json:"status,omitempty"`
// Type of the entity where event would be hosted
// See field requirements
// https://discord.com/developers/docs/resources/guild-scheduled-event#guild-scheduled-event-object-field-requirements-by-entity-type
EntityType GuildScheduledEventEntityType `json:"entity_type,omitempty"`
// Additional metadata for the guild scheduled event
EntityMetadata *GuildScheduledEventEntityMetadata `json:"entity_metadata,omitempty"`
// The cover image hash of the scheduled event
// see https://discord.com/developers/docs/reference#image-formatting for more
// information about image formatting