-
Notifications
You must be signed in to change notification settings - Fork 927
/
structs.go
1551 lines (1304 loc) · 59 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"
"net/http"
"strconv"
"strings"
"sync"
"time"
"github.com/botlabs-gg/yagpdb/v2/lib/gojay"
"github.com/pkg/errors"
"github.com/volatiletech/null"
)
// A Session represents a connection to the Discord API.
type Session struct {
// General configurable settings.
// Authentication token for this session
Token string
MFA bool
Intents []GatewayIntent
// 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 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 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
// Max number of REST API retries
MaxRestRetries int
// Managed state object, updated internally with events when
// StateEnabled is true.
State *State
// The http client used for REST requests
Client *http.Client
// Stores the last HeartbeatAck that was recieved (in UTC)
LastHeartbeatAck time.Time
// used to deal with rate limits
Ratelimiter *RateLimiter
// The gateway websocket connection
GatewayManager *GatewayConnectionManager
tokenInvalid *int32
// Event handlers
handlersMu sync.RWMutex
handlers map[string][]*eventHandlerInstance
onceHandlers map[string][]*eventHandlerInstance
}
// 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"`
ExpireBehavior int `json:"expire_behavior"`
ExpireGracePeriod int `json:"expire_grace_period"`
User *User `json:"user"`
Account IntegrationAccount `json:"account"`
SyncedAt Timestamp `json:"synced_at"`
}
// 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"`
Hostname string `json:"sample_hostname"`
Port int `json:"sample_port"`
}
// A VoiceICE stores data for voice ICE servers.
type VoiceICE struct {
TTL string `json:"ttl"`
Servers []*ICEServer `json:"servers"`
}
// A ICEServer stores data for a specific voice ICE server.
type ICEServer struct {
URL string `json:"url"`
Username string `json:"username"`
Credential string `json:"credential"`
}
// 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 Timestamp `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"`
// will only be filled when using InviteWithCounts
ApproximatePresenceCount int `json:"approximate_presence_count"`
ApproximateMemberCount int `json:"approximate_member_count"`
}
// ChannelType is the type of a Channel
type ChannelType int
// Block contains known ChannelType values
const (
ChannelTypeGuildText ChannelType = 0 // a text channel within a server
ChannelTypeDM ChannelType = 1 // a direct message between users
ChannelTypeGuildVoice ChannelType = 2 // a voice channel within a server
ChannelTypeGroupDM ChannelType = 3 // a direct message between multiple users
ChannelTypeGuildCategory ChannelType = 4 // an organizational category that contains up to 50 channels
ChannelTypeGuildNews ChannelType = 5 // a channel that users can follow and crosspost into their own server
ChannelTypeGuildStore ChannelType = 6 // a channel in which game developers can sell their game on Discord
ChannelTypeGuildNewsThread ChannelType = 10 // a temporary sub-channel within a GUILD_NEWS channel
ChannelTypeGuildPublicThread ChannelType = 11 // a temporary sub-channel within a GUILD_TEXT channel
ChannelTypeGuildPrivateThread ChannelType = 12 // a temporary sub-channel within a GUILD_TEXT channel that is only viewable by those invited and those with the MANAGE_THREADS permission
ChannelTypeGuildStageVoice ChannelType = 13 // a voice channel for hosting events with an audience
ChannelTypeGuildForum ChannelType = 15 // a channel that can only contain threads
)
func (t ChannelType) IsThread() bool {
return t == ChannelTypeGuildPrivateThread || t == ChannelTypeGuildPublicThread
}
// A Channel holds all data related to an individual Discord channel.
type Channel struct {
// The ID of the channel.
ID int64 `json:"id,string"`
// 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 int64 `json:"guild_id,string"`
// 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 int64 `json:"last_message_id,string"`
// 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
ParentID int64 `json:"parent_id,string"`
// Period of time in which the user is unable to send another message or create a new thread for.
// Excludes "manage_messages" and "manage_channel" permissions
RateLimitPerUser int `json:"rate_limit_per_user"`
// The user ID of the owner of the thread. Nil on normal channels
OwnerID int64 `json:"owner_id,string"`
// Thread specific fields
ThreadMetadata *ThreadMetadata `json:"thread_metadata"`
}
func (c *Channel) GetChannelID() int64 {
return c.ID
}
func (c *Channel) GetGuildID() int64 {
return c.GuildID
}
// Mention returns a string which mentions the channel
func (c *Channel) Mention() string {
return fmt.Sprintf("<#%d>", c.ID)
}
// A ChannelEdit holds Channel Feild 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 *null.String `json:"parent_id,omitempty"`
RateLimitPerUser *int `json:"rate_limit_per_user,omitempty"`
}
type RoleCreate struct {
Name string `json:"name,omitempty"`
Permissions int64 `json:"permissions,string,omitempty"`
Color int32 `json:"color,omitempty"`
Hoist bool `json:"hoist"`
Mentionable bool `json:"mentionable"`
}
// A PermissionOverwrite holds permission overwrite data for a Channel
type PermissionOverwrite struct {
ID int64 `json:"id,string"`
Type PermissionOverwriteType `json:"type"`
Deny int64 `json:"deny,string"`
Allow int64 `json:"allow,string"`
}
type PermissionOverwriteType int
const (
PermissionOverwriteTypeRole PermissionOverwriteType = 0
PermissionOverwriteTypeMember PermissionOverwriteType = 1
)
// Emoji struct holds data related to Emoji's
type Emoji struct {
ID int64 `json:"id,string"`
Name string `json:"name"`
Roles IDSlice `json:"roles,string"`
Managed bool `json:"managed"`
RequireColons bool `json:"require_colons"`
Animated bool `json:"animated"`
}
// MessageFormat returns a correctly formatted Emoji for use in Message content and embeds
func (e *Emoji) MessageFormat() string {
if e.ID != 0 && 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 != 0 && e.Name != "" {
return e.Name + ":" + StrID(e.ID)
}
if e.Name != "" {
return e.Name
}
return StrID(e.ID)
}
// VerificationLevel type definition
type VerificationLevel int
// Constants for VerificationLevel levels from 0 to 3 inclusive
const (
VerificationLevelNone VerificationLevel = iota
VerificationLevelLow
VerificationLevelMedium
VerificationLevelHigh
)
// ExplicitContentFilterLevel type definition
type ExplicitContentFilterLevel int
// Constants for ExplicitContentFilterLevel levels from 0 to 2 inclusive
const (
ExplicitContentFilterDisabled ExplicitContentFilterLevel = iota
ExplicitContentFilterMembersWithoutRoles
ExplicitContentFilterAllMembers
)
// MfaLevel type definition
type MfaLevel int
// Constants for MfaLevel levels from 0 to 1 inclusive
const (
MfaLevelNone MfaLevel = iota
MfaLevelElevated
)
// 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 int64 `json:"id,string"`
// The name of the guild. (2–100 characters)
Name string `json:"name"`
Description string `json:"description"`
Banner string `json:"banner"`
PreferredLocale string `json:"preferred_locale"`
// 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 int64 `json:"afk_channel_id,string"`
// The user ID of the owner of the guild.
OwnerID int64 `json:"owner_id,string"`
// 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 Timestamp `json:"joined_at"`
// 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.
// 0 == all messages, 1 == mentions only.
DefaultMessageNotifications int `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 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"`
// A list of channels in the guild.
// This field is only present in GUILD_CREATE events
Channels []*Channel `json:"channels"`
// All active threads in the guild that current user has permission to view
// This field is only present in GUILD_CREATE events
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"`
MaxPresences int `json:"max_presences"`
MaxMembers int `json:"max_members"`
// 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 list of enabled guild features
Features []string `json:"features"`
// Required MFA level for the guild
MfaLevel MfaLevel `json:"mfa_level"`
// 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"`
ApproximateMemberCount int `json:"approximate_member_count"`
ApproximatePresenceCount int `json:"approximate_presence_count"`
VanityURLCode string `json:"vanity_url_code"`
}
func (g *Guild) GetGuildID() int64 {
return g.ID
}
func (g *Guild) Role(id int64) *Role {
for _, v := range g.Roles {
if v.ID == id {
return v
}
}
return nil
}
func (g *Guild) Channel(id int64) *Channel {
for _, v := range g.Channels {
if v.ID == id {
return v
}
}
return nil
}
// A UserGuild holds a brief version of a Guild
type UserGuild struct {
ID int64 `json:"id,string"`
Name string `json:"name"`
Icon string `json:"icon"`
Owner bool `json:"owner"`
Permissions int64 `json:"permissions,string"`
}
// A GuildParams stores all the data needed to update discord guild settings
type GuildParams struct {
Name string `json:"name,omitempty"`
Region string `json:"region,omitempty"`
VerificationLevel *VerificationLevel `json:"verification_level,omitempty"`
DefaultMessageNotifications int `json:"default_message_notifications,omitempty"` // TODO: Separate type?
AfkChannelID int64 `json:"afk_channel_id,omitempty,string"`
AfkTimeout int `json:"afk_timeout,omitempty"`
Icon string `json:"icon,omitempty"`
OwnerID int64 `json:"owner_id,omitempty,string"`
Splash string `json:"splash,omitempty"`
}
// A Role stores information about Discord guild member roles.
type Role struct {
// The ID of the role.
ID int64 `json:"id,string"`
// The name of the role.
Name string `json:"name"`
// Whether this role is managed by an integration, and
// thus cannot be manually added to, or taken from, members.
Managed bool `json:"managed"`
// Whether this role is mentionable.
Mentionable bool `json:"mentionable"`
// Whether this role is hoisted (shows up separately in member list).
Hoist bool `json:"hoist"`
// The hex color of this role.
Color int `json:"color"`
// The position of this role in the guild's role hierarchy.
Position int `json:"position"`
// The permissions of the role on the guild (doesn't include channel overrides).
// This is a combination of bit masks; the presence of a certain permission can
// be checked by performing a bitwise AND between this int and the permission.
Permissions int64 `json:"permissions,string"`
}
// Mention returns a string which mentions the role
func (r *Role) Mention() string {
return fmt.Sprintf("<@&%d>", r.ID)
}
// Roles are a collection of Role
type Roles []*Role
func (r Roles) Len() int {
return len(r)
}
func (r Roles) Less(i, j int) bool {
return r[i].Position > r[j].Position
}
func (r Roles) Swap(i, j int) {
r[i], r[j] = r[j], r[i]
}
// A VoiceState stores the voice states of Guilds
type VoiceState struct {
UserID int64 `json:"user_id,string"`
SessionID string `json:"session_id"`
ChannelID int64 `json:"channel_id,string"`
GuildID int64 `json:"guild_id,string"`
Suppress bool `json:"suppress"`
SelfMute bool `json:"self_mute"`
SelfDeaf bool `json:"self_deaf"`
Mute bool `json:"mute"`
Deaf bool `json:"deaf"`
SelfStream bool `json:"self_stream"`
SelfVideo bool `json:"self_video"`
}
// A Presence stores the online, offline, or idle and game status of Guild members.
type Presence struct {
User *User `json:"user"`
Status Status `json:"status"`
Activities Activities `json:"activities"`
}
// implement gojay.UnmarshalerJSONObject
func (p *Presence) UnmarshalJSONObject(dec *gojay.Decoder, key string) error {
var err error
switch key {
case "user":
p.User = &User{}
err = dec.Object(p.User)
case "status":
err = dec.String((*string)(&p.Status))
case "activities":
err = dec.DecodeArray(&p.Activities)
default:
}
if err != nil {
return errors.Wrap(err, key)
}
return nil
}
func (p *Presence) NKeys() int {
return 0
}
type Activities []*Game
func (a *Activities) UnmarshalJSONArray(dec *gojay.Decoder) error {
instance := Game{}
err := dec.Object(&instance)
if err != nil {
return err
}
*a = append(*a, &instance)
return nil
}
// GameType is the type of "game" (see GameType* consts) in the Game struct
type GameType int
// Valid GameType values
const (
GameTypeGame GameType = iota
GameTypeStreaming
GameTypeListening
GameTypeWatching
)
// A Game struct holds the name of the "playing .." game for a user
type Game struct {
Name string `json:"name"`
Type GameType `json:"type"`
URL string `json:"url,omitempty"`
Details string `json:"details,omitempty"`
State string `json:"state,omitempty"`
TimeStamps TimeStamps `json:"timestamps,omitempty"`
Assets Assets `json:"assets,omitempty"`
Instance int8 `json:"instance,omitempty"`
}
// implement gojay.UnmarshalerJSONObject
func (g *Game) UnmarshalJSONObject(dec *gojay.Decoder, key string) error {
switch key {
case "name":
return dec.String(&g.Name)
case "type":
return dec.Int((*int)(&g.Type))
case "url":
return dec.String(&g.URL)
case "details":
return dec.String(&g.Details)
case "state":
return dec.String(&g.State)
case "timestamps":
return dec.Object(&g.TimeStamps)
case "assets":
case "instance":
return dec.Int8(&g.Instance)
}
return nil
}
func (g *Game) NKeys() int {
return 0
}
// A TimeStamps struct contains start and end times used in the rich presence "playing .." Game
type TimeStamps struct {
EndTimestamp int64 `json:"end,omitempty"`
StartTimestamp int64 `json:"start,omitempty"`
}
func (t *TimeStamps) UnmarshalJSONObject(dec *gojay.Decoder, key string) error {
switch key {
case "start":
return dec.Int64(&t.StartTimestamp)
case "end":
return dec.Int64(&t.EndTimestamp)
}
return nil
}
// UnmarshalJSON unmarshals JSON into TimeStamps struct
func (t *TimeStamps) UnmarshalJSON(b []byte) error {
temp := struct {
End json.Number `json:"end,omitempty"`
Start json.Number `json:"start,omitempty"`
}{}
err := json.Unmarshal(b, &temp)
if err != nil {
return err
}
var endParsed float64
if temp.End != "" {
endParsed, err = temp.End.Float64()
if err != nil {
return err
}
}
var startParsed float64
if temp.Start != "" {
startParsed, err = temp.Start.Float64()
if err != nil {
return err
}
}
t.EndTimestamp = int64(endParsed)
t.StartTimestamp = int64(startParsed)
return nil
}
func (t *TimeStamps) NKeys() int {
return 0
}
// An Assets struct contains assets and labels used in the rich presence "playing .." Game
type Assets struct {
LargeImageID string `json:"large_image,omitempty"`
SmallImageID string `json:"small_image,omitempty"`
LargeText string `json:"large_text,omitempty"`
SmallText string `json:"small_text,omitempty"`
}
// A MessageActivity represents the activity sent with a message, such as a game invite.
type MessageActivity struct {
Type int `json:"type"`
PartyID string `json:"party_id"`
}
// A Member stores user information for Guild members. A guild
// member represents a certain user's presence in a guild.
type Member struct {
// The guild ID on which the member exists.
GuildID int64 `json:"guild_id,string"`
// The time at which the member joined the guild, in ISO8601.
JoinedAt Timestamp `json:"joined_at"`
// The nickname of the member, if they have one.
Nick string `json:"nick"`
// The guild avatar hash of the member, if they have one.
Avatar string `json:"avatar"`
// Whether the member is deafened at a guild level.
Deaf bool `json:"deaf"`
// Whether the member is muted at a guild level.
Mute bool `json:"mute"`
// The underlying user on which the member is based.
User *User `json:"user"`
// A list of IDs of the roles which are possessed by the member.
Roles IDSlice `json:"roles,string"`
// Whether the user has not yet passed the guild's Membership Screening requirements
Pending bool `json:"pending"`
// The time at which the member's timeout will expire.
// Time in the past or nil if the user is not timed out.
CommunicationDisabledUntil *time.Time `json:"communication_disabled_until"`
}
func (m *Member) GetGuildID() int64 {
return m.GuildID
}
func (m *Member) AvatarURL(size string) string {
var URL string
if m == nil {
return "Member not found"
}
u := m.User
if m.Avatar == "" {
return u.AvatarURL(size)
} else if strings.HasPrefix(m.Avatar, "a_") {
URL = EndpointGuildMemberAvatarAnimated(m.GuildID, u.ID, m.Avatar)
} else {
URL = EndpointGuildMemberAvatar(m.GuildID, u.ID, m.Avatar)
}
if size != "" {
return URL + "?size=" + size
}
return URL
}
// A Settings stores data for a specific users Discord client settings.
type Settings struct {
RenderEmbeds bool `json:"render_embeds"`
InlineEmbedMedia bool `json:"inline_embed_media"`
InlineAttachmentMedia bool `json:"inline_attachment_media"`
EnableTtsCommand bool `json:"enable_tts_command"`
MessageDisplayCompact bool `json:"message_display_compact"`
ShowCurrentGame bool `json:"show_current_game"`
ConvertEmoticons bool `json:"convert_emoticons"`
Locale string `json:"locale"`
Theme string `json:"theme"`
GuildPositions IDSlice `json:"guild_positions,string"`
RestrictedGuilds IDSlice `json:"restricted_guilds,string"`
FriendSourceFlags *FriendSourceFlags `json:"friend_source_flags"`
Status Status `json:"status"`
DetectPlatformAccounts bool `json:"detect_platform_accounts"`
DeveloperMode bool `json:"developer_mode"`
}
// Status type definition
type Status string
// Constants for Status with the different current available status
const (
StatusOnline Status = "online"
StatusIdle Status = "idle"
StatusDoNotDisturb Status = "dnd"
StatusInvisible Status = "invisible"
StatusOffline Status = "offline"
)
// FriendSourceFlags stores ... TODO :)
type FriendSourceFlags struct {
All bool `json:"all"`
MutualGuilds bool `json:"mutual_guilds"`
MutualFriends bool `json:"mutual_friends"`
}
// A Relationship between the logged in user and Relationship.User
type Relationship struct {
User *User `json:"user"`
Type int `json:"type"` // 1 = friend, 2 = blocked, 3 = incoming friend req, 4 = sent friend req
ID string `json:"id"`
}
// A TooManyRequests struct holds information received from Discord
// when receiving a HTTP 429 response.
type TooManyRequests struct {
Bucket string `json:"bucket"`
Message string `json:"message"`
RetryAfter float64 `json:"retry_after"`
Global bool `json:"global"`
}
func (t *TooManyRequests) RetryAfterDur() time.Duration {
return time.Duration(t.RetryAfter*1000) * time.Millisecond
}
// A ReadState stores data on the read state of channels.
type ReadState struct {
MentionCount int `json:"mention_count"`
LastMessageID int64 `json:"last_message_id,string"`
ID int64 `json:"id,string"`
}
// An Ack is used to ack messages
type Ack struct {
Token string `json:"token"`
}
// A GuildRole stores data for guild roles.
type GuildRole struct {
Role *Role `json:"role"`
GuildID int64 `json:"guild_id,string"`
}
func (e *GuildRole) GetGuildID() int64 {
return e.GuildID
}
// A GuildBan stores data for a guild ban.
type GuildBan struct {
Reason string `json:"reason"`
User *User `json:"user"`
}
// A GuildEmbed stores data for a guild embed.
type GuildEmbed struct {
Enabled bool `json:"enabled"`
ChannelID int64 `json:"channel_id,string"`
}
// A GuildAuditLog stores data for a guild audit log.
type GuildAuditLog struct {
Webhooks []struct {
ChannelID int64 `json:"channel_id,string"`
GuildID int64 `json:"guild_id,string"`
ID string `json:"id"`
Avatar string `json:"avatar"`
Name string `json:"name"`
} `json:"webhooks,omitempty"`
Users []*User `json:"users,omitempty"`
AuditLogEntries []*AuditLogEntry `json:"audit_log_entries"`
}
// AuditLogAction is the Action of the AuditLog (see AuditLogAction* consts)
// https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-events
type AuditLogAction int
// Block contains Discord Audit Log Action Types
const (
AuditLogActionGuildUpdate AuditLogAction = 1
AuditLogActionChannelCreate AuditLogAction = 10
AuditLogActionChannelUpdate AuditLogAction = 11
AuditLogActionChannelDelete AuditLogAction = 12
AuditLogActionChannelOverwriteCreate AuditLogAction = 13
AuditLogActionChannelOverwriteUpdate AuditLogAction = 14
AuditLogActionChannelOverwriteDelete AuditLogAction = 15
AuditLogActionMemberKick AuditLogAction = 20
AuditLogActionMemberPrune AuditLogAction = 21
AuditLogActionMemberBanAdd AuditLogAction = 22
AuditLogActionMemberBanRemove AuditLogAction = 23
AuditLogActionMemberUpdate AuditLogAction = 24
AuditLogActionMemberRoleUpdate AuditLogAction = 25
AuditLogActionMemberMove AuditLogAction = 26
AuditLogActionMemberDisconnect AuditLogAction = 27
AuditLogActionBotAdd AuditLogAction = 28
AuditLogActionRoleCreate AuditLogAction = 30
AuditLogActionRoleUpdate AuditLogAction = 31
AuditLogActionRoleDelete AuditLogAction = 32
AuditLogActionInviteCreate AuditLogAction = 40
AuditLogActionInviteUpdate AuditLogAction = 41
AuditLogActionInviteDelete AuditLogAction = 42
AuditLogActionWebhookCreate AuditLogAction = 50
AuditLogActionWebhookUpdate AuditLogAction = 51
AuditLogActionWebhookDelete AuditLogAction = 52
AuditLogActionEmojiCreate AuditLogAction = 60
AuditLogActionEmojiUpdate AuditLogAction = 61
AuditLogActionEmojiDelete AuditLogAction = 62
AuditLogActionMessageDelete AuditLogAction = 72
AuditLogActionMessageBulkDelete AuditLogAction = 73
AuditLogActionMessagePin AuditLogAction = 74
AuditLogActionMessageUnpin AuditLogAction = 75
AuditLogActionIntegrationCreate AuditLogAction = 80
AuditLogActionIntegrationUpdate AuditLogAction = 81
AuditLogActionIntegrationDelete AuditLogAction = 82
AuditLogActionStageInstanceCreate AuditLogAction = 83
AuditLogActionStageInstanceUpdate AuditLogAction = 84
AuditLogActionStageInstanceDelete AuditLogAction = 85
AuditLogActionStickerCreate AuditLogAction = 90
AuditLogActionStickerUpdate AuditLogAction = 91
AuditLogActionStickerDelete AuditLogAction = 92
AuditLogGuildScheduledEventCreate AuditLogAction = 100
AuditLogGuildScheduledEventUpdare AuditLogAction = 101
AuditLogGuildScheduledEventDelete AuditLogAction = 102
AuditLogActionThreadCreate AuditLogAction = 110
AuditLogActionThreadUpdate AuditLogAction = 111
AuditLogActionThreadDelete AuditLogAction = 112
AuditLogActionApplicationCommandPermissionUpdate AuditLogAction = 121
AuditLogActionAutoModerationRuleCreate AuditLogAction = 140
AuditLogActionAutoModerationRuleUpdate AuditLogAction = 141
AuditLogActionAutoModerationRuleDelete AuditLogAction = 142
AuditLogActionAutoModerationBlockMessage AuditLogAction = 143
AuditLogActionAutoModerationFlagToChannel AuditLogAction = 144
AuditLogActionAutoModerationUserCommunicationDisabled AuditLogAction = 145
)
// AuditLogChange for an AuditLogEntry
type AuditLogChange struct {
NewValue interface{} `json:"new_value"`
OldValue interface{} `json:"old_value"`
Key *AuditLogChangeKey `json:"key"`
}
// AuditLogChangeKey value for AuditLogChange
// https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-key
type AuditLogChangeKey string
// Block of valid AuditLogChangeKey
const (
// AuditLogChangeKeyAfkChannelID is sent when afk channel changed (snowflake) - guild
AuditLogChangeKeyAfkChannelID AuditLogChangeKey = "afk_channel_id"
// AuditLogChangeKeyAfkTimeout is sent when afk timeout duration changed (int) - guild
AuditLogChangeKeyAfkTimeout AuditLogChangeKey = "afk_timeout"