Discord: Fixed incorrect Audit Log structures
This commit is contained in:
parent
ca80a524b0
commit
52ca6638f5
10
api/guild.go
10
api/guild.go
|
@ -167,13 +167,13 @@ func (c *Client) VoiceRegionsGuild(guildID discord.Snowflake) ([]discord.VoiceRe
|
||||||
// optional.
|
// optional.
|
||||||
type AuditLogData struct {
|
type AuditLogData struct {
|
||||||
// Filter the log for actions made by a user
|
// Filter the log for actions made by a user
|
||||||
UserID discord.Snowflake `json:"user_id,omitempty"`
|
UserID discord.Snowflake `schema:"user_id,omitempty"`
|
||||||
// The type of audit log event
|
// The type of audit log event
|
||||||
ActionType discord.AuditLogEvent `json:"action_type,omitempty"`
|
ActionType discord.AuditLogEvent `schema:"action_type,omitempty"`
|
||||||
// Filter the log before a certain entry ID
|
// Filter the log before a certain entry ID
|
||||||
Before discord.Snowflake `json:"before,omitempty"`
|
Before discord.Snowflake `schema:"before,omitempty"`
|
||||||
// How many entries are returned (default 50, minimum 1, maximum 100)
|
// How many entries are returned (default 50, minimum 1, maximum 100)
|
||||||
Limit uint `json:"limit"`
|
Limit uint `schema:"limit"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuditLog returns an audit log object for the guild. Requires the
|
// AuditLog returns an audit log object for the guild. Requires the
|
||||||
|
@ -191,7 +191,7 @@ func (c *Client) AuditLog(guildID discord.Snowflake, data AuditLogData) (*discor
|
||||||
return audit, c.RequestJSON(
|
return audit, c.RequestJSON(
|
||||||
&audit, "GET",
|
&audit, "GET",
|
||||||
EndpointGuilds+guildID.String()+"/audit-logs",
|
EndpointGuilds+guildID.String()+"/audit-logs",
|
||||||
httputil.WithJSONBody(c, data),
|
httputil.WithSchema(c, data),
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,6 +1,9 @@
|
||||||
package discord
|
package discord
|
||||||
|
|
||||||
import "github.com/diamondburned/arikawa/utils/json"
|
import (
|
||||||
|
"github.com/diamondburned/arikawa/utils/json"
|
||||||
|
"github.com/pkg/errors"
|
||||||
|
)
|
||||||
|
|
||||||
type AuditLog struct {
|
type AuditLog struct {
|
||||||
// List of webhooks found in the audit log
|
// List of webhooks found in the audit log
|
||||||
|
@ -8,12 +11,13 @@ type AuditLog struct {
|
||||||
// List of users found in the audit log
|
// List of users found in the audit log
|
||||||
Users []User `json:"users"`
|
Users []User `json:"users"`
|
||||||
// List of audit log entries
|
// List of audit log entries
|
||||||
Entries []AuditLogEntries `json:"audit_log_entries"`
|
Entries []AuditLogEntry `json:"audit_log_entries"`
|
||||||
// List of partial integration objects, only ID, Name, Type, and Account
|
// List of partial integration objects, only ID, Name, Type, and Account
|
||||||
Integrations []Integration `json:"integrations"`
|
Integrations []Integration `json:"integrations"`
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuditLogEntries struct {
|
// AuditLogEntry is a single entry in the audit log.
|
||||||
|
type AuditLogEntry struct {
|
||||||
ID Snowflake `json:"id"`
|
ID Snowflake `json:"id"`
|
||||||
UserID Snowflake `json:"user_id"`
|
UserID Snowflake `json:"user_id"`
|
||||||
TargetID string `json:"target_id,omitempty"`
|
TargetID string `json:"target_id,omitempty"`
|
||||||
|
@ -25,6 +29,7 @@ type AuditLogEntries struct {
|
||||||
Reason string `json:"reason,omitempty"`
|
Reason string `json:"reason,omitempty"`
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// AuditLogEvent is the type of audit log action that occured.
|
||||||
type AuditLogEvent uint8
|
type AuditLogEvent uint8
|
||||||
|
|
||||||
const (
|
const (
|
||||||
|
@ -93,138 +98,168 @@ const (
|
||||||
RoleChannelOverwritten ChannelOverwritten = "role"
|
RoleChannelOverwritten ChannelOverwritten = "role"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
// AuditLogChange is a single key type to changed value audit log entry. The
|
||||||
|
// type can be found in the key's comment. Values can be nil.
|
||||||
|
//
|
||||||
|
// What
|
||||||
|
//
|
||||||
|
// I'm glad to see the same reaction that I had on you. In short, in this
|
||||||
|
// struct, the Key dictates what type NewValue and OldValue will have. They will
|
||||||
|
// always be the same type, but I will leave that as JSON for the user.
|
||||||
|
//
|
||||||
|
// Usage
|
||||||
|
//
|
||||||
|
// The usage of this is pretty simple, as AuditLogChange already has a
|
||||||
|
// convenient method to use. Here's an example on how to do "owner_id":
|
||||||
|
//
|
||||||
|
// if change.Key != discord.AuditGuildOwnerID {
|
||||||
|
// return errors.New("not owner ID")
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// // We know these are snowflakes because the comment said so for AuditGuildOwnerID.
|
||||||
|
// var oldOwnerID, newOwnerID discord.Snowflake
|
||||||
|
// if err := change.UnmarshalValues(&oldOwnerID, &newOwnerID); err != nil {
|
||||||
|
// return err
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// log.Println("Transferred ownership from user", oldOwnerID, "to", newOwnerID)
|
||||||
|
//
|
||||||
type AuditLogChange struct {
|
type AuditLogChange struct {
|
||||||
Key string `json:"key"`
|
Key string `json:"key"`
|
||||||
NewValue *AuditLogChangeKey `json:"new_value,omitempty"`
|
NewValue json.Raw `json:"new_value,omitempty"` // nullable
|
||||||
OldValue *AuditLogChangeKey `json:"old_value,omitempty"`
|
OldValue json.Raw `json:"old_value,omitempty"` // nullable
|
||||||
}
|
}
|
||||||
|
|
||||||
type AuditLogChangeKey struct {
|
func (a AuditLogChange) UnmarshalValues(old, new interface{}) error {
|
||||||
// The ID of the changed entity - sometimes used in conjunction with other
|
if err := a.NewValue.UnmarshalTo(new); err != nil {
|
||||||
// keys
|
return errors.Wrap(err, "Failed to unmarshal old value")
|
||||||
ID Snowflake `json:"snowflake"`
|
}
|
||||||
// Type of entity created, either a ChannelType (int) or string.
|
if err := a.OldValue.UnmarshalTo(old); err != nil {
|
||||||
Type json.AlwaysString `json:"type"`
|
return errors.Wrap(err, "Failed to unmarshal new value")
|
||||||
|
}
|
||||||
*AuditLogChangeGuild
|
return nil
|
||||||
*AuditLogChangeChannel
|
|
||||||
*AuditLogChangeRole
|
|
||||||
*AuditLogChangeInvite
|
|
||||||
*AuditLogChangeUser
|
|
||||||
*AuditLogChangeIntegration
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// AuditLogChangeGuild is the audit log key for Guild.
|
type AuditLogChangeKey string
|
||||||
type AuditLogChangeGuild struct {
|
|
||||||
// Name changed
|
|
||||||
Name string `json:"name,omitempty"`
|
|
||||||
// Icon changed
|
|
||||||
IconHash string `json:"icon_hash,omitempty"`
|
|
||||||
// Invite splash page artwork changed
|
|
||||||
SplashHash string `json:"splash_hash,omitempty"`
|
|
||||||
// Owner changed
|
|
||||||
OwnerID Snowflake `json:"owner_id,omitempty"`
|
|
||||||
// Region changed
|
|
||||||
Region string `json:"region,omitempty"`
|
|
||||||
// AFK channel changed
|
|
||||||
AfkChannelID Snowflake `json:"afk_channel_id,omitempty"`
|
|
||||||
// AFK timeout duration changed
|
|
||||||
AFKTimeout Seconds `json:"afk_timeout,omitempty"`
|
|
||||||
// Two-factor auth requirement changed
|
|
||||||
MFA MFALevel `json:"mfa_level,omitempty"`
|
|
||||||
// Required verification level changed
|
|
||||||
Verification Verification `json:"verification_level,omitempty"`
|
|
||||||
// Change in whose messages are scanned and deleted for explicit content in
|
|
||||||
// the server
|
|
||||||
ExplicitFilter ExplicitFilter `json:"explicit_content_filter,omitempty"`
|
|
||||||
// Default message notification level changed
|
|
||||||
Notification Notification `json:"default_message_notifications,omitempty"`
|
|
||||||
// Guild invite vanity url changed
|
|
||||||
VanityURLCode string `json:"vanity_url_code,omitempty"`
|
|
||||||
// New role added, only ID and Name are available
|
|
||||||
RoleAdd []Role `json:"$add,omitempty"`
|
|
||||||
// Role removed, partial similar to RoleAdd
|
|
||||||
RoleRemove []Role `json:"$remove,omitempty"`
|
|
||||||
// Change in number of days after which inactive and role-unassigned members
|
|
||||||
// are kicked
|
|
||||||
PruneDeleteDays int `json:"prune_delete_days,omitempty"`
|
|
||||||
// Server widget enabled/disable
|
|
||||||
WidgetEnabled bool `json:"widget_enabled,omitempty"`
|
|
||||||
// Channel id of the server widget changed
|
|
||||||
WidgetChannelID Snowflake `json:"widget_channel_id,omitempty"`
|
|
||||||
// ID of the system channel changed
|
|
||||||
SystemChannelID Snowflake `json:"system_channel_id,omitempty"`
|
|
||||||
}
|
|
||||||
|
|
||||||
// AuditLogChangeChannel is the audit log key for Channel.
|
const (
|
||||||
type AuditLogChangeChannel struct {
|
// Type string, name changed
|
||||||
// Text channel topic changed
|
AuditGuildName AuditLogChangeKey = "name"
|
||||||
Topic string `json:"topic,omitempty"`
|
// Type Hash, icon changed
|
||||||
// Voice channel bitrate changed
|
AuditGuildIconHash AuditLogChangeKey = "icon_hash"
|
||||||
Bitrate uint `json:"bitrate,omitempty"`
|
// Type Hash, invite splash page artwork changed
|
||||||
// Permissions on a channel changed
|
AuditGuildSplashHash AuditLogChangeKey = "splash_hash"
|
||||||
Permissions []Overwrite `json:"permission_overwrites,omitempty"`
|
// Type Snowflake, owner changed
|
||||||
// Channel NSFW restriction changed
|
AuditGuildOwnerID AuditLogChangeKey = "owner_id"
|
||||||
NSFW bool `json:"nsfw,omitempty"`
|
// Type string, region changed
|
||||||
// Application ID of the added or removed webhook or bot
|
AuditGuildRegion AuditLogChangeKey = "region"
|
||||||
ApplicationID Snowflake `json:"application_id,omitempty"`
|
// Type Snowflake, afk channel changed
|
||||||
// Amount of seconds a user has to wait before sending another message
|
AuditGuildAFKChannelID AuditLogChangeKey = "afk_channel_id"
|
||||||
// changed
|
// Type Seconds, afk timeout duration changed
|
||||||
UserRateLimit Seconds `json:"rate_limit_per_user,omitempty"`
|
AuditGuildAFKTimeout AuditLogChangeKey = "afk_timeout"
|
||||||
}
|
// Type int, two-factor auth requirement changed
|
||||||
|
AuditGuildMFA AuditLogChangeKey = "mfa_level"
|
||||||
|
// Type Verification, required verification level changed
|
||||||
|
AuditGuildVerification AuditLogChangeKey = "verification_level"
|
||||||
|
// Type ExplicitFilter, change in whose messages are scanned and deleted for
|
||||||
|
// explicit content in the server
|
||||||
|
AuditGuildExplicitFilter AuditLogChangeKey = "explicit_content_filter"
|
||||||
|
// Type Notification, default message notification level changed
|
||||||
|
AuditGuildNotification AuditLogChangeKey = "default_message_notifications"
|
||||||
|
// Type string, guild invite vanity URL changed
|
||||||
|
AuditGuildVanityURLCode AuditLogChangeKey = "vanity_url_code"
|
||||||
|
// Type []Role{ID, Name}, new role added
|
||||||
|
AuditGuildRoleAdd AuditLogChangeKey = "$add"
|
||||||
|
// Type []Role{ID, Name}, role removed
|
||||||
|
AuditGuildRoleRemove AuditLogChangeKey = "$remove"
|
||||||
|
// Type int, change in number of days after which inactive and
|
||||||
|
// role-unassigned members are kicked
|
||||||
|
AuditGuildPruneDeleteDays AuditLogChangeKey = "prune_delete_days"
|
||||||
|
// Type bool, server widget enabled/disable
|
||||||
|
AuditGuildWidgetEnabled AuditLogChangeKey = "widget_enabled"
|
||||||
|
// Type Snowflake, channel ID of the server widget changed
|
||||||
|
AuditGuildWidgetChannelID AuditLogChangeKey = "widget_channel_id"
|
||||||
|
// Type Snowflake, ID of the system channel changed
|
||||||
|
AuditGuildSystemChannelID AuditLogChangeKey = "system_channel_id"
|
||||||
|
)
|
||||||
|
|
||||||
// AuditLogChangeRole is the audit log key for Role.
|
const (
|
||||||
type AuditLogChangeRole struct {
|
// Type int, text or voice channel position changed
|
||||||
// Permissions for a role changed
|
AuditChannelPosition AuditLogChangeKey = "position"
|
||||||
Permissions Permissions `json:"permissions,omitempty"`
|
// Type string, text channel topic changed
|
||||||
// Role color changed
|
AuditChannelTopic AuditLogChangeKey = "topic"
|
||||||
Color Color `json:"color,omitempty"`
|
// Type uint, voice channel bitrate changed
|
||||||
// Role is now displayed/no longer displayed separate from online users
|
AuditChannelBitrate AuditLogChangeKey = "bitrate"
|
||||||
Hoist bool `json:"hoist,omitempty"`
|
// Type []Overwrite, permissions on a channel changed
|
||||||
// Role is now mentionable/unmentionable
|
AuditChannelPermissionOverwrites AuditLogChangeKey = "permission_overwrites"
|
||||||
Mentionable bool `json:"mentionable,omitempty"`
|
// Type bool, channel NSFW restriction changed
|
||||||
// A permission on a text or voice channel was allowed for a role
|
AuditChannelNSFW AuditLogChangeKey = "nsfw"
|
||||||
Allow Permissions `json:"allow,omitempty"`
|
// Type Snowflake, application ID of the added or removed webhook or bot
|
||||||
// A permission on a text or voice channel was denied for a role
|
AuditChannelApplicationID AuditLogChangeKey = "application_id"
|
||||||
Deny Permissions `json:"deny,omitempty"`
|
// Type Seconds, amount of seconds a user has to wait before sending another
|
||||||
}
|
// message changed
|
||||||
|
AuditChannelRateLimitPerUser AuditLogChangeKey = "rate_limit_per_user"
|
||||||
|
)
|
||||||
|
|
||||||
// AuditLogChangeInvite is the audit log key for InviteMetadata.
|
const (
|
||||||
type AuditLogChangeInvite struct {
|
// Type Permissions, permissions for a role changed
|
||||||
// Invite code changed
|
AuditRolePermissions AuditLogChangeKey = "permissions"
|
||||||
Code string `json:"code,omitempty"`
|
// Type Color, role color changed
|
||||||
// Channel for invite code changed
|
AuditRoleColor AuditLogChangeKey = "color"
|
||||||
ChannelID Snowflake `json:"channel_id,omitempty"`
|
// Type bool, role is now displayed/no longer displayed separate from online
|
||||||
// Person who created invite code changed
|
// users
|
||||||
InviterID Snowflake `json:"inviter_id,omitempty"`
|
AuditRoleHoist AuditLogChangeKey = "hoist"
|
||||||
// Change to max number of times invite code can be used
|
// Type bool, role is now mentionable/unmentionable
|
||||||
MaxUses int `json:"max_uses,omitempty"`
|
AuditRoleMentionable AuditLogChangeKey = "mentionable"
|
||||||
// Number of times invite code used changed
|
// Type Permissions, a permission on a text or voice channel was allowed for
|
||||||
Uses int `json:"uses,omitempty"`
|
// a role
|
||||||
// How long invite code lasts changed
|
AuditRoleAllow AuditLogChangeKey = "allow"
|
||||||
MaxAge Seconds `json:"max_age,omitempty"`
|
// Type Permissions, a permission on a text or voice channel was denied for
|
||||||
// Invite code is temporary/never expires
|
// a role
|
||||||
Temporary bool `json:"temporary,omitempty"`
|
AuditRoleDeny AuditLogChangeKey = "deny"
|
||||||
}
|
)
|
||||||
|
|
||||||
// AuditLogChangeUser is the audit log key for User.
|
const (
|
||||||
type AuditLogChangeUser struct {
|
// Type string, invite code changed
|
||||||
// User server deafened/undeafened
|
AuditInviteCode AuditLogChangeKey = "code"
|
||||||
Deaf bool `json:"deaf,omitempty"`
|
// Type Snowflake, channel for invite code changed
|
||||||
// User server muted/unmuted
|
AuditInviteChannelID AuditLogChangeKey = "channel_id"
|
||||||
Mute bool `json:"mute,omitempty"`
|
// Type Snowflake, person who created invite code changed
|
||||||
// User nickname changed
|
AuditInviteInviterID AuditLogChangeKey = "inviter_id"
|
||||||
Nick string `json:"nick,omitempty"`
|
// Type int, change to max number of times invite code can be used
|
||||||
// User avatar changed
|
AuditInviteMaxUses AuditLogChangeKey = "max_uses"
|
||||||
Avatar Hash `json:"avatar_hash,omitempty"`
|
// Type int, number of times invite code used changed
|
||||||
}
|
AuditInviteUses AuditLogChangeKey = "uses"
|
||||||
|
// Type Seconds, how long invite code lasts changed
|
||||||
|
AuditInviteMaxAge AuditLogChangeKey = "max_age"
|
||||||
|
// Type bool, invite code is temporary/never expires
|
||||||
|
AuditInviteTemporary AuditLogChangeKey = "temporary"
|
||||||
|
)
|
||||||
|
|
||||||
// AuditLogChangeIntegration is the audit log key for Integration.
|
const (
|
||||||
type AuditLogChangeIntegration struct {
|
// Type bool, user server deafened/undeafened
|
||||||
// Integration emoticons enabled/disabled
|
AuditUserDeaf AuditLogChangeKey = "deaf"
|
||||||
EnableEmoticons bool `json:"enable_emoticons,omitempty"`
|
// Type bool, user server muted/unmuted
|
||||||
// Integration expiring subscriber behavior changed
|
AuditUserMute AuditLogChangeKey = "mute"
|
||||||
ExpireBehavior int `json:"expire_behavior,omitempty"`
|
// Type string, user nickname changed
|
||||||
// Integration expire grace period changed
|
AuditUserNick AuditLogChangeKey = "nick"
|
||||||
ExpireGracePeriod int `json:"expire_grace_period,omitempty"`
|
// Type Hash, user avatar changed
|
||||||
}
|
AuditUserAvatarHash AuditLogChangeKey = "avatar_hash"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Type Snowflake, the ID of the changed entity - sometimes used in
|
||||||
|
// conjunction with other keys
|
||||||
|
AuditAnyID AuditLogChangeKey = "id"
|
||||||
|
// Type int (channel type) or string, type of entity created
|
||||||
|
AuditAnyType AuditLogChangeKey = "type"
|
||||||
|
)
|
||||||
|
|
||||||
|
const (
|
||||||
|
// Type bool, integration emoticons enabled/disabled
|
||||||
|
AuditIntegrationEnableEmoticons AuditLogChangeKey = "enable_emoticons"
|
||||||
|
// Type int, integration expiring subscriber behavior changed
|
||||||
|
AuditIntegrationExpireBehavior AuditLogChangeKey = "expire_behavior"
|
||||||
|
// Type int, integration expire grace period changed
|
||||||
|
AuditIntegrationExpireGracePeriod AuditLogChangeKey = "expire_grace_period"
|
||||||
|
)
|
||||||
|
|
|
@ -76,17 +76,18 @@ func WithJSONBody(json json.Driver, v interface{}) RequestOption {
|
||||||
}
|
}
|
||||||
|
|
||||||
var rp, wp = io.Pipe()
|
var rp, wp = io.Pipe()
|
||||||
|
var err error
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
json.EncodeStream(wp, v)
|
err = json.EncodeStream(wp, v)
|
||||||
wp.Close()
|
wp.Close()
|
||||||
}()
|
}()
|
||||||
|
|
||||||
return func(r httpdriver.Request) error {
|
return func(r httpdriver.Request) error {
|
||||||
// TODO: maybe do something to this?
|
// TODO: maybe do something to this?
|
||||||
// if err != nil {
|
if err != nil {
|
||||||
// return err
|
return err
|
||||||
// }
|
}
|
||||||
|
|
||||||
r.AddHeader(http.Header{
|
r.AddHeader(http.Header{
|
||||||
"Content-Type": {"application/json"},
|
"Content-Type": {"application/json"},
|
||||||
|
|
|
@ -31,6 +31,14 @@ func (m *Raw) UnmarshalJSON(data []byte) error {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (m Raw) UnmarshalTo(v interface{}) error {
|
||||||
|
// Leave as nil.
|
||||||
|
if len(m) == 0 {
|
||||||
|
return nil
|
||||||
|
}
|
||||||
|
return Unmarshal(m, v)
|
||||||
|
}
|
||||||
|
|
||||||
func (m Raw) String() string {
|
func (m Raw) String() string {
|
||||||
return string(m)
|
return string(m)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue