2020-01-02 05:39:52 +00:00
|
|
|
package api
|
|
|
|
|
2020-01-04 04:19:24 +00:00
|
|
|
import (
|
2020-01-06 03:48:39 +00:00
|
|
|
"io"
|
2020-05-09 21:59:39 +00:00
|
|
|
"net/url"
|
2020-01-06 03:48:39 +00:00
|
|
|
|
2020-01-04 04:19:24 +00:00
|
|
|
"github.com/diamondburned/arikawa/discord" // for clarity
|
2020-04-09 02:28:40 +00:00
|
|
|
"github.com/diamondburned/arikawa/utils/httputil"
|
2020-05-11 01:14:30 +00:00
|
|
|
"github.com/diamondburned/arikawa/utils/json/option"
|
2020-01-04 04:19:24 +00:00
|
|
|
)
|
|
|
|
|
2020-04-19 16:30:12 +00:00
|
|
|
var EndpointGuilds = Endpoint + "guilds/"
|
2020-01-04 04:19:24 +00:00
|
|
|
|
|
|
|
// https://discordapp.com/developers/docs/resources/guild#create-guild-json-params
|
|
|
|
type CreateGuildData struct {
|
2020-05-11 22:06:19 +00:00
|
|
|
// Name is the name of the guild (2-100 characters)
|
2020-01-06 03:48:39 +00:00
|
|
|
Name string `json:"name"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// VoiceRegion is the voice region id.
|
|
|
|
VoiceRegion string `json:"region,omitempty"`
|
|
|
|
// Icon is the base64 128x128 image for the guild icon.
|
|
|
|
Icon *Image `json:"image,omitempty"`
|
|
|
|
|
|
|
|
// Verification is the verification level.
|
|
|
|
Verification *discord.Verification `json:"verification_level,omitempty"`
|
|
|
|
// Notification is the default message notification level.
|
|
|
|
Notification *discord.Notification `json:"default_message_notifications,omitempty"`
|
|
|
|
// ExplicitFilter is the explicit content filter level.
|
|
|
|
ExplicitFilter *discord.ExplicitFilter `json:"explicit_content_filter,omitempty"`
|
|
|
|
|
|
|
|
// Roles are the new guild roles.
|
|
|
|
//
|
|
|
|
// When using the roles parameter, the first member of the array is used to
|
|
|
|
// change properties of the guild's @everyone role. If you are trying to
|
|
|
|
// bootstrap a guild with additional roles, keep this in mind.
|
|
|
|
//
|
|
|
|
// When using the roles parameter, the required id field within each role
|
|
|
|
// object is an integer placeholder, and will be replaced by the API upon
|
|
|
|
// consumption. Its purpose is to allow you to overwrite a role's
|
|
|
|
// permissions in a channel when also passing in channels with the channels
|
|
|
|
// array.
|
2020-01-06 03:48:39 +00:00
|
|
|
Roles []discord.Role `json:"roles,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// Channels are the new guild's channels.
|
|
|
|
// Assigning a channel to a channel category is not supported by this
|
|
|
|
// endpoint, i.e. a channel can't have the parent_id field.
|
|
|
|
//
|
|
|
|
// When using the channels parameter, the position field is ignored,
|
|
|
|
// and none of the default channels are created.
|
|
|
|
//
|
|
|
|
// When using the channels parameter, the id field within each channel
|
|
|
|
// object may be set to an integer placeholder, and will be replaced by the
|
|
|
|
// API upon consumption. Its purpose is to allow you to create
|
|
|
|
// GUILD_CATEGORY channels by setting the parent_id field on any children
|
|
|
|
// to the category's id field. Category channels must be listed before any
|
|
|
|
// children.
|
|
|
|
Channels []discord.Channel `json:"channels,omitempty"`
|
2020-01-06 03:48:39 +00:00
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// AFKChannelID is the id for the afk channel.
|
2020-07-21 20:27:59 +00:00
|
|
|
AFKChannelID discord.ChannelID `json:"afk_channel_id,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// AFKTimeout is the afk timeout in seconds.
|
|
|
|
AFKTimeout option.Seconds `json:"afk_timeout,omitempty"`
|
2020-01-04 04:19:24 +00:00
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// SystemChannelID is the id of the channel where guild notices such as
|
|
|
|
// welcome messages and boost events are posted.
|
2020-07-21 20:27:59 +00:00
|
|
|
SystemChannelID discord.ChannelID `json:"system_channel_id,omitempty"`
|
2020-01-04 04:19:24 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// CreateGuild creates a new guild. Returns a guild object on success.
|
|
|
|
// Fires a Guild Create Gateway event.
|
|
|
|
//
|
|
|
|
// This endpoint can be used only by bots in less than 10 guilds.
|
2020-01-04 04:19:24 +00:00
|
|
|
func (c *Client) CreateGuild(data CreateGuildData) (*discord.Guild, error) {
|
|
|
|
var g *discord.Guild
|
2020-05-08 03:43:46 +00:00
|
|
|
return g, c.RequestJSON(&g, "POST", Endpoint+"guilds", httputil.WithJSONBody(data))
|
2020-01-04 04:19:24 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// Guild returns the guild object for the given id.
|
|
|
|
// ApproximateMembers and ApproximatePresences will not be set.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) Guild(id discord.GuildID) (*discord.Guild, error) {
|
2020-01-04 04:19:24 +00:00
|
|
|
var g *discord.Guild
|
2020-05-08 00:09:45 +00:00
|
|
|
return g, c.RequestJSON(&g, "GET", EndpointGuilds+id.String())
|
2020-01-04 04:19:24 +00:00
|
|
|
}
|
|
|
|
|
2020-05-15 18:02:49 +00:00
|
|
|
// GuildPreview returns the guild preview object for the given id, even if the
|
|
|
|
// user is not in the guild.
|
|
|
|
//
|
|
|
|
// This endpoint is only for public guilds.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) GuildPreview(id discord.GuildID) (*discord.GuildPreview, error) {
|
2020-05-15 18:02:49 +00:00
|
|
|
var g *discord.GuildPreview
|
|
|
|
return g, c.RequestJSON(&g, "GET", EndpointGuilds+id.String()+"/preview")
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// GuildWithCount returns the guild object for the given id.
|
|
|
|
// This will also set the ApproximateMembers and ApproximatePresences fields
|
|
|
|
// of the guild struct.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) GuildWithCount(id discord.GuildID) (*discord.Guild, error) {
|
2020-05-09 21:59:39 +00:00
|
|
|
var g *discord.Guild
|
|
|
|
return g, c.RequestJSON(
|
|
|
|
&g, "GET",
|
|
|
|
EndpointGuilds+id.String(),
|
|
|
|
httputil.WithSchema(c, url.Values{
|
|
|
|
"with_counts": {"true"},
|
|
|
|
}),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-16 23:35:57 +00:00
|
|
|
// Guilds returns a list of partial guild objects the current user is a member
|
|
|
|
// of. This method automatically paginates until it reaches the passed limit,
|
|
|
|
// or, if the limit is set to 0, has fetched all guilds within the passed
|
|
|
|
// range.
|
2020-05-11 22:06:19 +00:00
|
|
|
//
|
2020-05-16 23:35:57 +00:00
|
|
|
// As the underlying endpoint has a maximum of 100 guilds per request, at
|
|
|
|
// maximum a total of limit/100 rounded up requests will be made, although they
|
|
|
|
// may be less, if no more guilds are available.
|
|
|
|
//
|
|
|
|
// When fetching the guilds, those with the smallest ID will be fetched first.
|
|
|
|
//
|
|
|
|
// Also note that 100 is the maximum number of guilds a non-bot user can join.
|
|
|
|
// Therefore, pagination is not needed for integrations that need to get a list
|
|
|
|
// of the users' guilds.
|
|
|
|
//
|
|
|
|
// Requires the guilds OAuth2 scope.
|
|
|
|
func (c *Client) Guilds(limit uint) ([]discord.Guild, error) {
|
|
|
|
return c.GuildsAfter(0, limit)
|
|
|
|
}
|
|
|
|
|
|
|
|
// GuildsBefore returns a list of partial guild objects the current user is a
|
|
|
|
// member of. This method automatically paginates until it reaches the
|
|
|
|
// passed limit, or, if the limit is set to 0, has fetched all guilds within
|
|
|
|
// the passed range.
|
|
|
|
//
|
|
|
|
// As the underlying endpoint has a maximum of 100 guilds per request, at
|
|
|
|
// maximum a total of limit/100 rounded up requests will be made, although they
|
|
|
|
// may be less, if no more guilds are available.
|
|
|
|
//
|
|
|
|
// Requires the guilds OAuth2 scope.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) GuildsBefore(before discord.GuildID, limit uint) ([]discord.Guild, error) {
|
2020-01-16 04:27:57 +00:00
|
|
|
var guilds []discord.Guild
|
2020-01-06 05:22:26 +00:00
|
|
|
|
2020-05-16 23:35:57 +00:00
|
|
|
// this is the limit of max guilds per request,as imposed by Discord
|
2020-01-16 04:27:57 +00:00
|
|
|
const hardLimit int = 100
|
2020-01-07 06:45:29 +00:00
|
|
|
|
2020-05-16 23:35:57 +00:00
|
|
|
unlimited := limit == 0
|
2020-05-11 22:06:19 +00:00
|
|
|
|
2020-05-16 23:35:57 +00:00
|
|
|
for fetch := uint(hardLimit); limit > 0 || unlimited; fetch = uint(hardLimit) {
|
|
|
|
if limit > 0 {
|
|
|
|
if fetch > limit {
|
|
|
|
fetch = limit
|
2020-01-18 19:34:08 +00:00
|
|
|
}
|
2020-05-16 23:35:57 +00:00
|
|
|
limit -= fetch
|
2020-01-07 06:45:29 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 23:35:57 +00:00
|
|
|
g, err := c.guildsRange(before, 0, fetch)
|
2020-01-06 05:22:26 +00:00
|
|
|
if err != nil {
|
2020-01-16 04:27:57 +00:00
|
|
|
return guilds, err
|
2020-01-06 05:22:26 +00:00
|
|
|
}
|
2020-05-16 23:35:57 +00:00
|
|
|
guilds = append(g, guilds...)
|
2020-01-06 05:22:26 +00:00
|
|
|
|
2020-01-16 04:27:57 +00:00
|
|
|
if len(g) < hardLimit {
|
2020-01-06 05:22:26 +00:00
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2020-05-16 23:35:57 +00:00
|
|
|
before = g[0].ID
|
2020-01-06 05:22:26 +00:00
|
|
|
}
|
|
|
|
|
2020-01-16 04:27:57 +00:00
|
|
|
return guilds, nil
|
2020-01-06 05:22:26 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 23:35:57 +00:00
|
|
|
// GuildsAfter returns a list of partial guild objects the current user is a
|
|
|
|
// member of. This method automatically paginates until it reaches the
|
|
|
|
// passed limit, or, if the limit is set to 0, has fetched all guilds within
|
|
|
|
// the passed range.
|
|
|
|
//
|
|
|
|
// As the underlying endpoint has a maximum of 100 guilds per request, at
|
|
|
|
// maximum a total of limit/100 rounded up requests will be made, although they
|
|
|
|
// may be less, if no more guilds are available.
|
|
|
|
//
|
|
|
|
// Requires the guilds OAuth2 scope.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) GuildsAfter(after discord.GuildID, limit uint) ([]discord.Guild, error) {
|
2020-05-16 23:35:57 +00:00
|
|
|
var guilds []discord.Guild
|
2020-01-05 07:50:22 +00:00
|
|
|
|
2020-05-16 23:35:57 +00:00
|
|
|
// this is the limit of max guilds per request, as imposed by Discord
|
|
|
|
const hardLimit int = 100
|
|
|
|
|
|
|
|
unlimited := limit == 0
|
|
|
|
|
|
|
|
for fetch := uint(hardLimit); limit > 0 || unlimited; fetch = uint(hardLimit) {
|
|
|
|
if limit > 0 {
|
|
|
|
if fetch > limit {
|
|
|
|
fetch = limit
|
|
|
|
}
|
|
|
|
limit -= fetch
|
|
|
|
}
|
|
|
|
|
|
|
|
g, err := c.guildsRange(0, after, fetch)
|
|
|
|
if err != nil {
|
|
|
|
return guilds, err
|
|
|
|
}
|
|
|
|
guilds = append(guilds, g...)
|
|
|
|
|
|
|
|
if len(g) < hardLimit {
|
|
|
|
break
|
|
|
|
}
|
|
|
|
|
2020-05-22 22:59:27 +00:00
|
|
|
after = g[len(g)-1].ID
|
2020-01-05 07:50:22 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 23:35:57 +00:00
|
|
|
return guilds, nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func (c *Client) guildsRange(
|
2020-07-21 20:27:59 +00:00
|
|
|
before, after discord.GuildID, limit uint) ([]discord.Guild, error) {
|
2020-05-16 23:35:57 +00:00
|
|
|
|
2020-01-05 07:50:22 +00:00
|
|
|
var param struct {
|
2020-07-21 20:27:59 +00:00
|
|
|
Before discord.GuildID `schema:"before,omitempty"`
|
|
|
|
After discord.GuildID `schema:"after,omitempty"`
|
2020-01-16 04:27:57 +00:00
|
|
|
|
|
|
|
Limit uint `schema:"limit"`
|
2020-01-05 07:50:22 +00:00
|
|
|
}
|
|
|
|
|
2020-01-16 04:27:57 +00:00
|
|
|
param.Before = before
|
|
|
|
param.After = after
|
|
|
|
param.Limit = limit
|
2020-01-05 07:50:22 +00:00
|
|
|
|
2020-01-16 04:27:57 +00:00
|
|
|
var gs []discord.Guild
|
|
|
|
return gs, c.RequestJSON(
|
|
|
|
&gs, "GET",
|
|
|
|
EndpointMe+"/guilds",
|
2020-01-06 03:48:39 +00:00
|
|
|
httputil.WithSchema(c, param),
|
2020-01-05 07:50:22 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// LeaveGuild leaves a guild.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) LeaveGuild(id discord.GuildID) error {
|
2020-05-08 00:09:45 +00:00
|
|
|
return c.FastRequest("DELETE", EndpointMe+"/guilds/"+id.String())
|
2020-01-05 07:50:22 +00:00
|
|
|
}
|
|
|
|
|
2020-01-16 04:27:57 +00:00
|
|
|
// https://discordapp.com/developers/docs/resources/guild#modify-guild-json-params
|
|
|
|
type ModifyGuildData struct {
|
2020-05-11 22:06:19 +00:00
|
|
|
// Name is the guild's name.
|
|
|
|
Name string `json:"name,omitempty"`
|
|
|
|
// Region is the guild's voice region id.
|
|
|
|
Region option.NullableString `json:"region,omitempty"`
|
|
|
|
|
|
|
|
// Verification is the verification level.
|
|
|
|
//
|
|
|
|
// This field is nullable.
|
|
|
|
Verification *discord.Verification `json:"verification_level,omitempty"`
|
|
|
|
// Notification is the default message notification level.
|
|
|
|
//
|
|
|
|
// This field is nullable.
|
|
|
|
Notification *discord.Notification `json:"default_message_notifications,omitempty"`
|
|
|
|
// ExplicitFilter is the explicit content filter level.
|
|
|
|
//
|
|
|
|
// This field is nullable.
|
|
|
|
ExplicitFilter *discord.ExplicitFilter `json:"explicit_content_filter,omitempty"`
|
|
|
|
|
|
|
|
// AFKChannelID is the id for the afk channel.
|
|
|
|
//
|
|
|
|
// This field is nullable.
|
2020-07-21 20:27:59 +00:00
|
|
|
AFKChannelID discord.ChannelID `json:"afk_channel_id,string,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// AFKTimeout is the afk timeout in seconds.
|
|
|
|
AFKTimeout option.Seconds `json:"afk_timeout,omitempty"`
|
|
|
|
// Icon is the base64 1024x1024 png/jpeg/gif image for the guild icon
|
|
|
|
// (can be animated gif when the server has the ANIMATED_ICON feature).
|
|
|
|
Icon *Image `json:"icon,omitempty"`
|
|
|
|
// Splash is the base64 16:9 png/jpeg image for the guild splash
|
|
|
|
// (when the server has the INVITE_SPLASH feature).
|
2020-05-07 19:32:56 +00:00
|
|
|
Splash *Image `json:"splash,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// Banner is the base64 16:9 png/jpeg image for the guild banner (when the
|
|
|
|
// server has BANNER feature).
|
2020-05-07 19:32:56 +00:00
|
|
|
Banner *Image `json:"banner,omitempty"`
|
2020-01-05 07:50:22 +00:00
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// OwnerID is the user id to transfer guild ownership to (must be owner).
|
2020-07-21 20:27:59 +00:00
|
|
|
OwnerID discord.UserID `json:"owner_id,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
|
|
|
|
// SystemChannelID is the id of the channel where guild notices such as
|
|
|
|
// welcome messages and boost events are posted.
|
|
|
|
//
|
|
|
|
// This field is nullable.
|
2020-07-21 20:27:59 +00:00
|
|
|
SystemChannelID discord.ChannelID `json:"system_channel_id,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// RulesChannelID is the id of the channel where "PUBLIC" guilds display
|
|
|
|
// rules and/or guidelines.
|
|
|
|
//
|
|
|
|
// This field is nullable.
|
2020-07-21 20:27:59 +00:00
|
|
|
RulesChannelID discord.ChannelID `json:"rules_channel_id,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// PublicUpdatesChannelID is the id of the channel where admins and
|
|
|
|
// moderators of "PUBLIC" guilds receive notices from Discord.
|
|
|
|
//
|
|
|
|
// This field is nullable.
|
2020-07-21 20:27:59 +00:00
|
|
|
PublicUpdatesChannelID discord.ChannelID `json:"public_updates_channel_id,omitempty"`
|
2020-05-07 19:32:56 +00:00
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// PreferredLocale is the preferred locale of a "PUBLIC" guild used in
|
|
|
|
// server discovery and notices from Discord.
|
|
|
|
//
|
|
|
|
// This defaults to "en-US".
|
|
|
|
PreferredLocale option.NullableString `json:"preferred_locale,omitempty"`
|
2020-01-05 07:50:22 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// ModifyGuild modifies a guild's settings. Requires the MANAGE_GUILD permission.
|
|
|
|
// Fires a Guild Update Gateway event.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) ModifyGuild(id discord.GuildID, data ModifyGuildData) (*discord.Guild, error) {
|
2020-01-16 04:27:57 +00:00
|
|
|
var g *discord.Guild
|
|
|
|
return g, c.RequestJSON(
|
|
|
|
&g, "PATCH",
|
2020-05-08 00:09:45 +00:00
|
|
|
EndpointGuilds+id.String(),
|
2020-05-08 03:43:46 +00:00
|
|
|
httputil.WithJSONBody(data),
|
2020-01-05 07:50:22 +00:00
|
|
|
)
|
2020-05-11 18:24:28 +00:00
|
|
|
|
2020-01-05 07:50:22 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// DeleteGuild deletes a guild permanently. The User must be owner.
|
|
|
|
//
|
|
|
|
// Fires a Guild Delete Gateway event.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) DeleteGuild(id discord.GuildID) error {
|
2020-05-08 00:09:45 +00:00
|
|
|
return c.FastRequest("DELETE", EndpointGuilds+id.String())
|
2020-01-06 03:48:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// GuildVoiceRegions is the same as /voice, but returns VIP ones as well if
|
|
|
|
// available.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) VoiceRegionsGuild(guildID discord.GuildID) ([]discord.VoiceRegion, error) {
|
2020-01-06 03:48:39 +00:00
|
|
|
var vrs []discord.VoiceRegion
|
2020-04-19 21:53:53 +00:00
|
|
|
return vrs, c.RequestJSON(&vrs, "GET", EndpointGuilds+guildID.String()+"/regions")
|
2020-01-06 03:48:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// https://discord.com/developers/docs/resources/audit-log#get-guild-audit-log-query-string-parameters
|
2020-05-08 00:09:45 +00:00
|
|
|
type AuditLogData struct {
|
2020-05-11 22:06:19 +00:00
|
|
|
// UserID filters the log for actions made by a user.
|
2020-07-21 20:27:59 +00:00
|
|
|
UserID discord.UserID `schema:"user_id,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// ActionType is the type of audit log event.
|
2020-05-08 03:01:44 +00:00
|
|
|
ActionType discord.AuditLogEvent `schema:"action_type,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// Before filters the log before a certain entry ID.
|
2020-07-29 20:58:39 +00:00
|
|
|
Before discord.AuditLogEntryID `schema:"before,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
// Limit limits how many entries are returned (default 50, minimum 1,
|
|
|
|
// maximum 100).
|
2020-05-08 03:01:44 +00:00
|
|
|
Limit uint `schema:"limit"`
|
2020-05-08 00:09:45 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// AuditLog returns an audit log object for the guild.
|
|
|
|
//
|
|
|
|
// Requires the VIEW_AUDIT_LOG permission.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) AuditLog(guildID discord.GuildID, data AuditLogData) (*discord.AuditLog, error) {
|
2020-05-08 00:09:45 +00:00
|
|
|
switch {
|
|
|
|
case data.Limit == 0:
|
|
|
|
data.Limit = 50
|
|
|
|
case data.Limit > 100:
|
|
|
|
data.Limit = 100
|
|
|
|
}
|
|
|
|
|
|
|
|
var audit *discord.AuditLog
|
|
|
|
|
|
|
|
return audit, c.RequestJSON(
|
|
|
|
&audit, "GET",
|
|
|
|
EndpointGuilds+guildID.String()+"/audit-logs",
|
2020-05-08 03:01:44 +00:00
|
|
|
httputil.WithSchema(c, data),
|
2020-05-08 00:09:45 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// Integrations returns a list of integration objects for the guild.
|
|
|
|
//
|
|
|
|
// Requires the MANAGE_GUILD permission.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) Integrations(guildID discord.GuildID) ([]discord.Integration, error) {
|
2020-01-06 03:48:39 +00:00
|
|
|
var ints []discord.Integration
|
2020-04-19 21:53:53 +00:00
|
|
|
return ints, c.RequestJSON(&ints, "GET", EndpointGuilds+guildID.String()+"/integrations")
|
2020-01-06 03:48:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// AttachIntegration attaches an integration object from the current user to
|
|
|
|
// the guild.
|
|
|
|
//
|
|
|
|
// Requires the MANAGE_GUILD permission.
|
|
|
|
// Fires a Guild Integrations Update Gateway event.
|
2020-07-30 02:48:20 +00:00
|
|
|
func (c *Client) AttachIntegration(
|
|
|
|
guildID discord.GuildID, integrationID discord.IntegrationID,
|
|
|
|
integrationType discord.Service) error {
|
2020-01-06 03:48:39 +00:00
|
|
|
|
|
|
|
var param struct {
|
2020-07-21 20:27:59 +00:00
|
|
|
Type discord.Service `json:"type"`
|
|
|
|
ID discord.IntegrationID `json:"id"`
|
2020-01-06 03:48:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 18:32:28 +00:00
|
|
|
param.Type = integrationType
|
|
|
|
param.ID = integrationID
|
|
|
|
|
2020-01-06 03:48:39 +00:00
|
|
|
return c.FastRequest(
|
|
|
|
"POST",
|
|
|
|
EndpointGuilds+guildID.String()+"/integrations",
|
2020-05-08 03:43:46 +00:00
|
|
|
httputil.WithJSONBody(param),
|
2020-01-06 03:48:39 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-10 23:48:26 +00:00
|
|
|
// https://discord.com/developers/docs/resources/guild#modify-guild-integration-json-params
|
|
|
|
type ModifyIntegrationData struct {
|
2020-05-11 22:06:19 +00:00
|
|
|
// ExpireBehavior is the behavior when an integration subscription lapses
|
|
|
|
// (see the integration expire behaviors documentation).
|
|
|
|
ExpireBehavior *discord.ExpireBehavior `json:"expire_behavior,omitempty"`
|
|
|
|
// ExpireGracePeriod is the period (in days) where the integration will
|
|
|
|
// ignore lapsed subscriptions.
|
|
|
|
ExpireGracePeriod option.NullableInt `json:"expire_grace_period,omitempty"`
|
|
|
|
// EnableEmoticons specifies whether emoticons should be synced for this
|
|
|
|
// integration (twitch only currently).
|
|
|
|
EnableEmoticons option.NullableBool `json:"enable_emoticons,omitempty"`
|
2020-05-10 23:48:26 +00:00
|
|
|
}
|
2020-01-06 03:48:39 +00:00
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// ModifyIntegration modifies the behavior and settings of an integration
|
|
|
|
// object for the guild.
|
|
|
|
//
|
|
|
|
// Requires the MANAGE_GUILD permission.
|
|
|
|
// Fires a Guild Integrations Update Gateway event.
|
|
|
|
func (c *Client) ModifyIntegration(
|
2020-07-21 20:27:59 +00:00
|
|
|
guildID discord.GuildID, integrationID discord.IntegrationID, data ModifyIntegrationData) error {
|
2020-01-16 04:27:57 +00:00
|
|
|
return c.FastRequest(
|
2020-05-11 22:06:19 +00:00
|
|
|
"PATCH",
|
|
|
|
EndpointGuilds+guildID.String()+"/integrations/"+integrationID.String(),
|
2020-05-10 23:48:26 +00:00
|
|
|
httputil.WithJSONBody(data),
|
2020-01-06 03:48:39 +00:00
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// Sync an integration. Requires the MANAGE_GUILD permission.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) SyncIntegration(guildID discord.GuildID, integrationID discord.IntegrationID) error {
|
2020-05-11 22:06:19 +00:00
|
|
|
return c.FastRequest(
|
|
|
|
"POST",
|
|
|
|
EndpointGuilds+guildID.String()+"/integrations/"+integrationID.String()+"/sync",
|
|
|
|
)
|
2020-01-06 03:48:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 15:57:25 +00:00
|
|
|
// GuildWidget returns the guild widget object.
|
2020-05-11 22:06:19 +00:00
|
|
|
//
|
|
|
|
// Requires the MANAGE_GUILD permission.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) GuildWidget(guildID discord.GuildID) (*discord.GuildWidget, error) {
|
2020-05-16 15:57:25 +00:00
|
|
|
var ge *discord.GuildWidget
|
2020-05-17 14:20:42 +00:00
|
|
|
return ge, c.RequestJSON(&ge, "GET", EndpointGuilds+guildID.String()+"/widget")
|
2020-01-06 03:48:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// https://discord.com/developers/docs/resources/guild#guild-embed-object-guild-embed-structure
|
2020-05-16 15:57:25 +00:00
|
|
|
type ModifyGuildWidgetData struct {
|
|
|
|
// Enabled specifies whether the widget is enabled.
|
|
|
|
Enabled option.Bool `json:"enabled,omitempty"`
|
|
|
|
// ChannelID is the widget channel id.
|
2020-07-21 20:27:59 +00:00
|
|
|
ChannelID discord.ChannelID `json:"channel_id,omitempty"`
|
2020-05-11 22:06:19 +00:00
|
|
|
}
|
|
|
|
|
2020-05-16 15:57:25 +00:00
|
|
|
// ModifyGuildWidget modifies a guild widget object for the guild.
|
2020-04-19 21:53:53 +00:00
|
|
|
//
|
2020-05-16 15:57:25 +00:00
|
|
|
// Requires the MANAGE_GUILD permission.
|
|
|
|
func (c *Client) ModifyGuildWidget(
|
2020-07-21 20:27:59 +00:00
|
|
|
guildID discord.GuildID, data ModifyGuildWidgetData) (*discord.GuildWidget, error) {
|
2020-05-16 15:57:25 +00:00
|
|
|
|
|
|
|
var w *discord.GuildWidget
|
|
|
|
return w, c.RequestJSON(
|
|
|
|
&w, "PATCH",
|
2020-05-17 14:20:42 +00:00
|
|
|
EndpointGuilds+guildID.String()+"/widget",
|
2020-05-16 15:57:25 +00:00
|
|
|
httputil.WithJSONBody(data),
|
|
|
|
)
|
2020-01-06 03:48:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// GuildVanityURL returns *Invite for guilds that have that feature enabled,
|
|
|
|
// but only Code and Uses are filled. Code will be "" if a vanity url for the
|
|
|
|
// guild is not set.
|
|
|
|
//
|
|
|
|
// Requires MANAGE_GUILD.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) GuildVanityURL(guildID discord.GuildID) (*discord.Invite, error) {
|
2020-01-06 03:48:39 +00:00
|
|
|
var inv *discord.Invite
|
2020-04-19 21:53:53 +00:00
|
|
|
return inv, c.RequestJSON(&inv, "GET", EndpointGuilds+guildID.String()+"/vanity-url")
|
2020-01-06 03:48:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// https://discord.com/developers/docs/resources/guild#get-guild-widget-image-widget-style-options
|
2020-05-10 20:13:47 +00:00
|
|
|
type GuildImageStyle string
|
2020-01-06 03:48:39 +00:00
|
|
|
|
|
|
|
const (
|
2020-05-11 22:06:19 +00:00
|
|
|
// GuildShield is a shield style widget with Discord icon and guild members
|
|
|
|
// online count.
|
|
|
|
//
|
|
|
|
// Example: https://discordapp.com/api/guilds/81384788765712384/widget.png?style=shield
|
|
|
|
GuildShield GuildImageStyle = "shield"
|
|
|
|
// GuildBanner1 is a large image with guild icon, name and online count.
|
|
|
|
// "POWERED BY DISCORD" as the footer of the widget.
|
|
|
|
//
|
|
|
|
// Example: https://discordapp.com/api/guilds/81384788765712384/widget.png?style=banner1
|
2020-05-10 20:13:47 +00:00
|
|
|
GuildBanner1 GuildImageStyle = "banner1"
|
2020-05-11 22:06:19 +00:00
|
|
|
// GuildBanner2 is a smaller widget style with guild icon, name and online
|
|
|
|
// count. Split on the right with Discord logo.
|
|
|
|
//
|
|
|
|
// Example: https://discordapp.com/api/guilds/81384788765712384/widget.png?style=banner2
|
2020-05-10 20:13:47 +00:00
|
|
|
GuildBanner2 GuildImageStyle = "banner2"
|
2020-05-11 22:06:19 +00:00
|
|
|
// GuildBanner3 is a large image with guild icon, name and online count. In
|
|
|
|
// the footer, Discord logo on the left and "Chat Now" on the right.
|
|
|
|
//
|
|
|
|
// Example: https://discordapp.com/api/guilds/81384788765712384/widget.png?style=banner3
|
2020-05-10 20:13:47 +00:00
|
|
|
GuildBanner3 GuildImageStyle = "banner3"
|
2020-05-11 22:06:19 +00:00
|
|
|
// GuildBanner4 is a large Discord logo at the top of the widget.
|
|
|
|
// Guild icon, name and online count in the middle portion of the widget
|
|
|
|
// and a "JOIN MY SERVER" button at the bottom.
|
|
|
|
//
|
|
|
|
// Example: https://discordapp.com/api/guilds/81384788765712384/widget.png?style=banner4
|
2020-05-10 20:13:47 +00:00
|
|
|
GuildBanner4 GuildImageStyle = "banner4"
|
2020-01-06 03:48:39 +00:00
|
|
|
)
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// GuildImageURL returns a link to the PNG image widget for the guild.
|
|
|
|
//
|
|
|
|
// Requires no permissions or authentication.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) GuildImageURL(guildID discord.GuildID, img GuildImageStyle) string {
|
2020-04-19 21:53:53 +00:00
|
|
|
return EndpointGuilds + guildID.String() + "/widget.png?style=" + string(img)
|
2020-01-06 03:48:39 +00:00
|
|
|
}
|
|
|
|
|
2020-05-11 22:06:19 +00:00
|
|
|
// GuildImage returns a PNG image widget for the guild. Requires no permissions
|
|
|
|
// or authentication.
|
2020-07-21 20:27:59 +00:00
|
|
|
func (c *Client) GuildImage(guildID discord.GuildID, img GuildImageStyle) (io.ReadCloser, error) {
|
2020-01-06 03:48:39 +00:00
|
|
|
r, err := c.Request("GET", c.GuildImageURL(guildID, img))
|
|
|
|
if err != nil {
|
|
|
|
return nil, err
|
|
|
|
}
|
|
|
|
|
2020-04-19 21:53:53 +00:00
|
|
|
return r.GetBody(), nil
|
2020-01-06 03:48:39 +00:00
|
|
|
}
|