1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-12-01 03:03:48 +00:00
arikawa/api/invite.go

103 lines
3.1 KiB
Go
Raw Normal View History

2020-01-02 05:39:52 +00:00
package api
import (
"github.com/diamondburned/arikawa/discord"
"github.com/diamondburned/arikawa/utils/httputil"
2020-05-11 22:06:19 +00:00
"github.com/diamondburned/arikawa/utils/json/option"
)
2020-01-02 05:39:52 +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.
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
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.
func (c *Client) ChannelInvites(channelID discord.ChannelID) ([]discord.Invite, error) {
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.
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(
channelID discord.ChannelID, data CreateInviteData) (*discord.Invite, error) {
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.
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)
}