2020-01-02 05:39:52 +00:00
|
|
|
package api
|
|
|
|
|
2020-01-02 19:53:08 +00:00
|
|
|
import (
|
2020-10-28 22:39:59 +00:00
|
|
|
"github.com/diamondburned/arikawa/v2/discord"
|
|
|
|
"github.com/diamondburned/arikawa/v2/utils/httputil"
|
|
|
|
"github.com/diamondburned/arikawa/v2/utils/json/option"
|
2020-01-02 19:53:08 +00:00
|
|
|
)
|
2020-01-02 05:39:52 +00:00
|
|
|
|
2020-04-19 16:30:12 +00:00
|
|
|
var EndpointInvites = Endpoint + "invites/"
|
2020-01-02 05:39:52 +00:00
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// Invite returns an invite object for the given code.
|
2020-05-12 02:57:43 +00:00
|
|
|
//
|
|
|
|
// ApproxMembers will not get filled.
|
2020-01-02 19:53:08 +00:00
|
|
|
func (c *Client) Invite(code string) (*discord.Invite, error) {
|
2020-05-12 02:57:43 +00:00
|
|
|
var inv *discord.Invite
|
|
|
|
return inv, c.RequestJSON(
|
|
|
|
&inv, "GET",
|
|
|
|
EndpointInvites+code,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Invite returns an invite object for the given code and fills ApproxMembers.
|
|
|
|
func (c *Client) InviteWithCounts(code string) (*discord.Invite, error) {
|
2020-01-02 05:39:52 +00:00
|
|
|
var params struct {
|
2020-01-06 03:48:39 +00:00
|
|
|
WithCounts bool `schema:"with_counts,omitempty"`
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
params.WithCounts = true
|
|
|
|
|
2020-01-02 19:53:08 +00:00
|
|
|
var inv *discord.Invite
|
2020-01-06 03:48:39 +00:00
|
|
|
return inv, c.RequestJSON(
|
|
|
|
&inv, "GET",
|
|
|
|
EndpointInvites+code,
|
|
|
|
httputil.WithSchema(c, params),
|
|
|
|
)
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// ChannelInvites returns a list of invite objects (with invite metadata) for
|
|
|
|
// the channel. Only usable for guild channels.
|
|
|
|
//
|
|
|
|
// Requires the MANAGE_CHANNELS permission.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) ChannelInvites(channelID discord.ChannelID) ([]discord.Invite, error) {
|
2020-01-02 19:53:08 +00:00
|
|
|
var invs []discord.Invite
|
2020-01-02 05:39:52 +00:00
|
|
|
return invs, c.RequestJSON(&invs, "GET",
|
|
|
|
EndpointChannels+channelID.String()+"/invites")
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// GuildInvites returns a list of invite objects (with invite metadata) for the
|
|
|
|
// guild.
|
|
|
|
//
|
|
|
|
// Requires the MANAGE_GUILD permission.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) GuildInvites(guildID discord.GuildID) ([]discord.Invite, error) {
|
2020-01-06 03:48:39 +00:00
|
|
|
var invs []discord.Invite
|
|
|
|
return invs, c.RequestJSON(&invs, "GET",
|
|
|
|
EndpointGuilds+guildID.String()+"/invites")
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// https://discord.com/developers/docs/resources/channel#create-channel-invite-json-params
|
|
|
|
type CreateInviteData struct {
|
|
|
|
// MaxAge is the duration of invite in seconds before expiry, or 0 for
|
|
|
|
// never.
|
|
|
|
//
|
|
|
|
// Default: 86400 (24 hours)
|
|
|
|
MaxAge option.Uint `json:"max_age,omitempty"`
|
|
|
|
// MaxUses is the max number of uses or 0 for unlimited.
|
|
|
|
//
|
|
|
|
// Default: 0
|
|
|
|
MaxUses uint `json:"max_uses,omitempty"`
|
|
|
|
// Temporary specifies whether this invite only grants temporary membership.
|
|
|
|
//
|
|
|
|
// Default: false
|
|
|
|
Temporary bool `json:"temporary,omitempty"`
|
|
|
|
// Unique has the following behavior: if true, don't try to reuse a similar
|
|
|
|
// invite (useful for creating many unique one time use invites).
|
|
|
|
//
|
|
|
|
// Default: false
|
|
|
|
Unique bool `json:"unique,omitempty"`
|
|
|
|
}
|
|
|
|
|
|
|
|
// CreateInvite creates a new invite object for the channel. Only usable for
|
|
|
|
// guild channels.
|
2020-01-02 05:39:52 +00:00
|
|
|
//
|
2020-05-11 22:06:19 +00:00
|
|
|
// Requires the CREATE_INSTANT_INVITE permission.
|
2020-01-06 03:48:39 +00:00
|
|
|
func (c *Client) CreateInvite(
|
2020-07-21 20:27:59 +00:00
|
|
|
channelID discord.ChannelID, data CreateInviteData) (*discord.Invite, error) {
|
2020-01-02 19:53:08 +00:00
|
|
|
var inv *discord.Invite
|
2020-01-06 03:48:39 +00:00
|
|
|
return inv, c.RequestJSON(
|
|
|
|
&inv, "POST",
|
|
|
|
EndpointChannels+channelID.String()+"/invites",
|
2020-05-11 22:06:19 +00:00
|
|
|
httputil.WithJSONBody(data),
|
2020-01-06 03:48:39 +00:00
|
|
|
)
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
2020-05-22 17:45:44 +00:00
|
|
|
// DeleteInvite deletes an invite.
|
2020-05-11 22:06:19 +00:00
|
|
|
//
|
2020-05-22 17:45:44 +00:00
|
|
|
// Requires the MANAGE_CHANNELS permission on the channel this invite belongs
|
|
|
|
// to, or MANAGE_GUILD to remove any invite across the guild.
|
|
|
|
// Fires a Invite Delete Gateway event.
|
2020-01-02 19:53:08 +00:00
|
|
|
func (c *Client) DeleteInvite(code string) (*discord.Invite, error) {
|
|
|
|
var inv *discord.Invite
|
2020-01-02 05:39:52 +00:00
|
|
|
return inv, c.RequestJSON(&inv, "DELETE", EndpointInvites+code)
|
|
|
|
}
|