1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2025-11-22 04:23:39 +00:00

api: Add support for the X-Audit-Log-Reason header (#259)

* api: add support for the X-Audit-Log-Reason header

* api: inline reason parameter, where data struct has a single field
This commit is contained in:
Maximilian von Lindern 2021-08-15 18:33:33 +02:00 committed by GitHub
parent dbfc49fb08
commit 244570c280
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
13 changed files with 303 additions and 157 deletions

View file

@ -80,3 +80,18 @@ type Session struct {
Token string Token string
UserAgent string UserAgent string
} }
// AuditLogReason is the type embedded in data structs when the action
// performed by calling that api endpoint supports attaching a custom audit log
// reason.
type AuditLogReason string
// Header returns a http.Header containing the reason, or nil if the reason is
// empty.
func (r AuditLogReason) Header() http.Header {
if len(r) == 0 {
return nil
}
return http.Header{"X-Audit-Log-Reason": []string{string(r)}}
}

View file

@ -90,8 +90,7 @@ func (c *Client) GuildCommands(
func (c *Client) GuildCommand( func (c *Client) GuildCommand(
appID discord.AppID, appID discord.AppID,
guildID discord.GuildID, guildID discord.GuildID, commandID discord.CommandID) (discord.Command, error) {
commandID discord.CommandID) (discord.Command, error) {
var cmd discord.Command var cmd discord.Command
return cmd, c.RequestJSON( return cmd, c.RequestJSON(

View file

@ -71,6 +71,8 @@ type CreateChannelData struct {
// //
// ChannelTypes: Voice // ChannelTypes: Voice
VoiceQualityMode discord.VideoQualityMode `json:"voice_quality_mode,omitempty"` VoiceQualityMode discord.VideoQualityMode `json:"voice_quality_mode,omitempty"`
AuditLogReason `json:"-"`
} }
// CreateChannel creates a new channel object for the guild. // CreateChannel creates a new channel object for the guild.
@ -83,35 +85,46 @@ type CreateChannelData struct {
// Fires a ChannelCreate Gateway event. // Fires a ChannelCreate Gateway event.
func (c *Client) CreateChannel( func (c *Client) CreateChannel(
guildID discord.GuildID, data CreateChannelData) (*discord.Channel, error) { guildID discord.GuildID, data CreateChannelData) (*discord.Channel, error) {
var ch *discord.Channel var ch *discord.Channel
return ch, c.RequestJSON( return ch, c.RequestJSON(
&ch, "POST", &ch, "POST",
EndpointGuilds+guildID.String()+"/channels", EndpointGuilds+guildID.String()+"/channels",
httputil.WithJSONBody(data), httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
) )
} }
type MoveChannelData struct { type (
// ID is the channel id. MoveChannelsData struct {
ID discord.ChannelID `json:"id"` // Channels are the channels to be moved.
// Position is the sorting position of the channel. Channels []MoveChannelData
Position option.Int `json:"position"`
// LockPermissions syncs the permission overwrites with the new parent,
// if moving to a new category.
LockPermissions option.Bool `json:"lock_permissions"`
// CategoryID is the new parent ID for the channel that is moved.
CategoryID discord.ChannelID `json:"parent_id"`
}
// MoveChannel modifies the position of channels in the guild. AuditLogReason
}
MoveChannelData struct {
// ID is the channel id.
ID discord.ChannelID `json:"id"`
// Position is the sorting position of the channel.
Position option.Int `json:"position"`
// LockPermissions syncs the permission overwrites with the new parent,
// if moving to a new category.
LockPermissions option.Bool `json:"lock_permissions"`
// CategoryID is the new parent ID for the channel that is moved.
CategoryID discord.ChannelID `json:"parent_id"`
}
)
// MoveChannels modifies the position of channels in the guild.
// //
// Requires MANAGE_CHANNELS. // Requires MANAGE_CHANNELS.
// //
// Fires multiple Channel Update Gateway events. // Fires multiple Channel Update Gateway events.
func (c *Client) MoveChannel(guildID discord.GuildID, data []MoveChannelData) error { func (c *Client) MoveChannels(guildID discord.GuildID, data MoveChannelsData) error {
return c.FastRequest( return c.FastRequest(
"PATCH", "PATCH",
EndpointGuilds+guildID.String()+"/channels", httputil.WithJSONBody(data), EndpointGuilds+guildID.String()+"/channels",
httputil.WithJSONBody(data.Channels), httputil.WithHeaders(data.Header()),
) )
} }
@ -187,6 +200,8 @@ type ModifyChannelData struct {
// Locked specifies whether the thread is locked. When a thread is locked, // Locked specifies whether the thread is locked. When a thread is locked,
// only users with MANAGE_THREADS can unarchive it. // only users with MANAGE_THREADS can unarchive it.
Locked option.Bool `json:"locked,omitempty"` Locked option.Bool `json:"locked,omitempty"`
AuditLogReason `json:"-"`
} }
// ModifyChannel updates a channel's settings. // ModifyChannel updates a channel's settings.
@ -201,7 +216,10 @@ type ModifyChannelData struct {
// Fires a Channel Update event when modifying a guild channel, and a Thread // Fires a Channel Update event when modifying a guild channel, and a Thread
// Update event when modifying a thread. // Update event when modifying a thread.
func (c *Client) ModifyChannel(channelID discord.ChannelID, data ModifyChannelData) error { func (c *Client) ModifyChannel(channelID discord.ChannelID, data ModifyChannelData) error {
return c.FastRequest("PATCH", EndpointChannels+channelID.String(), httputil.WithJSONBody(data)) return c.FastRequest(
"PATCH", EndpointChannels+channelID.String(),
httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
)
} }
// DeleteChannel deletes a channel, or closes a private message. Requires the // DeleteChannel deletes a channel, or closes a private message. Requires the
@ -210,8 +228,13 @@ func (c *Client) ModifyChannel(channelID discord.ChannelID, data ModifyChannelDa
// Channel Update Gateway event will fire for each of them. // Channel Update Gateway event will fire for each of them.
// //
// Fires a Channel Delete Gateway event. // Fires a Channel Delete Gateway event.
func (c *Client) DeleteChannel(channelID discord.ChannelID) error { func (c *Client) DeleteChannel(
return c.FastRequest("DELETE", EndpointChannels+channelID.String()) channelID discord.ChannelID, reason AuditLogReason) error {
return c.FastRequest(
"DELETE", EndpointChannels+channelID.String(),
httputil.WithHeaders(reason.Header()),
)
} }
// https://discord.com/developers/docs/resources/channel#edit-channel-permissions-json-params // https://discord.com/developers/docs/resources/channel#edit-channel-permissions-json-params
@ -222,6 +245,8 @@ type EditChannelPermissionData struct {
Allow discord.Permissions `json:"allow,string"` Allow discord.Permissions `json:"allow,string"`
// Deny is a permission bit set for denied permissions. // Deny is a permission bit set for denied permissions.
Deny discord.Permissions `json:"deny,string"` Deny discord.Permissions `json:"deny,string"`
AuditLogReason `json:"-"`
} }
// EditChannelPermission edits the channel's permission overwrites for a user // EditChannelPermission edits the channel's permission overwrites for a user
@ -234,7 +259,7 @@ func (c *Client) EditChannelPermission(
return c.FastRequest( return c.FastRequest(
"PUT", EndpointChannels+channelID.String()+"/permissions/"+overwriteID.String(), "PUT", EndpointChannels+channelID.String()+"/permissions/"+overwriteID.String(),
httputil.WithJSONBody(data), httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
) )
} }
@ -242,10 +267,12 @@ func (c *Client) EditChannelPermission(
// role in a channel. Only usable for guild channels. // role in a channel. Only usable for guild channels.
// //
// Requires the MANAGE_ROLES permission. // Requires the MANAGE_ROLES permission.
func (c *Client) DeleteChannelPermission(channelID discord.ChannelID, overwriteID discord.Snowflake) error { func (c *Client) DeleteChannelPermission(
channelID discord.ChannelID, overwriteID discord.Snowflake, reason AuditLogReason) error {
return c.FastRequest( return c.FastRequest(
"DELETE", "DELETE", EndpointChannels+channelID.String()+"/permissions/"+overwriteID.String(),
EndpointChannels+channelID.String()+"/permissions/"+overwriteID.String(), httputil.WithHeaders(reason.Header()),
) )
} }
@ -265,20 +292,30 @@ func (c *Client) PinnedMessages(channelID discord.ChannelID) ([]discord.Message,
// PinMessage pins a message in a channel. // PinMessage pins a message in a channel.
// //
// Requires the MANAGE_MESSAGES permission. // Requires the MANAGE_MESSAGES permission.
func (c *Client) PinMessage(channelID discord.ChannelID, messageID discord.MessageID) error { func (c *Client) PinMessage(
return c.FastRequest("PUT", EndpointChannels+channelID.String()+"/pins/"+messageID.String()) channelID discord.ChannelID, messageID discord.MessageID, reason AuditLogReason) error {
return c.FastRequest(
"PUT", EndpointChannels+channelID.String()+"/pins/"+messageID.String(),
httputil.WithHeaders(reason.Header()),
)
} }
// UnpinMessage deletes a pinned message in a channel. // UnpinMessage deletes a pinned message in a channel.
// //
// Requires the MANAGE_MESSAGES permission. // Requires the MANAGE_MESSAGES permission.
func (c *Client) UnpinMessage(channelID discord.ChannelID, messageID discord.MessageID) error { func (c *Client) UnpinMessage(
return c.FastRequest("DELETE", EndpointChannels+channelID.String()+"/pins/"+messageID.String()) channelID discord.ChannelID, messageID discord.MessageID, reason AuditLogReason) error {
return c.FastRequest(
"DELETE", EndpointChannels+channelID.String()+"/pins/"+messageID.String(),
httputil.WithHeaders(reason.Header()),
)
} }
// AddRecipient adds a user to a group direct message. As accessToken is needed, // AddRecipient adds a user to a group direct message. As accessToken is
// clearly this endpoint should only be used for OAuth. AccessToken can be // needed, clearly this endpoint should only be used for OAuth. AccessToken can
// obtained with the "gdm.join" scope. // be obtained with the "gdm.join" scope.
func (c *Client) AddRecipient( func (c *Client) AddRecipient(
channelID discord.ChannelID, userID discord.UserID, accessToken, nickname string) error { channelID discord.ChannelID, userID discord.UserID, accessToken, nickname string) error {
@ -311,8 +348,8 @@ type Ack struct {
} }
// Ack marks the read state of a channel. This is undocumented. The method will // Ack marks the read state of a channel. This is undocumented. The method will
// write to the ack variable passed in. If this method is called asynchronously, // write to the ack variable passed in. If this method is called
// then ack should be mutex guarded. // asynchronously, then ack should be mutex guarded.
func (c *Client) Ack(channelID discord.ChannelID, messageID discord.MessageID, ack *Ack) error { func (c *Client) Ack(channelID discord.ChannelID, messageID discord.MessageID, ack *Ack) error {
return c.RequestJSON( return c.RequestJSON(
ack, "POST", ack, "POST",
@ -337,6 +374,8 @@ type StartThreadData struct {
// //
// This field can only be used when starting a thread without a message // This field can only be used when starting a thread without a message
Type discord.ChannelType `json:"type,omitempty"` // we can omit, since thread types start at 10 Type discord.ChannelType `json:"type,omitempty"` // we can omit, since thread types start at 10
AuditLogReason `json:"-"`
} }
// StartThreadWithMessage creates a new thread from an existing message. // StartThreadWithMessage creates a new thread from an existing message.
@ -357,7 +396,7 @@ func (c *Client) StartThreadWithMessage(
return ch, c.RequestJSON( return ch, c.RequestJSON(
&ch, "POST", &ch, "POST",
EndpointChannels+channelID.String()+"/messages/"+messageID.String()+"/threads", EndpointChannels+channelID.String()+"/messages/"+messageID.String()+"/threads",
httputil.WithJSONBody(data), httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
) )
} }
@ -372,7 +411,7 @@ func (c *Client) StartThreadWithoutMessage(
return ch, c.RequestJSON( return ch, c.RequestJSON(
&ch, "POST", &ch, "POST",
EndpointChannels+channelID.String()+"/threads", EndpointChannels+channelID.String()+"/threads",
httputil.WithJSONBody(data), httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
) )
} }

View file

@ -26,14 +26,18 @@ type CreateEmojiData struct {
Image Image `json:"image"` Image Image `json:"image"`
// Roles are the roles that can use the emoji. // Roles are the roles that can use the emoji.
Roles *[]discord.RoleID `json:"roles,omitempty"` Roles *[]discord.RoleID `json:"roles,omitempty"`
AuditLogReason `json:"-"`
} }
// CreateEmoji creates a new emoji in the guild. This endpoint requires // CreateEmoji creates a new emoji in the guild. This endpoint requires
// MANAGE_EMOJIS. ContentType must be "image/jpeg", "image/png", or // MANAGE_EMOJIS. ContentType must be "image/jpeg", "image/png", or
// "image/gif". However, ContentType can also be automatically detected // "image/gif". However, ContentType can also be automatically detected (though
// (though shouldn't be relied on). // shouldn't be relied on).
//
// Emojis and animated emojis have a maximum file size of 256kb. // Emojis and animated emojis have a maximum file size of 256kb.
func (c *Client) CreateEmoji(guildID discord.GuildID, data CreateEmojiData) (*discord.Emoji, error) { func (c *Client) CreateEmoji(
guildID discord.GuildID, data CreateEmojiData) (*discord.Emoji, error) {
// Max 256KB // Max 256KB
if err := data.Image.Validate(256 * 1000); err != nil { if err := data.Image.Validate(256 * 1000); err != nil {
@ -44,7 +48,7 @@ func (c *Client) CreateEmoji(guildID discord.GuildID, data CreateEmojiData) (*di
return emj, c.RequestJSON( return emj, c.RequestJSON(
&emj, "POST", &emj, "POST",
EndpointGuilds+guildID.String()+"/emojis", EndpointGuilds+guildID.String()+"/emojis",
httputil.WithJSONBody(data), httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
) )
} }
@ -54,24 +58,34 @@ type ModifyEmojiData struct {
Name string `json:"name,omitempty"` Name string `json:"name,omitempty"`
// Roles are the roles that can use the emoji. // Roles are the roles that can use the emoji.
Roles *[]discord.RoleID `json:"roles,omitempty"` Roles *[]discord.RoleID `json:"roles,omitempty"`
AuditLogReason `json:"-"`
} }
// ModifyEmoji changes an existing emoji. This requires MANAGE_EMOJIS. Name and // ModifyEmoji changes an existing emoji. This requires MANAGE_EMOJIS. Name and
// roles are optional fields (though you'd want to change either though). // roles are optional fields (though you'd want to change either though).
// //
// Fires a Guild Emojis Update Gateway event. // Fires a Guild Emojis Update Gateway event.
func (c *Client) ModifyEmoji(guildID discord.GuildID, emojiID discord.EmojiID, data ModifyEmojiData) error { func (c *Client) ModifyEmoji(
guildID discord.GuildID, emojiID discord.EmojiID, data ModifyEmojiData) error {
return c.FastRequest( return c.FastRequest(
"PATCH", "PATCH",
EndpointGuilds+guildID.String()+"/emojis/"+emojiID.String(), EndpointGuilds+guildID.String()+"/emojis/"+emojiID.String(),
httputil.WithJSONBody(data), httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
) )
} }
// Delete the given emoji. // DeleteEmoji deletes the given emoji.
// //
// Requires the MANAGE_EMOJIS permission. // Requires the MANAGE_EMOJIS permission.
//
// Fires a Guild Emojis Update Gateway event. // Fires a Guild Emojis Update Gateway event.
func (c *Client) DeleteEmoji(guildID discord.GuildID, emojiID discord.EmojiID) error { func (c *Client) DeleteEmoji(
return c.FastRequest("DELETE", EndpointGuilds+guildID.String()+"/emojis/"+emojiID.String()) guildID discord.GuildID, emojiID discord.EmojiID, reason AuditLogReason) error {
return c.FastRequest(
"DELETE", EndpointGuilds+guildID.String()+"/emojis/"+emojiID.String(),
httputil.WithHeaders(reason.Header()),
)
} }

View file

@ -79,6 +79,7 @@ func (c *Client) CreateGuild(data CreateGuildData) (*discord.Guild, error) {
} }
// Guild returns the guild object for the given id. // Guild returns the guild object for the given id.
//
// ApproximateMembers and ApproximatePresences will not be set. // ApproximateMembers and ApproximatePresences will not be set.
func (c *Client) Guild(id discord.GuildID) (*discord.Guild, error) { func (c *Client) Guild(id discord.GuildID) (*discord.Guild, error) {
var g *discord.Guild var g *discord.Guild
@ -94,9 +95,9 @@ func (c *Client) GuildPreview(id discord.GuildID) (*discord.GuildPreview, error)
return g, c.RequestJSON(&g, "GET", EndpointGuilds+id.String()+"/preview") return g, c.RequestJSON(&g, "GET", EndpointGuilds+id.String()+"/preview")
} }
// GuildWithCount returns the guild object for the given id. // GuildWithCount returns the guild object for the given id. This will also
// This will also set the ApproximateMembers and ApproximatePresences fields // set the ApproximateMembers and ApproximatePresences fields of the guild
// of the guild struct. // struct.
func (c *Client) GuildWithCount(id discord.GuildID) (*discord.Guild, error) { func (c *Client) GuildWithCount(id discord.GuildID) (*discord.Guild, error) {
var g *discord.Guild var g *discord.Guild
return g, c.RequestJSON( return g, c.RequestJSON(
@ -217,9 +218,7 @@ func (c *Client) GuildsAfter(after discord.GuildID, limit uint) ([]discord.Guild
return guilds, nil return guilds, nil
} }
func (c *Client) guildsRange( func (c *Client) guildsRange(before, after discord.GuildID, limit uint) ([]discord.Guild, error) {
before, after discord.GuildID, limit uint) ([]discord.Guild, error) {
var param struct { var param struct {
Before discord.GuildID `schema:"before,omitempty"` Before discord.GuildID `schema:"before,omitempty"`
After discord.GuildID `schema:"after,omitempty"` After discord.GuildID `schema:"after,omitempty"`
@ -304,16 +303,21 @@ type ModifyGuildData struct {
// //
// This defaults to "en-US". // This defaults to "en-US".
PreferredLocale option.NullableString `json:"preferred_locale,omitempty"` PreferredLocale option.NullableString `json:"preferred_locale,omitempty"`
AuditLogReason `json:"-"`
} }
// ModifyGuild modifies a guild's settings. Requires the MANAGE_GUILD permission. // ModifyGuild modifies a guild's settings.
//
// Requires the MANAGE_GUILD permission.
//
// Fires a Guild Update Gateway event. // Fires a Guild Update Gateway event.
func (c *Client) ModifyGuild(id discord.GuildID, data ModifyGuildData) (*discord.Guild, error) { func (c *Client) ModifyGuild(id discord.GuildID, data ModifyGuildData) (*discord.Guild, error) {
var g *discord.Guild var g *discord.Guild
return g, c.RequestJSON( return g, c.RequestJSON(
&g, "PATCH", &g, "PATCH",
EndpointGuilds+id.String(), EndpointGuilds+id.String(),
httputil.WithJSONBody(data), httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
) )
} }
@ -325,7 +329,7 @@ func (c *Client) DeleteGuild(id discord.GuildID) error {
return c.FastRequest("DELETE", EndpointGuilds+id.String()) return c.FastRequest("DELETE", EndpointGuilds+id.String())
} }
// GuildVoiceRegions is the same as /voice, but returns VIP ones as well if // VoiceRegionsGuild is the same as /voice, but returns VIP ones as well if
// available. // available.
func (c *Client) VoiceRegionsGuild(guildID discord.GuildID) ([]discord.VoiceRegion, error) { func (c *Client) VoiceRegionsGuild(guildID discord.GuildID) ([]discord.VoiceRegion, error) {
var vrs []discord.VoiceRegion var vrs []discord.VoiceRegion
@ -369,6 +373,7 @@ func (c *Client) AuditLog(guildID discord.GuildID, data AuditLogData) (*discord.
// //
// Requires the MANAGE_GUILD permission. // Requires the MANAGE_GUILD permission.
func (c *Client) Integrations(guildID discord.GuildID) ([]discord.Integration, error) { func (c *Client) Integrations(guildID discord.GuildID) ([]discord.Integration, error) {
var ints []discord.Integration var ints []discord.Integration
return ints, c.RequestJSON(&ints, "GET", EndpointGuilds+guildID.String()+"/integrations") return ints, c.RequestJSON(&ints, "GET", EndpointGuilds+guildID.String()+"/integrations")
} }
@ -377,10 +382,11 @@ func (c *Client) Integrations(guildID discord.GuildID) ([]discord.Integration, e
// the guild. // the guild.
// //
// Requires the MANAGE_GUILD permission. // Requires the MANAGE_GUILD permission.
//
// Fires a Guild Integrations Update Gateway event. // Fires a Guild Integrations Update Gateway event.
func (c *Client) AttachIntegration( func (c *Client) AttachIntegration(
guildID discord.GuildID, integrationID discord.IntegrationID, guildID discord.GuildID,
integrationType discord.Service) error { integrationID discord.IntegrationID, integrationType discord.Service) error {
var param struct { var param struct {
Type discord.Service `json:"type"` Type discord.Service `json:"type"`
@ -416,7 +422,9 @@ type ModifyIntegrationData struct {
// Requires the MANAGE_GUILD permission. // Requires the MANAGE_GUILD permission.
// Fires a Guild Integrations Update Gateway event. // Fires a Guild Integrations Update Gateway event.
func (c *Client) ModifyIntegration( func (c *Client) ModifyIntegration(
guildID discord.GuildID, integrationID discord.IntegrationID, data ModifyIntegrationData) error { guildID discord.GuildID,
integrationID discord.IntegrationID, data ModifyIntegrationData) error {
return c.FastRequest( return c.FastRequest(
"PATCH", "PATCH",
EndpointGuilds+guildID.String()+"/integrations/"+integrationID.String(), EndpointGuilds+guildID.String()+"/integrations/"+integrationID.String(),
@ -424,8 +432,12 @@ func (c *Client) ModifyIntegration(
) )
} }
// Sync an integration. Requires the MANAGE_GUILD permission. // SyncIntegration syncs an integration.
func (c *Client) SyncIntegration(guildID discord.GuildID, integrationID discord.IntegrationID) error { //
// Requires the MANAGE_GUILD permission.
func (c *Client) SyncIntegration(
guildID discord.GuildID, integrationID discord.IntegrationID) error {
return c.FastRequest( return c.FastRequest(
"POST", "POST",
EndpointGuilds+guildID.String()+"/integrations/"+integrationID.String()+"/sync", EndpointGuilds+guildID.String()+"/integrations/"+integrationID.String()+"/sync",
@ -451,6 +463,8 @@ type ModifyGuildWidgetData struct {
Enabled option.Bool `json:"enabled,omitempty"` Enabled option.Bool `json:"enabled,omitempty"`
// ChannelID is the widget channel ID. // ChannelID is the widget channel ID.
ChannelID discord.ChannelID `json:"channel_id,omitempty"` ChannelID discord.ChannelID `json:"channel_id,omitempty"`
AuditLogReason `json:"-"`
} }
// ModifyGuildWidget modifies a guild widget object for the guild. // ModifyGuildWidget modifies a guild widget object for the guild.
@ -463,7 +477,7 @@ func (c *Client) ModifyGuildWidget(
return w, c.RequestJSON( return w, c.RequestJSON(
&w, "PATCH", &w, "PATCH",
EndpointGuilds+guildID.String()+"/widget", EndpointGuilds+guildID.String()+"/widget",
httputil.WithJSONBody(data), httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
) )
} }
@ -526,7 +540,9 @@ func (c *Client) GuildWidgetImageURL(guildID discord.GuildID, img GuildWidgetIma
// GuildWidgetImage returns a PNG image widget for the guild. Requires no permissions // GuildWidgetImage returns a PNG image widget for the guild. Requires no permissions
// or authentication. // or authentication.
func (c *Client) GuildWidgetImage(guildID discord.GuildID, img GuildWidgetImageStyle) (io.ReadCloser, error) { func (c *Client) GuildWidgetImage(
guildID discord.GuildID, img GuildWidgetImageStyle) (io.ReadCloser, error) {
r, err := c.Request("GET", c.GuildWidgetImageURL(guildID, img)) r, err := c.Request("GET", c.GuildWidgetImageURL(guildID, img))
if err != nil { if err != nil {
return nil, err return nil, err

View file

@ -263,7 +263,7 @@ func (c *Client) EditInteractionFollowup(
EndpointWebhooks+appID.String()+"/"+token+"/messages/"+messageID.String()) EndpointWebhooks+appID.String()+"/"+token+"/messages/"+messageID.String())
} }
// DeleteInteractionFollowup deletes a followup message for an interaction // DeleteInteractionFollowup deletes a followup message for an interaction.
func (c *Client) DeleteInteractionFollowup( func (c *Client) DeleteInteractionFollowup(
appID discord.AppID, messageID discord.MessageID, token string) error { appID discord.AppID, messageID discord.MessageID, token string) error {

View file

@ -19,7 +19,8 @@ func (c *Client) Invite(code string) (*discord.Invite, error) {
) )
} }
// Invite returns an invite object for the given code and fills ApproxMembers. // InviteWithCounts returns an invite object for the given code and fills
// ApproxMembers.
func (c *Client) InviteWithCounts(code string) (*discord.Invite, error) { func (c *Client) InviteWithCounts(code string) (*discord.Invite, error) {
var params struct { var params struct {
WithCounts bool `schema:"with_counts,omitempty"` WithCounts bool `schema:"with_counts,omitempty"`
@ -75,6 +76,8 @@ type CreateInviteData struct {
// //
// Default: false // Default: false
Unique bool `json:"unique,omitempty"` Unique bool `json:"unique,omitempty"`
AuditLogReason `json:"-"`
} }
// CreateInvite creates a new invite object for the channel. Only usable for // CreateInvite creates a new invite object for the channel. Only usable for
@ -83,11 +86,12 @@ type CreateInviteData struct {
// Requires the CREATE_INSTANT_INVITE permission. // Requires the CREATE_INSTANT_INVITE permission.
func (c *Client) CreateInvite( func (c *Client) CreateInvite(
channelID discord.ChannelID, data CreateInviteData) (*discord.Invite, error) { channelID discord.ChannelID, data CreateInviteData) (*discord.Invite, error) {
var inv *discord.Invite var inv *discord.Invite
return inv, c.RequestJSON( return inv, c.RequestJSON(
&inv, "POST", &inv, "POST",
EndpointChannels+channelID.String()+"/invites", EndpointChannels+channelID.String()+"/invites",
httputil.WithJSONBody(data), httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
) )
} }
@ -110,8 +114,13 @@ func (c *Client) JoinInvite(code string) (*JoinedInvite, error) {
// //
// Requires the MANAGE_CHANNELS permission on the channel this invite belongs // Requires the MANAGE_CHANNELS permission on the channel this invite belongs
// to, or MANAGE_GUILD to remove any invite across the guild. // 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) { // Fires an Invite Delete Gateway event.
func (c *Client) DeleteInvite(code string, reason AuditLogReason) (*discord.Invite, error) {
var inv *discord.Invite var inv *discord.Invite
return inv, c.RequestJSON(&inv, "DELETE", EndpointInvites+code) return inv, c.RequestJSON(
&inv,
"DELETE", EndpointInvites+code,
httputil.WithHeaders(reason.Header()),
)
} }

View file

@ -134,6 +134,7 @@ type AddMemberData struct {
// guild with CREATE_INSTANT_INVITE permission. // guild with CREATE_INSTANT_INVITE permission.
func (c *Client) AddMember( func (c *Client) AddMember(
guildID discord.GuildID, userID discord.UserID, data AddMemberData) (*discord.Member, error) { guildID discord.GuildID, userID discord.UserID, data AddMemberData) (*discord.Member, error) {
var mem *discord.Member var mem *discord.Member
return mem, c.RequestJSON( return mem, c.RequestJSON(
&mem, "PUT", &mem, "PUT",
@ -166,18 +167,21 @@ type ModifyMemberData struct {
// //
// Requires MOVE_MEMBER // Requires MOVE_MEMBER
VoiceChannel discord.ChannelID `json:"channel_id,omitempty"` VoiceChannel discord.ChannelID `json:"channel_id,omitempty"`
AuditLogReason `json:"-"`
} }
// ModifyMember modifies attributes of a guild member. If the channel_id is set // ModifyMember modifies attributes of a guild member. If the channel_id is set
// to null, this will force the target user to be disconnected from voice. // to null, this will force the target user to be disconnected from voice.
// //
// Fires a Guild Member Update Gateway event. // Fires a Guild Member Update Gateway event.
func (c *Client) ModifyMember(guildID discord.GuildID, userID discord.UserID, data ModifyMemberData) error { func (c *Client) ModifyMember(
guildID discord.GuildID, userID discord.UserID, data ModifyMemberData) error {
return c.FastRequest( return c.FastRequest(
"PATCH", "PATCH",
EndpointGuilds+guildID.String()+"/members/"+userID.String(), EndpointGuilds+guildID.String()+"/members/"+userID.String(),
httputil.WithJSONBody(data), httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
) )
} }
@ -223,6 +227,8 @@ type PruneData struct {
ReturnCount bool `schema:"compute_prune_count"` ReturnCount bool `schema:"compute_prune_count"`
// IncludedRoles are the role(s) to include. // IncludedRoles are the role(s) to include.
IncludedRoles []discord.RoleID `schema:"include_roles,omitempty"` IncludedRoles []discord.RoleID `schema:"include_roles,omitempty"`
AuditLogReason `schema:"-"`
} }
// Prune begins a prune. Days must be 1 or more, default 7. // Prune begins a prune. Days must be 1 or more, default 7.
@ -233,6 +239,7 @@ type PruneData struct {
// will be included in the prune and users with additional roles will not. // will be included in the prune and users with additional roles will not.
// //
// Requires KICK_MEMBERS. // Requires KICK_MEMBERS.
//
// Fires multiple Guild Member Remove Gateway events. // Fires multiple Guild Member Remove Gateway events.
func (c *Client) Prune(guildID discord.GuildID, data PruneData) (uint, error) { func (c *Client) Prune(guildID discord.GuildID, data PruneData) (uint, error) {
if data.Days == 0 { if data.Days == 0 {
@ -246,36 +253,28 @@ func (c *Client) Prune(guildID discord.GuildID, data PruneData) (uint, error) {
return resp.Pruned, c.RequestJSON( return resp.Pruned, c.RequestJSON(
&resp, "POST", &resp, "POST",
EndpointGuilds+guildID.String()+"/prune", EndpointGuilds+guildID.String()+"/prune",
httputil.WithSchema(c, data), httputil.WithSchema(c, data), httputil.WithHeaders(data.Header()),
) )
} }
// Kick removes a member from a guild. // Kick removes a member from a guild.
// //
// Requires KICK_MEMBERS permission. // Requires KICK_MEMBERS permission.
//
// Fires a Guild Member Remove Gateway event. // Fires a Guild Member Remove Gateway event.
func (c *Client) Kick(guildID discord.GuildID, userID discord.UserID) error { func (c *Client) Kick(guildID discord.GuildID, userID discord.UserID) error {
return c.KickWithReason(guildID, userID, "") return c.KickWithReason(guildID, userID, "")
} }
// KickWithReason removes a member from a guild. // KickWithReason is the same as Kick, but adds the given reason to the audit
// The reason, if non-empty, will be displayed in the audit log of the guild. // log.
//
// Requires KICK_MEMBERS permission.
// Fires a Guild Member Remove Gateway event.
func (c *Client) KickWithReason( func (c *Client) KickWithReason(
guildID discord.GuildID, userID discord.UserID, reason string) error { guildID discord.GuildID, userID discord.UserID, reason AuditLogReason) error {
var data struct {
Reason string `schema:"reason,omitempty"`
}
data.Reason = reason
return c.FastRequest( return c.FastRequest(
"DELETE", "DELETE",
EndpointGuilds+guildID.String()+"/members/"+userID.String(), EndpointGuilds+guildID.String()+"/members/"+userID.String(),
httputil.WithSchema(c, data), httputil.WithHeaders(reason.Header()),
) )
} }
@ -305,26 +304,34 @@ func (c *Client) GetBan(guildID discord.GuildID, userID discord.UserID) (*discor
type BanData struct { type BanData struct {
// DeleteDays is the number of days to delete messages for (0-7). // DeleteDays is the number of days to delete messages for (0-7).
DeleteDays option.Uint `schema:"delete_message_days,omitempty"` DeleteDays option.Uint `schema:"delete_message_days,omitempty"`
// Reason is the reason for the ban.
Reason option.String `schema:"reason,omitempty"` AuditLogReason `schema:"-"`
} }
// Ban creates a guild ban, and optionally delete previous messages sent by the // Ban creates a guild ban, and optionally delete previous messages sent by the
// banned user. // banned user.
// //
// Requires the BAN_MEMBERS permission. // Requires the BAN_MEMBERS permission.
//
// Fires a Guild Ban Add Gateway event.
func (c *Client) Ban(guildID discord.GuildID, userID discord.UserID, data BanData) error { func (c *Client) Ban(guildID discord.GuildID, userID discord.UserID, data BanData) error {
return c.FastRequest( return c.FastRequest(
"PUT", "PUT",
EndpointGuilds+guildID.String()+"/bans/"+userID.String(), EndpointGuilds+guildID.String()+"/bans/"+userID.String(),
httputil.WithSchema(c, data), httputil.WithSchema(c, data), httputil.WithHeaders(data.Header()),
) )
} }
// Unban removes the ban for a user. // Unban removes the ban for a user.
// //
// Requires the BAN_MEMBERS permissions. // Requires the BAN_MEMBERS permissions.
//
// Fires a Guild Ban Remove Gateway event. // Fires a Guild Ban Remove Gateway event.
func (c *Client) Unban(guildID discord.GuildID, userID discord.UserID) error { func (c *Client) Unban(
return c.FastRequest("DELETE", EndpointGuilds+guildID.String()+"/bans/"+userID.String()) guildID discord.GuildID, userID discord.UserID, reason AuditLogReason) error {
return c.FastRequest(
"DELETE", EndpointGuilds+guildID.String()+"/bans/"+userID.String(),
httputil.WithHeaders(reason.Header()),
)
} }

View file

@ -155,7 +155,8 @@ func (c *Client) MessagesAfter(
} }
func (c *Client) messagesRange( func (c *Client) messagesRange(
channelID discord.ChannelID, before, after, around discord.MessageID, limit uint) ([]discord.Message, error) { channelID discord.ChannelID,
before, after, around discord.MessageID, limit uint) ([]discord.Message, error) {
switch { switch {
case limit == 0: case limit == 0:
@ -189,7 +190,9 @@ func (c *Client) messagesRange(
// //
// If operating on a guild channel, this endpoint requires the // If operating on a guild channel, this endpoint requires the
// READ_MESSAGE_HISTORY permission to be present on the current user. // READ_MESSAGE_HISTORY permission to be present on the current user.
func (c *Client) Message(channelID discord.ChannelID, messageID discord.MessageID) (*discord.Message, error) { func (c *Client) Message(
channelID discord.ChannelID, messageID discord.MessageID) (*discord.Message, error) {
var msg *discord.Message var msg *discord.Message
return msg, c.RequestJSON(&msg, "GET", return msg, c.RequestJSON(&msg, "GET",
EndpointChannels+channelID.String()+"/messages/"+messageID.String()) EndpointChannels+channelID.String()+"/messages/"+messageID.String())
@ -203,8 +206,7 @@ func (c *Client) Message(channelID discord.ChannelID, messageID discord.MessageI
// Fires a Message Create Gateway event. // Fires a Message Create Gateway event.
func (c *Client) SendTextReply( func (c *Client) SendTextReply(
channelID discord.ChannelID, channelID discord.ChannelID,
content string, content string, referenceID discord.MessageID) (*discord.Message, error) {
referenceID discord.MessageID) (*discord.Message, error) {
return c.SendMessageComplex(channelID, SendMessageData{ return c.SendMessageComplex(channelID, SendMessageData{
Content: content, Content: content,
@ -234,8 +236,7 @@ func (c *Client) SendEmbeds(
// Fires a Message Create Gateway event. // Fires a Message Create Gateway event.
func (c *Client) SendEmbedReply( func (c *Client) SendEmbedReply(
channelID discord.ChannelID, channelID discord.ChannelID,
e discord.Embed, e discord.Embed, referenceID discord.MessageID) (*discord.Message, error) {
referenceID discord.MessageID) (*discord.Message, error) {
return c.SendMessageComplex(channelID, SendMessageData{ return c.SendMessageComplex(channelID, SendMessageData{
Embeds: []discord.Embed{e}, Embeds: []discord.Embed{e},
@ -250,7 +251,9 @@ func (c *Client) SendEmbedReply(
// //
// Fires a Message Create Gateway event. // Fires a Message Create Gateway event.
func (c *Client) SendMessage( func (c *Client) SendMessage(
channelID discord.ChannelID, content string, embeds ...discord.Embed) (*discord.Message, error) { channelID discord.ChannelID,
content string, embeds ...discord.Embed) (*discord.Message, error) {
data := SendMessageData{ data := SendMessageData{
Content: content, Content: content,
Embeds: embeds, Embeds: embeds,
@ -265,10 +268,9 @@ func (c *Client) SendMessage(
// //
// Fires a Message Create Gateway event. // Fires a Message Create Gateway event.
func (c *Client) SendMessageReply( func (c *Client) SendMessageReply(
channelID discord.ChannelID, channelID discord.ChannelID, content string,
content string, embed *discord.Embed, referenceID discord.MessageID) (*discord.Message, error) {
embed *discord.Embed,
referenceID discord.MessageID) (*discord.Message, error) {
data := SendMessageData{ data := SendMessageData{
Content: content, Content: content,
Reference: &discord.MessageReference{MessageID: referenceID}, Reference: &discord.MessageReference{MessageID: referenceID},
@ -312,7 +314,8 @@ func (data EditMessageData) WriteMultipart(body *multipart.Writer) error {
// EditText edits the contents of a previously sent message. For more // EditText edits the contents of a previously sent message. For more
// documentation, refer to EditMessageComplex. // documentation, refer to EditMessageComplex.
func (c *Client) EditText( func (c *Client) EditText(
channelID discord.ChannelID, messageID discord.MessageID, content string) (*discord.Message, error) { channelID discord.ChannelID,
messageID discord.MessageID, content string) (*discord.Message, error) {
return c.EditMessageComplex(channelID, messageID, EditMessageData{ return c.EditMessageComplex(channelID, messageID, EditMessageData{
Content: option.NewNullableString(content), Content: option.NewNullableString(content),
@ -322,7 +325,8 @@ func (c *Client) EditText(
// EditEmbeds edits the embed of a previously sent message. For more // EditEmbeds edits the embed of a previously sent message. For more
// documentation, refer to EditMessageComplex. // documentation, refer to EditMessageComplex.
func (c *Client) EditEmbeds( func (c *Client) EditEmbeds(
channelID discord.ChannelID, messageID discord.MessageID, embeds ...discord.Embed) (*discord.Message, error) { channelID discord.ChannelID,
messageID discord.MessageID, embeds ...discord.Embed) (*discord.Message, error) {
return c.EditMessageComplex(channelID, messageID, EditMessageData{ return c.EditMessageComplex(channelID, messageID, EditMessageData{
Embeds: &embeds, Embeds: &embeds,
@ -360,7 +364,9 @@ func (c *Client) EditMessage(
// //
// Fires a Message Update Gateway event. // Fires a Message Update Gateway event.
func (c *Client) EditMessageComplex( func (c *Client) EditMessageComplex(
channelID discord.ChannelID, messageID discord.MessageID, data EditMessageData) (*discord.Message, error) { channelID discord.ChannelID,
messageID discord.MessageID, data EditMessageData) (*discord.Message, error) {
if data.AllowedMentions != nil { if data.AllowedMentions != nil {
if err := data.AllowedMentions.Verify(); err != nil { if err := data.AllowedMentions.Verify(); err != nil {
return nil, errors.Wrap(err, "allowedMentions error") return nil, errors.Wrap(err, "allowedMentions error")
@ -387,7 +393,9 @@ func (c *Client) EditMessageComplex(
// CrosspostMessage crossposts a message in a news channel to following channels. // CrosspostMessage crossposts a message in a news channel to following channels.
// This endpoint requires the SEND_MESSAGES permission if the current user sent the message, // This endpoint requires the SEND_MESSAGES permission if the current user sent the message,
// or additionally the MANAGE_MESSAGES permission for all other messages. // or additionally the MANAGE_MESSAGES permission for all other messages.
func (c *Client) CrosspostMessage(channelID discord.ChannelID, messageID discord.MessageID) (*discord.Message, error) { func (c *Client) CrosspostMessage(
channelID discord.ChannelID, messageID discord.MessageID) (*discord.Message, error) {
var msg *discord.Message var msg *discord.Message
return msg, c.RequestJSON( return msg, c.RequestJSON(
@ -400,9 +408,12 @@ func (c *Client) CrosspostMessage(channelID discord.ChannelID, messageID discord
// DeleteMessage delete a message. If operating on a guild channel and trying // DeleteMessage delete a message. If operating on a guild channel and trying
// to delete a message that was not sent by the current user, this endpoint // to delete a message that was not sent by the current user, this endpoint
// requires the MANAGE_MESSAGES permission. // requires the MANAGE_MESSAGES permission.
func (c *Client) DeleteMessage(channelID discord.ChannelID, messageID discord.MessageID) error { func (c *Client) DeleteMessage(
return c.FastRequest("DELETE", EndpointChannels+channelID.String()+ channelID discord.ChannelID, messageID discord.MessageID, reason AuditLogReason) error {
"/messages/"+messageID.String())
return c.FastRequest(
"DELETE", EndpointChannels+channelID.String()+"/messages/"+messageID.String(),
httputil.WithHeaders(reason.Header()))
} }
// DeleteMessages deletes multiple messages in a single request. This endpoint // DeleteMessages deletes multiple messages in a single request. This endpoint
@ -418,21 +429,23 @@ func (c *Client) DeleteMessage(channelID discord.ChannelID, messageID discord.Me
// requests. // requests.
// //
// Fires a Message Delete Bulk Gateway event. // Fires a Message Delete Bulk Gateway event.
func (c *Client) DeleteMessages(channelID discord.ChannelID, messageIDs []discord.MessageID) error { func (c *Client) DeleteMessages(
channelID discord.ChannelID, messageIDs []discord.MessageID, reason AuditLogReason) error {
switch { switch {
case len(messageIDs) == 0: case len(messageIDs) == 0:
return nil return nil
case len(messageIDs) == 1: case len(messageIDs) == 1:
return c.DeleteMessage(channelID, messageIDs[0]) return c.DeleteMessage(channelID, messageIDs[0], reason)
case len(messageIDs) <= maxMessageDeleteLimit: // Fast path case len(messageIDs) <= maxMessageDeleteLimit: // Fast path
return c.deleteMessages(channelID, messageIDs) return c.deleteMessages(channelID, messageIDs, reason)
} }
// If the number of messages to be deleted exceeds the amount discord is willing // If the number of messages to be deleted exceeds the amount discord is willing
// to accept at one time then batches of messages will be deleted // to accept at one time then batches of messages will be deleted
for start := 0; start < len(messageIDs); start += maxMessageDeleteLimit { for start := 0; start < len(messageIDs); start += maxMessageDeleteLimit {
end := intmath.Min(len(messageIDs), start+maxMessageDeleteLimit) end := intmath.Min(len(messageIDs), start+maxMessageDeleteLimit)
err := c.deleteMessages(channelID, messageIDs[start:end]) err := c.deleteMessages(channelID, messageIDs[start:end], reason)
if err != nil { if err != nil {
return err return err
} }
@ -441,7 +454,9 @@ func (c *Client) DeleteMessages(channelID discord.ChannelID, messageIDs []discor
return nil return nil
} }
func (c *Client) deleteMessages(channelID discord.ChannelID, messageIDs []discord.MessageID) error { func (c *Client) deleteMessages(
channelID discord.ChannelID, messageIDs []discord.MessageID, reason AuditLogReason) error {
var param struct { var param struct {
Messages []discord.MessageID `json:"messages"` Messages []discord.MessageID `json:"messages"`
} }
@ -451,6 +466,6 @@ func (c *Client) deleteMessages(channelID discord.ChannelID, messageIDs []discor
return c.FastRequest( return c.FastRequest(
"POST", "POST",
EndpointChannels+channelID.String()+"/messages/bulk-delete", EndpointChannels+channelID.String()+"/messages/bulk-delete",
httputil.WithJSONBody(param), httputil.WithJSONBody(param), httputil.WithHeaders(reason.Header()),
) )
} }

View file

@ -15,8 +15,7 @@ const MaxMessageReactionFetchLimit = 100
// using this emoji, this endpoint requires the 'ADD_REACTIONS' permission to // using this emoji, this endpoint requires the 'ADD_REACTIONS' permission to
// be present on the current user. // be present on the current user.
func (c *Client) React( func (c *Client) React(
channelID discord.ChannelID, channelID discord.ChannelID, messageID discord.MessageID, emoji discord.APIEmoji) error {
messageID discord.MessageID, emoji discord.APIEmoji) error {
return c.FastRequest( return c.FastRequest(
"PUT", "PUT",
@ -28,8 +27,7 @@ func (c *Client) React(
// Unreact removes a reaction the current user has made for the message. // Unreact removes a reaction the current user has made for the message.
func (c *Client) Unreact( func (c *Client) Unreact(
channelID discord.ChannelID, channelID discord.ChannelID, messageID discord.MessageID, emoji discord.APIEmoji) error {
messageID discord.MessageID, emoji discord.APIEmoji) error {
return c.DeleteUserReaction(channelID, messageID, 0, emoji) return c.DeleteUserReaction(channelID, messageID, 0, emoji)
} }
@ -45,8 +43,7 @@ func (c *Client) Unreact(
// When fetching the users, those with the smallest ID will be fetched first. // When fetching the users, those with the smallest ID will be fetched first.
func (c *Client) Reactions( func (c *Client) Reactions(
channelID discord.ChannelID, channelID discord.ChannelID,
messageID discord.MessageID, messageID discord.MessageID, emoji discord.APIEmoji, limit uint) ([]discord.User, error) {
emoji discord.APIEmoji, limit uint) ([]discord.User, error) {
return c.ReactionsAfter(channelID, messageID, 0, emoji, limit) return c.ReactionsAfter(channelID, messageID, 0, emoji, limit)
} }
@ -60,10 +57,8 @@ func (c *Client) Reactions(
// maximum a total of limit/100 rounded up requests will be made, although they // maximum a total of limit/100 rounded up requests will be made, although they
// may be less, if no more guilds are available. // may be less, if no more guilds are available.
func (c *Client) ReactionsBefore( func (c *Client) ReactionsBefore(
channelID discord.ChannelID, channelID discord.ChannelID, messageID discord.MessageID,
messageID discord.MessageID, before discord.UserID, emoji discord.APIEmoji, limit uint) ([]discord.User, error) {
before discord.UserID,
emoji discord.APIEmoji, limit uint) ([]discord.User, error) {
users := make([]discord.User, 0, limit) users := make([]discord.User, 0, limit)
@ -108,10 +103,8 @@ func (c *Client) ReactionsBefore(
// maximum a total of limit/100 rounded up requests will be made, although they // maximum a total of limit/100 rounded up requests will be made, although they
// may be less, if no more guilds are available. // may be less, if no more guilds are available.
func (c *Client) ReactionsAfter( func (c *Client) ReactionsAfter(
channelID discord.ChannelID, channelID discord.ChannelID, messageID discord.MessageID,
messageID discord.MessageID, after discord.UserID, emoji discord.APIEmoji, limit uint) ([]discord.User, error) {
after discord.UserID,
emoji discord.APIEmoji, limit uint) ([]discord.User, error) {
users := make([]discord.User, 0, limit) users := make([]discord.User, 0, limit)
@ -150,10 +143,8 @@ func (c *Client) ReactionsAfter(
// reactionsRange get users before and after IDs. Before, after, and limit are // reactionsRange get users before and after IDs. Before, after, and limit are
// optional. A maximum limit of only 100 reactions could be returned. // optional. A maximum limit of only 100 reactions could be returned.
func (c *Client) reactionsRange( func (c *Client) reactionsRange(
channelID discord.ChannelID, channelID discord.ChannelID, messageID discord.MessageID,
messageID discord.MessageID, before, after discord.UserID, emoji discord.APIEmoji, limit uint) ([]discord.User, error) {
before, after discord.UserID,
emoji discord.APIEmoji, limit uint) ([]discord.User, error) {
switch { switch {
case limit == 0: case limit == 0:
@ -182,15 +173,13 @@ func (c *Client) reactionsRange(
) )
} }
// DeleteReaction deletes another user's reaction. // DeleteUserReaction deletes another user's reaction.
// //
// This endpoint requires the MANAGE_MESSAGES permission to be present on the // This endpoint requires the MANAGE_MESSAGES permission to be present on the
// current user. // current user.
func (c *Client) DeleteUserReaction( func (c *Client) DeleteUserReaction(
channelID discord.ChannelID, channelID discord.ChannelID,
messageID discord.MessageID, messageID discord.MessageID, userID discord.UserID, emoji discord.APIEmoji) error {
userID discord.UserID,
emoji discord.APIEmoji) error {
var user = "@me" var user = "@me"
if userID > 0 { if userID > 0 {
@ -209,6 +198,7 @@ func (c *Client) DeleteUserReaction(
// //
// This endpoint requires the MANAGE_MESSAGES permission to be present on the // This endpoint requires the MANAGE_MESSAGES permission to be present on the
// current user. // current user.
//
// Fires a Message Reaction Remove Emoji Gateway event. // Fires a Message Reaction Remove Emoji Gateway event.
func (c *Client) DeleteReactions( func (c *Client) DeleteReactions(
channelID discord.ChannelID, messageID discord.MessageID, emoji discord.APIEmoji) error { channelID discord.ChannelID, messageID discord.MessageID, emoji discord.APIEmoji) error {
@ -225,6 +215,7 @@ func (c *Client) DeleteReactions(
// //
// This endpoint requires the MANAGE_MESSAGES permission to be present on the // This endpoint requires the MANAGE_MESSAGES permission to be present on the
// current user. // current user.
//
// Fires a Message Reaction Remove All Gateway event. // Fires a Message Reaction Remove All Gateway event.
func (c *Client) DeleteAllReactions( func (c *Client) DeleteAllReactions(
channelID discord.ChannelID, messageID discord.MessageID) error { channelID discord.ChannelID, messageID discord.MessageID) error {

View file

@ -6,24 +6,37 @@ import (
"github.com/diamondburned/arikawa/v3/utils/json/option" "github.com/diamondburned/arikawa/v3/utils/json/option"
) )
// Adds a role to a guild member. type AddRoleData struct {
AuditLogReason
}
// AddRole adds a role to a guild member.
// //
// Requires the MANAGE_ROLES permission. // Requires the MANAGE_ROLES permission.
func (c *Client) AddRole(guildID discord.GuildID, userID discord.UserID, roleID discord.RoleID) error { func (c *Client) AddRole(
guildID discord.GuildID,
userID discord.UserID, roleID discord.RoleID, data AddRoleData) error {
return c.FastRequest( return c.FastRequest(
"PUT", "PUT",
EndpointGuilds+guildID.String()+"/members/"+userID.String()+"/roles/"+roleID.String(), EndpointGuilds+guildID.String()+"/members/"+userID.String()+"/roles/"+roleID.String(),
httputil.WithHeaders(data.Header()),
) )
} }
// RemoveRole removes a role from a guild member. // RemoveRole removes a role from a guild member.
// //
// Requires the MANAGE_ROLES permission. // Requires the MANAGE_ROLES permission.
//
// Fires a Guild Member Update Gateway event. // Fires a Guild Member Update Gateway event.
func (c *Client) RemoveRole(guildID discord.GuildID, userID discord.UserID, roleID discord.RoleID) error { func (c *Client) RemoveRole(
guildID discord.GuildID,
userID discord.UserID, roleID discord.RoleID, reason AuditLogReason) error {
return c.FastRequest( return c.FastRequest(
"DELETE", "DELETE",
EndpointGuilds+guildID.String()+"/members/"+userID.String()+"/roles/"+roleID.String(), EndpointGuilds+guildID.String()+"/members/"+userID.String()+"/roles/"+roleID.String(),
httputil.WithHeaders(reason.Header()),
) )
} }
@ -56,40 +69,51 @@ type CreateRoleData struct {
// //
// Default: false // Default: false
Mentionable bool `json:"mentionable,omitempty"` Mentionable bool `json:"mentionable,omitempty"`
AddRoleData `json:"-"`
} }
// CreateRole creates a new role for the guild. // CreateRole creates a new role for the guild.
// //
// Requires the MANAGE_ROLES permission. // Requires the MANAGE_ROLES permission.
//
// Fires a Guild Role Create Gateway event. // Fires a Guild Role Create Gateway event.
func (c *Client) CreateRole(guildID discord.GuildID, data CreateRoleData) (*discord.Role, error) { func (c *Client) CreateRole(guildID discord.GuildID, data CreateRoleData) (*discord.Role, error) {
var role *discord.Role var role *discord.Role
return role, c.RequestJSON( return role, c.RequestJSON(
&role, "POST", &role, "POST",
EndpointGuilds+guildID.String()+"/roles", EndpointGuilds+guildID.String()+"/roles",
httputil.WithJSONBody(data), httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
) )
} }
// https://discord.com/developers/docs/resources/guild#modify-guild-role-positions-json-params type (
type MoveRoleData struct { MoveRolesData struct {
// ID is the id of the role. Roles []MoveRoleData
ID discord.RoleID `json:"id"`
// Position is the sorting position of the role.
Position option.NullableInt `json:"position,omitempty"`
}
// MoveRole modifies the positions of a set of role objects for the guild. AuditLogReason
}
// https://discord.com/developers/docs/resources/guild#modify-guild-role-positions-json-params
MoveRoleData struct {
// ID is the id of the role.
ID discord.RoleID `json:"id"`
// Position is the sorting position of the role.
Position option.NullableInt `json:"position,omitempty"`
}
)
// MoveRoles modifies the positions of a set of role objects for the guild.
// //
// Requires the MANAGE_ROLES permission. // Requires the MANAGE_ROLES permission.
//
// Fires multiple Guild Role Update Gateway events. // Fires multiple Guild Role Update Gateway events.
func (c *Client) MoveRole(guildID discord.GuildID, data []MoveRoleData) ([]discord.Role, error) { func (c *Client) MoveRoles(guildID discord.GuildID, data MoveRolesData) ([]discord.Role, error) {
var roles []discord.Role var roles []discord.Role
return roles, c.RequestJSON( return roles, c.RequestJSON(
&roles, "PATCH", &roles, "PATCH",
EndpointGuilds+guildID.String()+"/roles", EndpointGuilds+guildID.String()+"/roles",
httputil.WithJSONBody(data), httputil.WithJSONBody(data.Roles), httputil.WithHeaders(data.Header()),
) )
} }
@ -106,29 +130,33 @@ type ModifyRoleData struct {
Hoist option.NullableBool `json:"hoist,omitempty"` Hoist option.NullableBool `json:"hoist,omitempty"`
// Mentionable specifies whether the role should be mentionable. // Mentionable specifies whether the role should be mentionable.
Mentionable option.NullableBool `json:"mentionable,omitempty"` Mentionable option.NullableBool `json:"mentionable,omitempty"`
AddRoleData `json:"-"`
} }
// ModifyRole modifies a guild role. // ModifyRole modifies a guild role.
// //
// Requires the MANAGE_ROLES permission. // Requires the MANAGE_ROLES permission.
func (c *Client) ModifyRole( func (c *Client) ModifyRole(
guildID discord.GuildID, roleID discord.RoleID, guildID discord.GuildID, roleID discord.RoleID, data ModifyRoleData) (*discord.Role, error) {
data ModifyRoleData) (*discord.Role, error) {
var role *discord.Role var role *discord.Role
return role, c.RequestJSON( return role, c.RequestJSON(
&role, "PATCH", &role, "PATCH",
EndpointGuilds+guildID.String()+"/roles/"+roleID.String(), EndpointGuilds+guildID.String()+"/roles/"+roleID.String(),
httputil.WithJSONBody(data), httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
) )
} }
// DeleteRole deletes a guild role. // DeleteRole deletes a guild role.
// //
// Requires the MANAGE_ROLES permission. // Requires the MANAGE_ROLES permission.
func (c *Client) DeleteRole(guildID discord.GuildID, roleID discord.RoleID) error { func (c *Client) DeleteRole(
guildID discord.GuildID, roleID discord.RoleID, reason AuditLogReason) error {
return c.FastRequest( return c.FastRequest(
"DELETE", "DELETE",
EndpointGuilds+guildID.String()+"/roles/"+roleID.String(), EndpointGuilds+guildID.String()+"/roles/"+roleID.String(),
httputil.WithHeaders(reason.Header()),
) )
} }

View file

@ -17,6 +17,8 @@ type CreateStageInstanceData struct {
// //
// Defaults to discord.GuildOnlyStage. // Defaults to discord.GuildOnlyStage.
PrivacyLevel discord.PrivacyLevel `json:"privacy_level,omitempty"` PrivacyLevel discord.PrivacyLevel `json:"privacy_level,omitempty"`
AuditLogReason `json:"-"`
} }
// CreateStageInstance creates a new Stage instance associated to a Stage // CreateStageInstance creates a new Stage instance associated to a Stage
@ -30,7 +32,7 @@ func (c *Client) CreateStageInstance(
return s, c.RequestJSON( return s, c.RequestJSON(
&s, "POST", &s, "POST",
EndpointStageInstances, EndpointStageInstances,
httputil.WithJSONBody(data), httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
) )
} }
@ -40,6 +42,8 @@ type UpdateStageInstanceData struct {
Topic string `json:"topic,omitempty"` Topic string `json:"topic,omitempty"`
// PrivacyLevel is the privacy level of the Stage instance. // PrivacyLevel is the privacy level of the Stage instance.
PrivacyLevel discord.PrivacyLevel `json:"privacy_level,omitempty"` PrivacyLevel discord.PrivacyLevel `json:"privacy_level,omitempty"`
AuditLogReason `json:"-"`
} }
// UpdateStageInstance updates fields of an existing Stage instance. // UpdateStageInstance updates fields of an existing Stage instance.
@ -51,10 +55,13 @@ func (c *Client) UpdateStageInstance(
return c.FastRequest( return c.FastRequest(
"PATCH", "PATCH",
EndpointStageInstances+channelID.String(), EndpointStageInstances+channelID.String(),
httputil.WithJSONBody(data), httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
) )
} }
func (c *Client) DeleteStageInstance(channelID discord.ChannelID) error { func (c *Client) DeleteStageInstance(channelID discord.ChannelID, reason AuditLogReason) error {
return c.FastRequest("DELETE", EndpointStageInstances+channelID.String()) return c.FastRequest(
"DELETE", EndpointStageInstances+channelID.String(),
httputil.WithHeaders(reason.Header()),
)
} }

View file

@ -32,12 +32,18 @@ type ModifySelfData struct {
Username option.String `json:"username,omitempty"` Username option.String `json:"username,omitempty"`
// Avatar modifies the user's avatar. // Avatar modifies the user's avatar.
Avatar *Image `json:"image,omitempty"` Avatar *Image `json:"image,omitempty"`
AuditLogReason `json:"-"`
} }
// ModifyMe modifies the requester's user account settings. // ModifyMe modifies the requester's user account settings.
func (c *Client) ModifyMe(data ModifySelfData) (*discord.User, error) { func (c *Client) ModifyMe(data ModifySelfData) (*discord.User, error) {
var u *discord.User var u *discord.User
return u, c.RequestJSON(&u, "PATCH", EndpointMe, httputil.WithJSONBody(data)) return u, c.RequestJSON(
&u,
"PATCH", EndpointMe,
httputil.WithJSONBody(data), httputil.WithHeaders(data.Header()),
)
} }
// ChangeOwnNickname modifies the nickname of the current user in a guild. // ChangeOwnNickname modifies the nickname of the current user in a guild.