This repository has been archived by the owner on Jul 11, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 70
/
invite.go
170 lines (131 loc) · 4.86 KB
/
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
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
package disgord
import (
"context"
"net/http"
"github.com/andersfylling/disgord/internal/endpoint"
"github.com/andersfylling/disgord/internal/httd"
)
// PartialInvite ...
//
// {
// "code": "abc"
// }
type PartialInvite = Invite
// Invite Represents a code that when used, adds a user to a guild.
// https://discord.com/developers/docs/resources/invite#invite-object
// Reviewed: 2018-06-10
type Invite struct {
// Code the invite code (unique Snowflake)
Code string `json:"code"`
// Guild the guild this invite is for
Guild *Guild `json:"guild"`
// Channel the channel this invite is for
Channel *PartialChannel `json:"channel"`
// Inviter the user that created the invite
Inviter *User `json:"inviter"`
// CreatedAt the time at which the invite was created
CreatedAt Time `json:"created_at"`
// MaxAge how long the invite is valid for (in seconds)
MaxAge int `json:"max_age"`
// MaxUses the maximum number of times the invite can be used
MaxUses int `json:"max_uses"`
// Temporary whether or not the invite is temporary (invited Users will be kicked on disconnect unless they're assigned a role)
Temporary bool `json:"temporary"`
// Uses how many times the invite has been used (always will be 0)
Uses int `json:"uses"`
Revoked bool `json:"revoked"`
Unique bool `json:"unique"`
// 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"`
}
var _ Copier = (*Invite)(nil)
var _ DeepCopier = (*Invite)(nil)
// InviteMetadata Object
// https://discord.com/developers/docs/resources/invite#invite-metadata-object
// Reviewed: 2018-06-10
type InviteMetadata struct {
// 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 Time `json:"created_at"`
// Revoked whether this invite is revoked
Revoked bool `json:"revoked"`
}
var _ Copier = (*InviteMetadata)(nil)
var _ DeepCopier = (*InviteMetadata)(nil)
// voiceRegionsFactory temporary until flyweight is implemented
func inviteFactory() interface{} {
return &Invite{}
}
type InviteQueryBuilder interface {
WithContext(ctx context.Context) InviteQueryBuilder
WithFlags(flags ...Flag) InviteQueryBuilder
// Get Returns an invite object for the given code.
Get(withMemberCount bool) (*Invite, error)
// Delete an invite. Requires the MANAGE_CHANNELS permission. Returns an invite object on success.
Delete() (deleted *Invite, err error)
}
func (c clientQueryBuilder) Invite(code string) InviteQueryBuilder {
return &inviteQueryBuilder{client: c.client, inviteCode: code}
}
type inviteQueryBuilder struct {
ctx context.Context
flags Flag
client *Client
inviteCode string
}
func (i inviteQueryBuilder) WithContext(ctx context.Context) InviteQueryBuilder {
i.ctx = ctx
return &i
}
func (i inviteQueryBuilder) WithFlags(flags ...Flag) InviteQueryBuilder {
i.flags = mergeFlags(flags)
return &i
}
type getInviteQuery struct {
WithMemberCount bool `urlparam:"with_count,omitempty"`
}
var _ URLQueryStringer = (*getInviteQuery)(nil)
// Get [REST] Returns an invite object for the given code.
//
// Method GET
// Endpoint /invites/{invite.code}
// Discord documentation https://discord.com/developers/docs/resources/invite#get-invite
// Reviewed 2018-06-10
// Comment -
// withMemberCount: whether or not the invite should contain the approximate number of members
func (i inviteQueryBuilder) Get(withMemberCount bool) (invite *Invite, err error) {
params := &getInviteQuery{withMemberCount}
r := i.client.newRESTRequest(&httd.Request{
Endpoint: endpoint.Invite(i.inviteCode) + params.URLQueryString(),
Ctx: i.ctx,
}, i.flags)
r.factory = inviteFactory
return getInvite(r.Execute)
}
// Delete [REST] Delete an invite. Requires the MANAGE_CHANNELS permission. Returns an invite object on success.
//
// Method DELETE
// Endpoint /invites/{invite.code}
// Discord documentation https://discord.com/developers/docs/resources/invite#delete-invite
// Reviewed 2018-06-10
// Comment -
func (i inviteQueryBuilder) Delete() (deleted *Invite, err error) {
r := i.client.newRESTRequest(&httd.Request{
Method: http.MethodDelete,
Endpoint: endpoint.Invite(i.inviteCode),
Ctx: i.ctx,
}, i.flags)
r.factory = inviteFactory
return getInvite(r.Execute)
}