github.com/diamondburned/arikawa@v1.3.14/discord/auditlog.go (about)

     1  package discord
     2  
     3  import (
     4  	"github.com/pkg/errors"
     5  
     6  	"github.com/diamondburned/arikawa/utils/json"
     7  )
     8  
     9  // https://discord.com/developers/docs/resources/audit-log#audit-log-object
    10  type AuditLog struct {
    11  	// Webhooks is the list of webhooks found in the audit log.
    12  	Webhooks []Webhook `json:"webhooks"`
    13  	// Users is the list of users found in the audit log.
    14  	Users []User `json:"users"`
    15  	// Entries is the list of audit log entries.
    16  	Entries []AuditLogEntry `json:"audit_log_entries"`
    17  	// Integrations is a list ist of partial integration objects (only ID,
    18  	// Name, Type, and Account).
    19  	Integrations []Integration `json:"integrations"`
    20  }
    21  
    22  // AuditLogEntry is a single entry in the audit log.
    23  //
    24  // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object
    25  type AuditLogEntry struct {
    26  	// ID is the id of the entry.
    27  	ID AuditLogEntryID `json:"id"`
    28  	// TargetID is the id of the affected entity (webhook, user, role, etc.).
    29  	TargetID string `json:"target_id,omitempty"`
    30  	// Changes are the changes made to the TargetID.
    31  	Changes []AuditLogChange `json:"changes,omitempty"`
    32  	// UserID is the id of the user who made the changes.
    33  	UserID UserID `json:"user_id"`
    34  
    35  	// ActionType is the type of action that occurred.
    36  	ActionType AuditLogEvent `json:"action_type"`
    37  
    38  	// Options contains additional info for certain action types.
    39  	Options AuditEntryInfo `json:"options,omitempty"`
    40  	// Reason is the reason for the change (0-512 characters).
    41  	Reason string `json:"reason,omitempty"`
    42  }
    43  
    44  // AuditLogEvent is the type of audit log action that occurred.
    45  type AuditLogEvent uint8
    46  
    47  // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-audit-log-events
    48  const (
    49  	GuildUpdate            AuditLogEvent = 1
    50  	ChannelCreate          AuditLogEvent = 10
    51  	ChannelUpdate          AuditLogEvent = 11
    52  	ChannelDelete          AuditLogEvent = 12
    53  	ChannelOverwriteCreate AuditLogEvent = 13
    54  	ChannelOverwriteUpdate AuditLogEvent = 14
    55  	ChannelOverwriteDelete AuditLogEvent = 15
    56  	MemberKick             AuditLogEvent = 20
    57  	MemberPrune            AuditLogEvent = 21
    58  	MemberBanAdd           AuditLogEvent = 22
    59  	MemberBanRemove        AuditLogEvent = 23
    60  	MemberUpdate           AuditLogEvent = 24
    61  	MemberRoleUpdate       AuditLogEvent = 25
    62  	MemberMove             AuditLogEvent = 26
    63  	MemberDisconnect       AuditLogEvent = 27
    64  	BotAdd                 AuditLogEvent = 28
    65  	RoleCreate             AuditLogEvent = 30
    66  	RoleUpdate             AuditLogEvent = 31
    67  	RoleDelete             AuditLogEvent = 32
    68  	InviteCreate           AuditLogEvent = 40
    69  	InviteUpdate           AuditLogEvent = 41
    70  	InviteDelete           AuditLogEvent = 42
    71  	WebhookCreate          AuditLogEvent = 50
    72  	WebhookUpdate          AuditLogEvent = 51
    73  	WebhookDelete          AuditLogEvent = 52
    74  	EmojiCreate            AuditLogEvent = 60
    75  	EmojiUpdate            AuditLogEvent = 61
    76  	EmojiDelete            AuditLogEvent = 62
    77  	MessageDelete          AuditLogEvent = 72
    78  	MessageBulkDelete      AuditLogEvent = 73
    79  	MessagePin             AuditLogEvent = 74
    80  	MessageUnpin           AuditLogEvent = 75
    81  	IntegrationCreate      AuditLogEvent = 80
    82  	IntegrationUpdate      AuditLogEvent = 81
    83  	IntegrationDelete      AuditLogEvent = 82
    84  )
    85  
    86  // https://discord.com/developers/docs/resources/audit-log#audit-log-entry-object-optional-audit-entry-info
    87  type AuditEntryInfo struct {
    88  	// DeleteMemberDays is the number of days after which inactive members were
    89  	// kicked.
    90  	//
    91  	// Events: MEMBER_PRUNE
    92  	DeleteMemberDays string `json:"delete_member_days,omitempty"`
    93  	// MembersRemoved is the number of members removed by the prune.
    94  	//
    95  	// Events: MEMBER_PRUNE
    96  	MembersRemoved string `json:"members_removed,omitempty"`
    97  	// ChannelID is the id of the channel in which the entities were targeted.
    98  	//
    99  	// Events: MEMBER_MOVE, MESSAGE_PIN, MESSAGE_UNPIN, MESSAGE_DELETE
   100  	ChannelID ChannelID `json:"channel_id,omitempty"`
   101  	// MessagesID is the id of the message that was targeted.
   102  	//
   103  	// Events: MESSAGE_PIN, MESSAGE_UNPIN
   104  	MessageID MessageID `json:"message_id,omitempty"`
   105  	// Count is the number of entities that were targeted.
   106  	//
   107  	// Events: MESSAGE_DELETE, MESSAGE_BULK_DELETE, MEMBER_DISCONNECT,
   108  	// MEMBER_MOVE
   109  	Count string `json:"count,omitempty"`
   110  	// ID is the id of the overwritten entity.
   111  	//
   112  	// Events: CHANNEL_OVERWRITE_CREATE, CHANNEL_OVERWRITE_UPDATE,
   113  	// CHANNEL_OVERWRITE_DELETE
   114  	ID Snowflake `json:"id,omitempty"`
   115  	// Type is the type of overwritten entity.
   116  	//
   117  	// Events: CHANNEL_OVERWRITE_CREATE, CHANNEL_OVERWRITE_UPDATE,
   118  	// CHANNEL_OVERWRITE_DELETE
   119  	Type ChannelOverwritten `json:"type,omitempty"`
   120  	// RoleName is the name of the role if type is "role".
   121  	//
   122  	// Events: CHANNEL_OVERWRITE_CREATE, CHANNEL_OVERWRITE_UPDATE,
   123  	// CHANNEL_OVERWRITE_DELETE
   124  	RoleName string `json:"role_name,omitempty"`
   125  }
   126  
   127  // ChannelOverwritten is the type of overwritten entity in
   128  // (AuditEntryInfo).Type.
   129  type ChannelOverwritten string
   130  
   131  const (
   132  	MemberChannelOverwritten ChannelOverwritten = "member"
   133  	RoleChannelOverwritten   ChannelOverwritten = "role"
   134  )
   135  
   136  // AuditLogChange is a single key type to changed value audit log entry. The
   137  // type can be found in the key's comment. Values can be nil.
   138  //
   139  // What
   140  //
   141  // I'm glad to see the same reaction that I had on you. In short, in this
   142  // struct, the Key dictates what type NewValue and OldValue will have. They will
   143  // always be the same type, but I will leave that as JSON for the user.
   144  //
   145  // Usage
   146  //
   147  // The usage of this is pretty simple, as AuditLogChange already has a
   148  // convenient method to use. Here's an example on how to do "owner_id":
   149  //
   150  //    if change.Key != discord.AuditGuildOwnerID {
   151  //        return errors.New("not owner ID")
   152  //    }
   153  //
   154  //    // We know these are UserIDs because the comment said so for AuditGuildOwnerID.
   155  //    var oldOwnerID, newOwnerID discord.UserID
   156  //    if err := change.UnmarshalValues(&oldOwnerID, &newOwnerID); err != nil {
   157  //        return err
   158  //    }
   159  //
   160  //    log.Println("Transferred ownership from user", oldOwnerID, "to", newOwnerID)
   161  //
   162  type AuditLogChange struct {
   163  	// Key is the name of audit log change key.
   164  	Key AuditLogChangeKey `json:"key"`
   165  	// NewValue is the new value of the key.
   166  	NewValue json.Raw `json:"new_value,omitempty"`
   167  	// OldValue is the old value of the key.
   168  	OldValue json.Raw `json:"old_value,omitempty"`
   169  }
   170  
   171  // UnmarshalValues unmarshals the values of the AuditLogChange into the passed
   172  // interfaces.
   173  func (a AuditLogChange) UnmarshalValues(old, new interface{}) error {
   174  	if err := a.NewValue.UnmarshalTo(new); err != nil {
   175  		return errors.Wrap(err, "failed to unmarshal old value")
   176  	}
   177  	if err := a.OldValue.UnmarshalTo(old); err != nil {
   178  		return errors.Wrap(err, "failed to unmarshal new value")
   179  	}
   180  	return nil
   181  }
   182  
   183  type AuditLogChangeKey string
   184  
   185  // https://discord.com/developers/docs/resources/audit-log#audit-log-change-object-audit-log-change-key
   186  const (
   187  	// AuditGuildName gets sent if the guild's name was changed.
   188  	//
   189  	// Type: string
   190  	AuditGuildName AuditLogChangeKey = "name"
   191  	// AuditGuildIconHash gets sent if the guild's icon was changed.
   192  	//
   193  	// Type: Hash
   194  	AuditGuildIconHash AuditLogChangeKey = "icon_hash"
   195  	// AuditGuildSplashHash gets sent if the guild's invite splash page artwork
   196  	// was changed.
   197  	//
   198  	// Type: Hash
   199  	AuditGuildSplashHash AuditLogChangeKey = "splash_hash"
   200  	// AuditGuildOwnerID gets sent if the guild's owner changed.
   201  	//
   202  	// Type: UserID
   203  	AuditGuildOwnerID AuditLogChangeKey = "owner_id"
   204  	// AuditGuildRegion gets sent if the guild's region changed.
   205  	//
   206  	// Type: string
   207  	AuditGuildRegion AuditLogChangeKey = "region"
   208  	// AuditGuildAFKChannelID gets sent if the guild's afk channel changed.
   209  	//
   210  	// Type: ChannelID
   211  	AuditGuildAFKChannelID AuditLogChangeKey = "afk_channel_id"
   212  	// AuditGuildAFKTimeout gets sent if the guild's afk timeout duration
   213  	// changed.
   214  	//
   215  	// Type: Seconds
   216  	AuditGuildAFKTimeout AuditLogChangeKey = "afk_timeout"
   217  	// AuditGuildMFA gets sent if the two-factor auth requirement changed.
   218  	//
   219  	// Type: MFALevel
   220  	AuditGuildMFA AuditLogChangeKey = "mfa_level"
   221  	// AuditGuildVerification gets sent if the guild's required verification
   222  	// level changed
   223  	//
   224  	// Type: Verification
   225  	AuditGuildVerification AuditLogChangeKey = "verification_level"
   226  	// AuditGuildExplicitFilter gets sent if there was a change in whose
   227  	// messages are scanned and deleted for explicit content in the server.
   228  	//
   229  	// Type: ExplicitFilter
   230  	AuditGuildExplicitFilter AuditLogChangeKey = "explicit_content_filter"
   231  	// AuditGuildNotification gets sent if the default message notification
   232  	// level changed.
   233  	//
   234  	// Type: Notification
   235  	AuditGuildNotification AuditLogChangeKey = "default_message_notifications"
   236  	// AuditGuildVanityURLCode gets sent if the guild invite vanity URL
   237  	// changed.
   238  	//
   239  	// Type: string
   240  	AuditGuildVanityURLCode AuditLogChangeKey = "vanity_url_code"
   241  	// AuditGuildRoleAdd gets sent if a new role was added.
   242  	//
   243  	// Type: []Role{ID, Name}
   244  	AuditGuildRoleAdd AuditLogChangeKey = "$add"
   245  	// AuditGuildRoleRemove gets sent if a role was removed.
   246  	//
   247  	// Type: []Role{ID, Name}
   248  	AuditGuildRoleRemove AuditLogChangeKey = "$remove"
   249  	// AuditGuildPruneDeleteDays gets sent if there was a change in number of
   250  	// days after which inactive and role-unassigned members are kicked.
   251  	//
   252  	// Type: int
   253  	AuditGuildPruneDeleteDays AuditLogChangeKey = "prune_delete_days"
   254  	// AuditGuildWidgetEnabled gets sent if the guild's widget was
   255  	// enabled/disabled.
   256  	//
   257  	// Type: bool
   258  	AuditGuildWidgetEnabled AuditLogChangeKey = "widget_enabled"
   259  	// AuditGuildWidgetChannelID gets sent if the channel ID of the guild
   260  	// widget changed.
   261  	//
   262  	// Type: ChannelID
   263  	AuditGuildWidgetChannelID AuditLogChangeKey = "widget_channel_id"
   264  	// AuditGuildSystemChannelID gets sent if the ID of the guild's system
   265  	// channel changed.
   266  	//
   267  	// Type: ChannelID
   268  	AuditGuildSystemChannelID AuditLogChangeKey = "system_channel_id"
   269  )
   270  
   271  const (
   272  	// AuditChannelPosition gets sent if a text or voice channel position was
   273  	// changed.
   274  	//
   275  	// Type: int
   276  	AuditChannelPosition AuditLogChangeKey = "position"
   277  	// AuditChannelTopic gets sent if the text channel topic changed.
   278  	//
   279  	// Type: string
   280  	AuditChannelTopic AuditLogChangeKey = "topic"
   281  	// AuditChannelBitrate gets sent if the voice channel bitrate changed.
   282  	//
   283  	// Type: uint
   284  	AuditChannelBitrate AuditLogChangeKey = "bitrate"
   285  	// AuditChannelPermissionOverwrites gets sent if the permissions on a
   286  	// channel changed.
   287  	//
   288  	// Type: []Overwrite
   289  	AuditChannelPermissionOverwrites AuditLogChangeKey = "permission_overwrites"
   290  	// AuditChannelNSFW gets sent if the channel NSFW restriction changed.
   291  	//
   292  	// Type: bool
   293  	AuditChannelNSFW AuditLogChangeKey = "nsfw"
   294  	// AuditChannelApplicationID contains the application ID of the added or
   295  	// removed webhook or bot.
   296  	//
   297  	// Type: AppID
   298  	AuditChannelApplicationID AuditLogChangeKey = "application_id"
   299  	// AuditChannelRateLimitPerUser gets sent if the amount of seconds a user
   300  	// has to wait before sending another message changed.
   301  	//
   302  	// Type: Seconds
   303  	AuditChannelRateLimitPerUser AuditLogChangeKey = "rate_limit_per_user"
   304  )
   305  
   306  const (
   307  	// AuditRolePermissions gets sent if the permissions for a role changed.
   308  	//
   309  	// Type: Permissions
   310  	AuditRolePermissions AuditLogChangeKey = "permissions"
   311  	// AuditRoleColor gets sent if the role color changed.
   312  	//
   313  	// Type: Color
   314  	AuditRoleColor AuditLogChangeKey = "color"
   315  	// AuditRoleHoist gets sent if the role is now displayed/no longer
   316  	// displayed separate from online users.
   317  	//
   318  	// Type: bool
   319  	AuditRoleHoist AuditLogChangeKey = "hoist"
   320  	// AuditRoleMentionable gets sent if a role is now
   321  	// mentionable/unmentionable.
   322  	//
   323  	// Type: bool
   324  	AuditRoleMentionable AuditLogChangeKey = "mentionable"
   325  	// AuditRoleAllow gets sent if a permission on a text or voice channel was
   326  	// allowed for a role.
   327  	//
   328  	// Type: Permissions
   329  	AuditRoleAllow AuditLogChangeKey = "allow"
   330  	// AuditRoleDeny gets sent if a permission on a text or voice channel was
   331  	// denied for a role.
   332  	//
   333  	// Type: Permissions
   334  	AuditRoleDeny AuditLogChangeKey = "deny"
   335  )
   336  
   337  const (
   338  	// AuditInviteCode gets sent if an invite code changed.
   339  	//
   340  	// Type: string
   341  	AuditInviteCode AuditLogChangeKey = "code"
   342  	// AuditInviteChannelID gets sent if the channel for an invite code
   343  	// changed.
   344  	//
   345  	// Type: ChannelID
   346  	AuditInviteChannelID AuditLogChangeKey = "channel_id"
   347  	// AuditInviteInviterID specifies the person who created invite code
   348  	// changed.
   349  	//
   350  	// Type: UserID
   351  	AuditInviteInviterID AuditLogChangeKey = "inviter_id"
   352  	// AuditInviteMaxUses specifies the change to max number of times invite
   353  	// code can be used.
   354  	//
   355  	// Type: int
   356  	AuditInviteMaxUses AuditLogChangeKey = "max_uses"
   357  	// AuditInviteUses specifies the number of times invite code used changed.
   358  	//
   359  	// Type: int
   360  	AuditInviteUses AuditLogChangeKey = "uses"
   361  	// AuditInviteMaxAge specifies the how long invite code lasts
   362  	// changed.
   363  	//
   364  	// Type: Seconds
   365  	AuditInviteMaxAge AuditLogChangeKey = "max_age"
   366  	// AuditInviteTemporary specifies if an invite code is temporary/never
   367  	// expires.
   368  	//
   369  	// Type: bool
   370  	AuditInviteTemporary AuditLogChangeKey = "temporary"
   371  )
   372  
   373  const (
   374  	// AuditUserDeaf specifies if the user was server deafened/undeafened.
   375  	//
   376  	// Type: bool
   377  	AuditUserDeaf AuditLogChangeKey = "deaf"
   378  	// AuditUserMute specifies if the user was server muted/unmuted.
   379  	//
   380  	// Type: bool
   381  	AuditUserMute AuditLogChangeKey = "mute"
   382  	// AuditUserNick specifies the new nickname of the user.
   383  	//
   384  	// Type: string
   385  	AuditUserNick AuditLogChangeKey = "nick"
   386  	// AuditUserAvatar specifies the hash of the new user avatar.
   387  	//
   388  	// Type: Hash
   389  	AuditUserAvatarHash AuditLogChangeKey = "avatar_hash"
   390  )
   391  
   392  const (
   393  	// AuditAnyID specifies the ID of the changed entity - sometimes used in
   394  	// conjunction with other keys.
   395  	//
   396  	// Type: Snowflake
   397  	AuditAnyID AuditLogChangeKey = "id"
   398  	// AuditAnyType is the type of the entity created.
   399  	// Type ChannelType or string
   400  	AuditAnyType AuditLogChangeKey = "type"
   401  )
   402  
   403  const (
   404  	// AuditIntegrationEnableEmoticons gets sent if the integration emoticons
   405  	// were enabled/disabled.
   406  	//
   407  	// Type: bool
   408  	AuditIntegrationEnableEmoticons AuditLogChangeKey = "enable_emoticons"
   409  	// AuditIntegrationExpireBehavior gets sent if the integration expiring
   410  	// subscriber behavior changed.
   411  	//
   412  	// Type: ExpireBehavior
   413  	AuditIntegrationExpireBehavior AuditLogChangeKey = "expire_behavior"
   414  	// AuditIntegrationExpireGracePeriod gets sent if the integration expire
   415  	// grace period changed.
   416  	//
   417  	// Type: int
   418  	AuditIntegrationExpireGracePeriod AuditLogChangeKey = "expire_grace_period"
   419  )