2020-01-02 05:39:52 +00:00
|
|
|
package api
|
|
|
|
|
2020-01-02 19:53:08 +00:00
|
|
|
import (
|
2020-01-02 19:55:45 +00:00
|
|
|
"github.com/diamondburned/arikawa/discord"
|
2020-01-06 03:48:39 +00:00
|
|
|
"github.com/diamondburned/arikawa/httputil"
|
2020-01-02 19:53:08 +00:00
|
|
|
)
|
2020-01-02 05:39:52 +00:00
|
|
|
|
|
|
|
const EndpointInvites = Endpoint + "invites/"
|
|
|
|
|
2020-01-02 19:53:08 +00:00
|
|
|
// Still unsure what this is
|
2020-01-02 05:39:52 +00:00
|
|
|
type MetaInvite struct {
|
2020-01-02 19:53:08 +00:00
|
|
|
Inviter discord.User `json:"user"`
|
|
|
|
Uses uint `json:"uses"`
|
|
|
|
MaxUses uint `json:"max_uses"`
|
2020-01-02 05:39:52 +00:00
|
|
|
|
|
|
|
MaxAge discord.Seconds `json:"max_age"`
|
|
|
|
|
|
|
|
Temporary bool `json:"temporary"`
|
|
|
|
CreatedAt discord.Timestamp `json:"created_at"`
|
|
|
|
}
|
|
|
|
|
2020-01-02 19:53:08 +00:00
|
|
|
func (c *Client) Invite(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
|
|
|
}
|
|
|
|
|
|
|
|
// Nothing says I can't!
|
|
|
|
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-01-06 03:48:39 +00:00
|
|
|
// ChannelInvites is only for guild channels. GuildInvites is for guilds.
|
|
|
|
func (c *Client) ChannelInvites(
|
|
|
|
channelID discord.Snowflake) ([]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-01-06 03:48:39 +00:00
|
|
|
// GuildInvites is for guilds.
|
|
|
|
func (c *Client) GuildInvites(
|
|
|
|
guildID discord.Snowflake) ([]discord.Invite, error) {
|
|
|
|
|
|
|
|
var invs []discord.Invite
|
|
|
|
return invs, c.RequestJSON(&invs, "GET",
|
|
|
|
EndpointGuilds+guildID.String()+"/invites")
|
|
|
|
}
|
|
|
|
|
2020-01-02 05:39:52 +00:00
|
|
|
// CreateInvite is only for guild channels. This endpoint requires
|
|
|
|
// CREATE_INSTANT_INVITE.
|
|
|
|
//
|
|
|
|
// MaxAge is the duration before expiry, 0 for never. MaxUses is the maximum
|
|
|
|
// number of uses, 0 for unlimited. Temporary is whether this invite grants
|
|
|
|
// temporary membership. Unique, if true, tries not to reuse a similar invite,
|
|
|
|
// useful for creating unique one time use invites.
|
2020-01-06 03:48:39 +00:00
|
|
|
func (c *Client) CreateInvite(
|
|
|
|
channelID discord.Snowflake, maxAge discord.Seconds,
|
|
|
|
maxUses uint, temp, unique bool) (*discord.Invite, error) {
|
2020-01-02 05:39:52 +00:00
|
|
|
|
2020-01-06 03:48:39 +00:00
|
|
|
var param struct {
|
2020-01-02 05:39:52 +00:00
|
|
|
MaxAge uint `json:"max_age"`
|
|
|
|
MaxUses uint `json:"max_uses"`
|
|
|
|
Temporary bool `json:"temporary"`
|
|
|
|
Unique bool `json:"unique"`
|
|
|
|
}
|
|
|
|
|
2020-01-06 03:48:39 +00:00
|
|
|
param.MaxAge = uint(maxAge)
|
|
|
|
param.MaxUses = maxUses
|
|
|
|
param.Temporary = temp
|
|
|
|
param.Unique = unique
|
2020-01-02 05:39:52 +00:00
|
|
|
|
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",
|
|
|
|
httputil.WithSchema(c, param),
|
|
|
|
)
|
2020-01-02 05:39:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// DeleteInvite requires either MANAGE_CHANNELS on the target channel, or
|
|
|
|
// MANAGE_GUILD to remove any invite in the guild.
|
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)
|
|
|
|
}
|