1
0
Fork 0
mirror of https://github.com/diamondburned/arikawa.git synced 2024-11-09 00:14:57 +00:00
arikawa/discord/auditlog.go

411 lines
14 KiB
Go
Raw Normal View History

2020-05-08 00:09:45 +00:00
package discord
import (
"github.com/pkg/errors"
2020-10-28 22:39:59 +00:00
"github.com/diamondburned/arikawa/v2/utils/json"
)
2020-05-08 00:09:45 +00:00
2020-05-18 12:53:42 +00:00
// https://discord.com/developers/docs/resources/audit-log#audit-log-object
2020-05-08 00:09:45 +00:00
type AuditLog struct {
2020-05-18 12:53:42 +00:00
// Webhooks is the list of webhooks found in the audit log.
2020-05-08 00:09:45 +00:00
Webhooks []Webhook `json:"webhooks"`
2020-05-18 12:53:42 +00:00
// Users is the list of users found in the audit log.
2020-05-08 00:09:45 +00:00
Users []User `json:"users"`
2020-05-18 12:53:42 +00:00
// Entries is the list of audit log entries.
Entries []AuditLogEntry `json:"audit_log_entries"`
2020-05-18 12:53:42 +00:00
// Integrations is a list ist of partial integration objects (only ID,
// Name, Type, and Account).
2020-05-08 00:09:45 +00:00
Integrations []Integration `json:"integrations"`
}
// AuditLogEntry is a single entry in the audit log.
2020-05-18 12:53:42 +00:00
//
// https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object
type AuditLogEntry struct {
2020-05-18 12:53:42 +00:00
// ID is the id of the entry.
ID AuditLogEntryID `json:"id"`
2020-05-18 12:53:42 +00:00
// TargetID is the id of the affected entity (webhook, user, role, etc.).
TargetID Snowflake `json:"target_id"`
2020-05-18 12:53:42 +00:00
// Changes are the changes made to the TargetID.
Changes []AuditLogChange `json:"changes,omitempty"`
// UserID is the id of the user who made the changes.
UserID UserID `json:"user_id"`
2020-05-08 00:09:45 +00:00
2020-05-18 12:53:42 +00:00
// ActionType is the type of action that occurred.
2020-05-08 00:09:45 +00:00
ActionType AuditLogEvent `json:"action_type"`
2020-05-18 12:53:42 +00:00
// Options contains additional info for certain action types.
Options AuditEntryInfo `json:"options,omitempty"`
// Reason is the reason for the change (0-512 characters).
Reason string `json:"reason,omitempty"`
2020-05-08 00:09:45 +00:00
}
2020-05-18 12:53:42 +00:00
// AuditLogEvent is the type of audit log action that occurred.
2020-05-08 00:09:45 +00:00
type AuditLogEvent uint8
2020-05-18 12:53:42 +00:00
// https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-events
2020-05-08 00:09:45 +00:00
const (
GuildUpdate AuditLogEvent = 1
ChannelCreate AuditLogEvent = 10
ChannelUpdate AuditLogEvent = 11
ChannelDelete AuditLogEvent = 12
ChannelOverwriteCreate AuditLogEvent = 13
ChannelOverwriteUpdate AuditLogEvent = 14
ChannelOverwriteDelete AuditLogEvent = 15
MemberKick AuditLogEvent = 20
MemberPrune AuditLogEvent = 21
MemberBanAdd AuditLogEvent = 22
MemberBanRemove AuditLogEvent = 23
MemberUpdate AuditLogEvent = 24
MemberRoleUpdate AuditLogEvent = 25
MemberMove AuditLogEvent = 26
MemberDisconnect AuditLogEvent = 27
BotAdd AuditLogEvent = 28
RoleCreate AuditLogEvent = 30
RoleUpdate AuditLogEvent = 31
RoleDelete AuditLogEvent = 32
InviteCreate AuditLogEvent = 40
InviteUpdate AuditLogEvent = 41
InviteDelete AuditLogEvent = 42
WebhookCreate AuditLogEvent = 50
WebhookUpdate AuditLogEvent = 51
WebhookDelete AuditLogEvent = 52
EmojiCreate AuditLogEvent = 60
EmojiUpdate AuditLogEvent = 61
EmojiDelete AuditLogEvent = 62
MessageDelete AuditLogEvent = 72
MessageBulkDelete AuditLogEvent = 73
MessagePin AuditLogEvent = 74
MessageUnpin AuditLogEvent = 75
IntegrationCreate AuditLogEvent = 80
IntegrationUpdate AuditLogEvent = 81
IntegrationDelete AuditLogEvent = 82
)
2020-05-18 12:53:42 +00:00
// https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info
2020-05-08 00:09:45 +00:00
type AuditEntryInfo struct {
2020-05-18 12:53:42 +00:00
// DeleteMemberDays is the number of days after which inactive members were
// kicked.
//
// Events: MEMBER_PRUNE
2020-05-08 00:09:45 +00:00
DeleteMemberDays string `json:"delete_member_days,omitempty"`
2020-05-18 12:53:42 +00:00
// MembersRemoved is the number of members removed by the prune.
//
// Events: MEMBER_PRUNE
2020-05-08 00:09:45 +00:00
MembersRemoved string `json:"members_removed,omitempty"`
2020-05-18 12:53:42 +00:00
// ChannelID is the id of the channel in which the entities were targeted.
//
// Events: MEMBER_MOVE, MESSAGE_PIN, MESSAGE_UNPIN, MESSAGE_DELETE
ChannelID ChannelID `json:"channel_id,omitempty"`
2020-05-18 12:53:42 +00:00
// MessagesID is the id of the message that was targeted.
//
// Events: MESSAGE_PIN, MESSAGE_UNPIN
MessageID MessageID `json:"message_id,omitempty"`
2020-05-18 12:53:42 +00:00
// Count is the number of entities that were targeted.
//
// Events: MESSAGE_DELETE, MESSAGE_BULK_DELETE, MEMBER_DISCONNECT,
// MEMBER_MOVE
2020-05-08 00:09:45 +00:00
Count string `json:"count,omitempty"`
2020-05-18 12:53:42 +00:00
// ID is the id of the overwritten entity.
//
// Events: CHANNEL_OVERWRITE_CREATE, CHANNEL_OVERWRITE_UPDATE,
// CHANNEL_OVERWRITE_DELETE
2020-05-08 00:09:45 +00:00
ID Snowflake `json:"id,omitempty"`
2020-05-18 12:53:42 +00:00
// Type is the type of overwritten entity.
//
// Events: CHANNEL_OVERWRITE_CREATE, CHANNEL_OVERWRITE_UPDATE,
// CHANNEL_OVERWRITE_DELETE
Type OverwriteType `json:"type,string,omitempty"`
2020-05-18 12:53:42 +00:00
// RoleName is the name of the role if type is "role".
//
// Events: CHANNEL_OVERWRITE_CREATE, CHANNEL_OVERWRITE_UPDATE,
// CHANNEL_OVERWRITE_DELETE
2020-05-08 00:09:45 +00:00
RoleName string `json:"role_name,omitempty"`
}
// 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 UserIDs because the comment said so for AuditGuildOwnerID.
// var oldOwnerID, newOwnerID discord.UserID
// if err := change.UnmarshalValues(&oldOwnerID, &newOwnerID); err != nil {
// return err
// }
//
// log.Println("Transferred ownership from user", oldOwnerID, "to", newOwnerID)
//
2020-05-08 00:09:45 +00:00
type AuditLogChange struct {
2020-05-18 12:53:42 +00:00
// Key is the name of audit log change key.
Key AuditLogChangeKey `json:"key"`
// NewValue is the new value of the key.
NewValue json.Raw `json:"new_value,omitempty"`
// OldValue is the old value of the key.
OldValue json.Raw `json:"old_value,omitempty"`
2020-05-08 00:09:45 +00:00
}
2020-05-18 12:53:42 +00:00
// UnmarshalValues unmarshals the values of the AuditLogChange into the passed
// interfaces.
func (a AuditLogChange) UnmarshalValues(old, new interface{}) error {
if err := a.NewValue.UnmarshalTo(new); err != nil {
2020-05-16 21:14:49 +00:00
return errors.Wrap(err, "failed to unmarshal old value")
}
if err := a.OldValue.UnmarshalTo(old); err != nil {
2020-05-16 21:14:49 +00:00
return errors.Wrap(err, "failed to unmarshal new value")
}
return nil
2020-05-08 00:09:45 +00:00
}
type AuditLogChangeKey string
2020-05-08 00:09:45 +00:00
2020-05-18 12:53:42 +00:00
// https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-key
const (
2020-05-18 12:53:42 +00:00
// AuditGuildName gets sent if the guild's name was changed.
//
// Type: string
AuditGuildName AuditLogChangeKey = "name"
2020-05-18 12:53:42 +00:00
// AuditGuildIconHash gets sent if the guild's icon was changed.
//
// Type: Hash
AuditGuildIconHash AuditLogChangeKey = "icon_hash"
2020-05-18 12:53:42 +00:00
// AuditGuildSplashHash gets sent if the guild's invite splash page artwork
// was changed.
//
// Type: Hash
AuditGuildSplashHash AuditLogChangeKey = "splash_hash"
2020-05-18 12:53:42 +00:00
// AuditGuildOwnerID gets sent if the guild's owner changed.
//
// Type: UserID
AuditGuildOwnerID AuditLogChangeKey = "owner_id"
2020-05-18 12:53:42 +00:00
// AuditGuildRegion gets sent if the guild's region changed.
//
// Type: string
AuditGuildRegion AuditLogChangeKey = "region"
2020-05-18 12:53:42 +00:00
// AuditGuildAFKChannelID gets sent if the guild's afk channel changed.
//
// Type: ChannelID
AuditGuildAFKChannelID AuditLogChangeKey = "afk_channel_id"
2020-05-18 12:53:42 +00:00
// AuditGuildAFKTimeout gets sent if the guild's afk timeout duration
// changed.
//
// Type: Seconds
AuditGuildAFKTimeout AuditLogChangeKey = "afk_timeout"
2020-05-18 12:53:42 +00:00
// AuditGuildMFA gets sent if the two-factor auth requirement changed.
//
// Type: MFALevel
AuditGuildMFA AuditLogChangeKey = "mfa_level"
2020-05-18 12:53:42 +00:00
// AuditGuildVerification gets sent if the guild's required verification
// level changed
//
// Type: Verification
AuditGuildVerification AuditLogChangeKey = "verification_level"
2020-05-18 12:53:42 +00:00
// AuditGuildExplicitFilter gets sent if there was a change in whose
// messages are scanned and deleted for explicit content in the server.
//
// Type: ExplicitFilter
AuditGuildExplicitFilter AuditLogChangeKey = "explicit_content_filter"
2020-05-18 12:53:42 +00:00
// AuditGuildNotification gets sent if the default message notification
// level changed.
//
// Type: Notification
AuditGuildNotification AuditLogChangeKey = "default_message_notifications"
2020-05-18 12:53:42 +00:00
// AuditGuildVanityURLCode gets sent if the guild invite vanity URL
// changed.
//
// Type: string
AuditGuildVanityURLCode AuditLogChangeKey = "vanity_url_code"
2020-05-18 12:53:42 +00:00
// AuditGuildRoleAdd gets sent if a new role was added.
//
// Type: []Role{ID, Name}
AuditGuildRoleAdd AuditLogChangeKey = "$add"
2020-05-18 12:53:42 +00:00
// AuditGuildRoleRemove gets sent if a role was removed.
//
// Type: []Role{ID, Name}
AuditGuildRoleRemove AuditLogChangeKey = "$remove"
2020-05-18 12:53:42 +00:00
// AuditGuildPruneDeleteDays gets sent if there was a change in number of
// days after which inactive and role-unassigned members are kicked.
//
// Type: int
AuditGuildPruneDeleteDays AuditLogChangeKey = "prune_delete_days"
2020-05-18 12:53:42 +00:00
// AuditGuildWidgetEnabled gets sent if the guild's widget was
// enabled/disabled.
//
// Type: bool
AuditGuildWidgetEnabled AuditLogChangeKey = "widget_enabled"
2020-05-18 12:53:42 +00:00
// AuditGuildWidgetChannelID gets sent if the channel ID of the guild
// widget changed.
//
// Type: ChannelID
AuditGuildWidgetChannelID AuditLogChangeKey = "widget_channel_id"
2020-05-18 12:53:42 +00:00
// AuditGuildSystemChannelID gets sent if the ID of the guild's system
// channel changed.
//
// Type: ChannelID
AuditGuildSystemChannelID AuditLogChangeKey = "system_channel_id"
)
2020-05-08 00:09:45 +00:00
const (
2020-05-18 12:53:42 +00:00
// AuditChannelPosition gets sent if a text or voice channel position was
// changed.
//
// Type: int
AuditChannelPosition AuditLogChangeKey = "position"
2020-05-18 12:53:42 +00:00
// AuditChannelTopic gets sent if the text channel topic changed.
//
// Type: string
AuditChannelTopic AuditLogChangeKey = "topic"
2020-05-18 12:53:42 +00:00
// AuditChannelBitrate gets sent if the voice channel bitrate changed.
//
// Type: uint
AuditChannelBitrate AuditLogChangeKey = "bitrate"
2020-05-18 12:53:42 +00:00
// AuditChannelPermissionOverwrites gets sent if the permissions on a
// channel changed.
//
// Type: []Overwrite
AuditChannelPermissionOverwrites AuditLogChangeKey = "permission_overwrites"
2020-05-18 12:53:42 +00:00
// AuditChannelNSFW gets sent if the channel NSFW restriction changed.
//
// Type: bool
AuditChannelNSFW AuditLogChangeKey = "nsfw"
2020-05-18 12:53:42 +00:00
// AuditChannelApplicationID contains the application ID of the added or
// removed webhook or bot.
//
// Type: AppID
AuditChannelApplicationID AuditLogChangeKey = "application_id"
2020-05-18 12:53:42 +00:00
// AuditChannelRateLimitPerUser gets sent if the amount of seconds a user
// has to wait before sending another message changed.
//
// Type: Seconds
AuditChannelRateLimitPerUser AuditLogChangeKey = "rate_limit_per_user"
)
2020-05-08 00:09:45 +00:00
const (
2020-05-18 12:53:42 +00:00
// AuditRolePermissions gets sent if the permissions for a role changed.
//
// Type: Permissions
AuditRolePermissions AuditLogChangeKey = "permissions"
2020-05-18 12:53:42 +00:00
// AuditRoleColor gets sent if the role color changed.
//
// Type: Color
AuditRoleColor AuditLogChangeKey = "color"
2020-05-18 12:53:42 +00:00
// AuditRoleHoist gets sent if the role is now displayed/no longer
// displayed separate from online users.
//
// Type: bool
AuditRoleHoist AuditLogChangeKey = "hoist"
2020-05-18 12:53:42 +00:00
// AuditRoleMentionable gets sent if a role is now
// mentionable/unmentionable.
//
// Type: bool
AuditRoleMentionable AuditLogChangeKey = "mentionable"
2020-05-18 12:53:42 +00:00
// AuditRoleAllow gets sent if a permission on a text or voice channel was
// allowed for a role.
//
// Type: Permissions
AuditRoleAllow AuditLogChangeKey = "allow"
2020-05-18 12:53:42 +00:00
// AuditRoleDeny gets sent if a permission on a text or voice channel was
// denied for a role.
//
// Type: Permissions
AuditRoleDeny AuditLogChangeKey = "deny"
)
2020-05-08 00:09:45 +00:00
const (
2020-05-18 12:53:42 +00:00
// AuditInviteCode gets sent if an invite code changed.
//
// Type: string
AuditInviteCode AuditLogChangeKey = "code"
2020-05-18 12:53:42 +00:00
// AuditInviteChannelID gets sent if the channel for an invite code
// changed.
//
// Type: ChannelID
AuditInviteChannelID AuditLogChangeKey = "channel_id"
2020-05-18 12:53:42 +00:00
// AuditInviteInviterID specifies the person who created invite code
// changed.
//
// Type: UserID
AuditInviteInviterID AuditLogChangeKey = "inviter_id"
2020-05-18 12:53:42 +00:00
// AuditInviteMaxUses specifies the change to max number of times invite
// code can be used.
//
// Type: int
AuditInviteMaxUses AuditLogChangeKey = "max_uses"
2020-05-18 12:53:42 +00:00
// AuditInviteUses specifies the number of times invite code used changed.
//
// Type: int
AuditInviteUses AuditLogChangeKey = "uses"
2020-05-18 12:53:42 +00:00
// AuditInviteMaxAge specifies the how long invite code lasts
// changed.
//
// Type: Seconds
AuditInviteMaxAge AuditLogChangeKey = "max_age"
2020-05-18 12:53:42 +00:00
// AuditInviteTemporary specifies if an invite code is temporary/never
// expires.
//
// Type: bool
AuditInviteTemporary AuditLogChangeKey = "temporary"
)
2020-05-08 00:09:45 +00:00
const (
2020-05-18 12:53:42 +00:00
// AuditUserDeaf specifies if the user was server deafened/undeafened.
//
// Type: bool
AuditUserDeaf AuditLogChangeKey = "deaf"
2020-05-18 12:53:42 +00:00
// AuditUserMute specifies if the user was server muted/unmuted.
//
// Type: bool
AuditUserMute AuditLogChangeKey = "mute"
2020-05-18 12:53:42 +00:00
// AuditUserNick specifies the new nickname of the user.
//
// Type: string
AuditUserNick AuditLogChangeKey = "nick"
2020-05-18 12:53:42 +00:00
// AuditUserAvatar specifies the hash of the new user avatar.
//
// Type: Hash
AuditUserAvatarHash AuditLogChangeKey = "avatar_hash"
)
const (
2020-05-18 12:53:42 +00:00
// AuditAnyID specifies the ID of the changed entity - sometimes used in
// conjunction with other keys.
//
// Type: Snowflake
AuditAnyID AuditLogChangeKey = "id"
2020-05-18 12:53:42 +00:00
// AuditAnyType is the type of the entity created.
// Type ChannelType or string
AuditAnyType AuditLogChangeKey = "type"
)
const (
2020-05-18 12:53:42 +00:00
// AuditIntegrationEnableEmoticons gets sent if the integration emoticons
// were enabled/disabled.
//
// Type: bool
AuditIntegrationEnableEmoticons AuditLogChangeKey = "enable_emoticons"
2020-05-18 12:53:42 +00:00
// AuditIntegrationExpireBehavior gets sent if the integration expiring
// subscriber behavior changed.
//
// Type: ExpireBehavior
AuditIntegrationExpireBehavior AuditLogChangeKey = "expire_behavior"
2020-05-18 12:53:42 +00:00
// AuditIntegrationExpireGracePeriod gets sent if the integration expire
// grace period changed.
//
// Type: int
AuditIntegrationExpireGracePeriod AuditLogChangeKey = "expire_grace_period"
)