forked from andersfylling/disgord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrest_invite.go
59 lines (51 loc) · 1.64 KB
/
rest_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
package disgord
import (
"fmt"
"net/http"
"github.com/andersfylling/disgord/endpoint"
"github.com/andersfylling/disgord/httd"
)
// GetInvite [GET] Returns an invite object for the given code.
// Endpoint /invites/{invite.code}
// Rate limiter /invites
// Discord documentation https://discordapp.com/developers/docs/resources/invite#get-invite
// Reviewed 2018-06-10
// Comment -
//
// withCounts whether the invite should contain approximate member counts
func GetInvite(client httd.Getter, inviteCode string, withCounts bool) (invite *Invite, err error) {
query := ""
if withCounts {
query += "?with_counts=true"
}
resp, body, err := client.Get(&httd.Request{
Ratelimiter: endpoint.Invites(),
Endpoint: endpoint.Invite(inviteCode) + query,
})
if err != nil {
return
}
if resp.StatusCode != http.StatusOK {
fmt.Println(resp.StatusCode)
}
err = unmarshal(body, &invite)
return
}
// DeleteInvite [DELETE] Delete an invite. Requires the MANAGE_CHANNELS permission. Returns an invite
// object on success.
// Endpoint /invites/{invite.code}
// Rate limiter /invites
// Discord documentation https://discordapp.com/developers/docs/resources/invite#delete-invite
// Reviewed 2018-06-10
// Comment -
func DeleteInvite(client httd.Deleter, inviteCode string) (invite *Invite, err error) {
_, body, err := client.Delete(&httd.Request{
Ratelimiter: endpoint.Invites(),
Endpoint: endpoint.Invite(inviteCode),
})
if err != nil {
return
}
err = unmarshal(body, &invite)
return
}