forked from andersfylling/disgord
-
Notifications
You must be signed in to change notification settings - Fork 0
/
struct_auditlog.go
246 lines (209 loc) · 10.3 KB
/
struct_auditlog.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
package disgord
import "sync"
const (
AuditLogEvtGuildUpdate = 1
AuditLogEvtChannelCreate = 10
AuditLogEvtChannelUpdate = 11
AuditLogEvtChannelDelete = 12
AuditLogEvtOverwriteCreate = 13
AuditLogEvtOverwriteUpdate = 14
AuditLogEvtOverwriteDelete = 15
AuditLogEvtMemberKick = 20
AuditLogEvtMemberPrune = 21
AuditLogEvtMemberBanAdd = 22
AuditLogEvtMemberBanRemove = 23
AuditLogEvtMemberUpdate = 24
AuditLogEvtMemberRoleUpdate = 25
AuditLogEvtRoleCreate = 30
AuditLogEvtRoleUpdate = 31
AuditLogEvtRoleDelete = 32
AuditLogEvtInviteCreate = 40
AuditLogEvtInviteUpdate = 41
AuditLogEvtInviteDelete = 42
AuditLogEvtWebhookCreate = 50
AuditLogEvtWebhookUpdate = 51
AuditLogEvtWebhookDelete = 52
AuditLogEvtEmojiCreate = 60
AuditLogEvtEmojiUpdate = 61
AuditLogEvtEmojiDelete = 62
AuditLogEvtMessageDelete = 72
)
const (
// key name, identifier changed, type, description
AuditLogChangeKeyName = "name" // guild string name changed
AuditLogChangeKeyIconHash = "icon_hash" // guild string icon changed
AuditLogChangeKeySplashHash = "splash_hash" // guild string invite splash page artwork changed
AuditLogChangeKeyOwnerID = "owner_id" // guild snowflake owner changed
AuditLogChangeKeyRegion = "region" // guild string region changed
AuditLogChangeKeyAFKChannelID = "afk_channel_id" // guild snowflake afk channel changed
AuditLogChangeKeyAFKTimeout = "afk_timeout" // guild integer afk timeout duration changed
AuditLogChangeKeyMFALevel = "mfa_level" // guild integer two-factor auth requirement changed
AuditLogChangeKeyVerificationLevel = "verification_level" // guild integer required verification level changed
AuditLogChangeKeyExplicitContentFilter = "explicit_content_filter" // guild integer change in whose messages are scanned and deleted for explicit content in the server
AuditLogChangeKeyDefaultMessageNotifications = "default_message_notifications" // guild integer default message notification level changed
AuditLogChangeKeyVanityURLCode = "vanity_url_code" // guild string guild invite vanity url changed
AuditLogChangeKeyAdd = "$add" // add guild array of role objects new role added
AuditLogChangeKeyRemove = "$remove" // remove guild array of role objects role removed
AuditLogChangeKeyPruneDeleteDays = "prune_delete_days" // guild integer change in number of days after which inactive and role-unassigned members are kicked
AuditLogChangeKeyWidgetEnabled = "widget_enabled" // guild bool server widget enabled/disable
AuditLogChangeKeyWidgetChannelID = "widget_channel_id" // guild snowflake channel id of the server widget changed
AuditLogChangeKeyPosition = "position" // channel integer text or voice channel position changed
AuditLogChangeKeyTopic = "topic" // channel string text channel topic changed
AuditLogChangeKeyBitrate = "bitrate" // channel integer voice channel bitrate changed
AuditLogChangeKeyPermissionOverwrites = "permission_overwrites" // channel array of channel overwrite objects permissions on a channel changed
AuditLogChangeKeyNSFW = "nsfw" // channel bool channel nsfw restriction changed
AuditLogChangeKeyApplicationID = "application_id" // channel snowflake application id of the added or removed webhook or bot
AuditLogChangeKeyPermissions = "permissions" // role integer permissions for a role changed
AuditLogChangeKeyColor = "color" // role integer role color changed
AuditLogChangeKeyHoist = "hoist" // role bool role is now displayed/no longer displayed separate from online users
AuditLogChangeKeyMentionable = "mentionable" // role bool role is now mentionable/unmentionable
AuditLogChangeKeyAllow = "allow" // role integer a permission on a text or voice channel was allowed for a role
AuditLogChangeKeyDeny = "deny" // role integer a permission on a text or voice channel was denied for a role
AuditLogChangeKeyCode = "code" // invite string invite code changed
AuditLogChangeKeyChannelID = "channel_id" // invite snowflake channel for invite code changed
AuditLogChangeKeyInviterID = "inviter_id" // invite snowflake person who created invite code changed
AuditLogChangeKeyMaxUses = "max_uses" // invite integer change to max number of times invite code can be used
AuditLogChangeKeyUses = "uses" // invite integer number of times invite code used changed
AuditLogChangeKeyMaxAge = "max_age" // invite integer how long invite code lasts changed
AuditLogChangeKeyTemporary = "temporary" // invite bool invite code is temporary/never expires
AuditLogChangeKeyDeaf = "deaf" // user bool user server deafened/undeafened
AuditLogChangeKeyMute = "mute" // user bool user server muted/unmuteds
AuditLogChangeKeyNick = "nick" // user string user nickname changed
AuditLogChangeKeyAvatarHash = "avatar_hash" // user string user avatar changed
AuditLogChangeKeyID = "id" // any snowflake the id of the changed entity - sometimes used in conjunction with other keys
AuditLogChangeKeyType = "type" // any integer (channel type) or string type of entity created
)
type AuditLog struct {
sync.RWMutex `json:"-"`
Webhooks []*Webhook `json:"webhooks"`
Users []*User `json:"users"`
AuditLogEntries []*AuditLogEntry `json:"audit_log_entries"`
}
func (l *AuditLog) DeepCopy() (copy interface{}) {
copy = &AuditLog{}
l.CopyOverTo(copy)
return
}
func (l *AuditLog) CopyOverTo(other interface{}) (err error) {
var ok bool
var log *AuditLog
if log, ok = other.(*AuditLog); !ok {
err = NewErrorUnsupportedType("given interface{} was not of type *AuditLog")
return
}
l.RLock()
log.Lock()
for _, webhook := range l.Webhooks {
log.Webhooks = append(log.Webhooks, webhook.DeepCopy().(*Webhook))
}
for _, user := range l.Users {
log.Users = append(log.Users, user.DeepCopy().(*User))
}
for _, entry := range l.AuditLogEntries {
log.AuditLogEntries = append(log.AuditLogEntries, entry.DeepCopy().(*AuditLogEntry))
}
l.RUnlock()
log.Unlock()
return
}
type AuditLogEntry struct {
sync.RWMutex `json:"-"`
TargetID Snowflake `json:"target_id"`
Changes []*AuditLogChange `json:"changes,omitempty"`
UserID Snowflake `json:"user_id"`
ID Snowflake `json:"id"`
ActionType uint `json:"action_type"`
Options []*AuditLogOption `json:"options,omitempty"`
Reason string `json:"reason,omitempty"`
}
func (l *AuditLogEntry) DeepCopy() (copy interface{}) {
copy = &AuditLogEntry{}
l.CopyOverTo(copy)
return
}
func (l *AuditLogEntry) CopyOverTo(other interface{}) (err error) {
var ok bool
var log *AuditLogEntry
if log, ok = other.(*AuditLogEntry); !ok {
err = NewErrorUnsupportedType("given interface{} was not of type *AuditLogEntry")
return
}
l.RLock()
log.Lock()
log.TargetID = l.TargetID
log.UserID = l.UserID
log.ID = l.ID
log.ActionType = l.ActionType
log.Reason = l.Reason
for _, change := range l.Changes {
log.Changes = append(log.Changes, change.DeepCopy().(*AuditLogChange))
}
for _, option := range l.Options {
log.Options = append(log.Options, option.DeepCopy().(*AuditLogOption))
}
l.RUnlock()
log.Unlock()
return
}
type AuditLogOption struct {
sync.RWMutex `json:"-"`
DeleteMemberDays string `json:"delete_member_days"`
MembersRemoved string `json:"members_removed"`
ChannelID Snowflake `json:"channel_id"`
Count string `json:"count"`
ID Snowflake `json:"id"`
Type string `json:"type"` // type of overwritten entity ("member" or "role")
RoleName string `json:"role_name"`
}
func (l *AuditLogOption) DeepCopy() (copy interface{}) {
copy = &AuditLogOption{}
l.CopyOverTo(copy)
return
}
func (l *AuditLogOption) CopyOverTo(other interface{}) (err error) {
var ok bool
var log *AuditLogOption
if log, ok = other.(*AuditLogOption); !ok {
err = NewErrorUnsupportedType("given interface{} was not of type *AuditLogOption")
return
}
l.RLock()
log.Lock()
log.DeleteMemberDays = l.DeleteMemberDays
log.MembersRemoved = l.MembersRemoved
log.ChannelID = l.ChannelID
log.Count = l.Count
log.ID = l.ID
log.Type = l.Type
log.RoleName = l.RoleName
l.RUnlock()
log.Unlock()
return
}
type AuditLogChange struct {
sync.RWMutex `json:"-"`
NewValue interface{} `json:"new_value,omitempty"`
OldValue interface{} `json:"old_value,omitempty"`
Key string `json:"key"`
}
func (l *AuditLogChange) DeepCopy() (copy interface{}) {
copy = &AuditLogChange{}
l.CopyOverTo(copy)
return
}
func (l *AuditLogChange) CopyOverTo(other interface{}) (err error) {
var ok bool
var log *AuditLogChange
if log, ok = other.(*AuditLogChange); !ok {
err = NewErrorUnsupportedType("given interface{} was not of type *AuditLogChange")
return
}
l.RLock()
log.Lock()
log.NewValue = l.NewValue
log.OldValue = l.OldValue
log.Key = l.Key
l.RUnlock()
log.Unlock()
return
}