forked from andersfylling/disgord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct_invite.go
128 lines (98 loc) · 2.94 KB
/
struct_invite.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
package disgord
import "sync"
// PartialInvite ...
// {
// "code": "abc"
// }
type PartialInvite = Invite
// Invite Represents a code that when used, adds a user to a guild.
// https://discordapp.com/developers/docs/resources/invite#invite-object
// Reviewed: 2018-06-10
type Invite struct {
sync.RWMutex `json:"-"`
// Code the invite code (unique Snowflake)
Code string `json:"code"`
// Guild the guild this invite is for
Guild *PartialGuild `json:"guild"`
// Channel the channel this invite is for
Channel *PartialChannel `json:"channel"`
// ApproximatePresenceCount approximate count of online members
ApproximatePresenceCount int `json:"approximate_presence_count,omitempty"`
// ApproximatePresenceCount approximate count of total members
ApproximateMemberCount int `json:"approximate_member_count,omitempty"`
}
func (i *Invite) DeepCopy() (copy interface{}) {
copy = &Invite{}
i.CopyOverTo(copy)
return
}
func (i *Invite) CopyOverTo(other interface{}) (err error) {
var ok bool
var invite *Invite
if invite, ok = other.(*Invite); !ok {
err = NewErrorUnsupportedType("given interface{} was not of type *Invite")
return
}
i.RLock()
invite.Lock()
invite.Code = i.Code
invite.ApproximatePresenceCount = i.ApproximatePresenceCount
invite.ApproximateMemberCount = i.ApproximateMemberCount
if i.Guild != nil {
invite.Guild = NewPartialGuild(i.Guild.ID)
}
if i.Channel != nil {
c := i.Channel
invite.Channel = NewPartialChannel(c.ID, c.Name, c.Type)
}
i.RUnlock()
invite.Unlock()
return
}
// InviteMetadata Object
// https://discordapp.com/developers/docs/resources/invite#invite-metadata-object
// Reviewed: 2018-06-10
type InviteMetadata struct {
sync.RWMutex `json:"-"`
// Inviter user who created the invite
Inviter *User `json:"inviter"`
// Uses number of times this invite has been used
Uses int `json:"uses"`
// MaxUses max number of times this invite can be used
MaxUses int `json:"max_uses"`
// MaxAge duration (in seconds) after which the invite expires
MaxAge int `json:"max_age"`
// Temporary whether this invite only grants temporary membership
Temporary bool `json:"temporary"`
// CreatedAt when this invite was created
CreatedAt Timestamp `json:"created_at"`
// Revoked whether this invite is revoked
Revoked bool `json:"revoked"`
}
func (i *InviteMetadata) DeepCopy() (copy interface{}) {
copy = &InviteMetadata{}
i.CopyOverTo(copy)
return
}
func (i *InviteMetadata) CopyOverTo(other interface{}) (err error) {
var ok bool
var invite *InviteMetadata
if invite, ok = other.(*InviteMetadata); !ok {
err = NewErrorUnsupportedType("given interface{} was not of type *InviteMetadata")
return
}
i.RLock()
invite.Lock()
invite.Uses = i.Uses
invite.MaxUses = i.MaxUses
invite.MaxAge = i.MaxAge
invite.Temporary = i.Temporary
invite.CreatedAt = i.CreatedAt
invite.Revoked = i.Revoked
if i.Inviter != nil {
invite.Inviter = i.Inviter.DeepCopy().(*User)
}
i.RUnlock()
invite.Unlock()
return
}