discord.js-selfv13 13.0.1

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of discord.js-selfv13 might be problematic. Click here for more details.

Files changed (188) hide show
  1. package/.dccache +1 -0
  2. package/LICENSE +190 -0
  3. package/README.md +87 -0
  4. package/browser.js +9 -0
  5. package/deploy/deploy-key.enc +0 -0
  6. package/deploy/deploy.sh +90 -0
  7. package/deploy/test.sh +34 -0
  8. package/docs/README.md +1 -0
  9. package/docs/examples/attachments.md +163 -0
  10. package/docs/examples/avatars.js +29 -0
  11. package/docs/examples/embed.js +38 -0
  12. package/docs/examples/greeting.js +30 -0
  13. package/docs/examples/moderation.md +145 -0
  14. package/docs/examples/ping.js +29 -0
  15. package/docs/examples/webhook.js +12 -0
  16. package/docs/general/faq.md +23 -0
  17. package/docs/general/updating.md +181 -0
  18. package/docs/general/welcome.md +95 -0
  19. package/docs/index.yml +30 -0
  20. package/docs/logo.svg +19 -0
  21. package/docs/topics/voice.md +113 -0
  22. package/docs/topics/web.md +38 -0
  23. package/package.json +147 -0
  24. package/src/client/Client.js +564 -0
  25. package/src/client/ClientDataManager.js +150 -0
  26. package/src/client/ClientDataResolver.js +376 -0
  27. package/src/client/ClientManager.js +74 -0
  28. package/src/client/WebhookClient.js +118 -0
  29. package/src/client/actions/Action.js +23 -0
  30. package/src/client/actions/ActionsManager.js +40 -0
  31. package/src/client/actions/ChannelCreate.js +11 -0
  32. package/src/client/actions/ChannelDelete.js +30 -0
  33. package/src/client/actions/ChannelUpdate.js +74 -0
  34. package/src/client/actions/GuildBanRemove.js +13 -0
  35. package/src/client/actions/GuildChannelsPositionUpdate.js +19 -0
  36. package/src/client/actions/GuildDelete.js +57 -0
  37. package/src/client/actions/GuildEmojiCreate.js +17 -0
  38. package/src/client/actions/GuildEmojiDelete.js +18 -0
  39. package/src/client/actions/GuildEmojiUpdate.js +17 -0
  40. package/src/client/actions/GuildEmojisUpdate.js +38 -0
  41. package/src/client/actions/GuildMemberGet.js +10 -0
  42. package/src/client/actions/GuildMemberRemove.js +41 -0
  43. package/src/client/actions/GuildRoleCreate.js +26 -0
  44. package/src/client/actions/GuildRoleDelete.js +42 -0
  45. package/src/client/actions/GuildRoleUpdate.js +41 -0
  46. package/src/client/actions/GuildRolesPositionUpdate.js +19 -0
  47. package/src/client/actions/GuildSync.js +29 -0
  48. package/src/client/actions/GuildUpdate.js +34 -0
  49. package/src/client/actions/MessageCreate.js +53 -0
  50. package/src/client/actions/MessageDelete.js +35 -0
  51. package/src/client/actions/MessageDeleteBulk.js +26 -0
  52. package/src/client/actions/MessageReactionAdd.js +37 -0
  53. package/src/client/actions/MessageReactionRemove.js +37 -0
  54. package/src/client/actions/MessageReactionRemoveAll.js +25 -0
  55. package/src/client/actions/MessageUpdate.js +40 -0
  56. package/src/client/actions/Ready.js +1 -0
  57. package/src/client/actions/Ready.js.bak +65 -0
  58. package/src/client/actions/UserGet.js +11 -0
  59. package/src/client/actions/UserNoteUpdate.js +30 -0
  60. package/src/client/actions/UserUpdate.js +33 -0
  61. package/src/client/rest/APIRequest.js +56 -0
  62. package/src/client/rest/DiscordAPIError.js +60 -0
  63. package/src/client/rest/RESTManager.js +58 -0
  64. package/src/client/rest/RESTMethods.js +1006 -0
  65. package/src/client/rest/RequestHandlers/Burst.js +90 -0
  66. package/src/client/rest/RequestHandlers/RequestHandler.js +54 -0
  67. package/src/client/rest/RequestHandlers/Sequential.js +132 -0
  68. package/src/client/rest/UserAgentManager.js +25 -0
  69. package/src/client/voice/ClientVoiceManager.js +81 -0
  70. package/src/client/voice/VoiceBroadcast.js +366 -0
  71. package/src/client/voice/VoiceConnection.js +530 -0
  72. package/src/client/voice/VoiceUDPClient.js +127 -0
  73. package/src/client/voice/VoiceWebSocket.js +246 -0
  74. package/src/client/voice/dispatcher/StreamDispatcher.js +331 -0
  75. package/src/client/voice/opus/BaseOpusEngine.js +60 -0
  76. package/src/client/voice/opus/NodeOpusEngine.js +40 -0
  77. package/src/client/voice/opus/OpusEngineList.js +28 -0
  78. package/src/client/voice/opus/OpusScriptEngine.js +45 -0
  79. package/src/client/voice/player/AudioPlayer.js +170 -0
  80. package/src/client/voice/receiver/VoiceReadable.js +17 -0
  81. package/src/client/voice/receiver/VoiceReceiver.js +219 -0
  82. package/src/client/voice/util/SecretKey.js +16 -0
  83. package/src/client/voice/util/Secretbox.js +33 -0
  84. package/src/client/voice/util/VolumeInterface.js +86 -0
  85. package/src/client/websocket/WebSocketConnection.js +506 -0
  86. package/src/client/websocket/WebSocketManager.js +90 -0
  87. package/src/client/websocket/packets/WebSocketPacketManager.js +110 -0
  88. package/src/client/websocket/packets/handlers/AbstractHandler.js +11 -0
  89. package/src/client/websocket/packets/handlers/ChannelCreate.js +17 -0
  90. package/src/client/websocket/packets/handlers/ChannelDelete.js +20 -0
  91. package/src/client/websocket/packets/handlers/ChannelPinsUpdate.js +37 -0
  92. package/src/client/websocket/packets/handlers/ChannelUpdate.js +11 -0
  93. package/src/client/websocket/packets/handlers/GuildBanAdd.js +23 -0
  94. package/src/client/websocket/packets/handlers/GuildBanRemove.js +20 -0
  95. package/src/client/websocket/packets/handlers/GuildCreate.js +22 -0
  96. package/src/client/websocket/packets/handlers/GuildDelete.js +19 -0
  97. package/src/client/websocket/packets/handlers/GuildEmojisUpdate.js +11 -0
  98. package/src/client/websocket/packets/handlers/GuildIntegrationsUpdate.js +19 -0
  99. package/src/client/websocket/packets/handlers/GuildMemberAdd.js +17 -0
  100. package/src/client/websocket/packets/handlers/GuildMemberRemove.js +13 -0
  101. package/src/client/websocket/packets/handlers/GuildMemberUpdate.js +18 -0
  102. package/src/client/websocket/packets/handlers/GuildMembersChunk.js +33 -0
  103. package/src/client/websocket/packets/handlers/GuildRoleCreate.js +11 -0
  104. package/src/client/websocket/packets/handlers/GuildRoleDelete.js +11 -0
  105. package/src/client/websocket/packets/handlers/GuildRoleUpdate.js +11 -0
  106. package/src/client/websocket/packets/handlers/GuildSync.js +11 -0
  107. package/src/client/websocket/packets/handlers/GuildUpdate.js +11 -0
  108. package/src/client/websocket/packets/handlers/MessageCreate.js +19 -0
  109. package/src/client/websocket/packets/handlers/MessageDelete.js +19 -0
  110. package/src/client/websocket/packets/handlers/MessageDeleteBulk.js +17 -0
  111. package/src/client/websocket/packets/handlers/MessageReactionAdd.js +11 -0
  112. package/src/client/websocket/packets/handlers/MessageReactionRemove.js +11 -0
  113. package/src/client/websocket/packets/handlers/MessageReactionRemoveAll.js +11 -0
  114. package/src/client/websocket/packets/handlers/MessageUpdate.js +11 -0
  115. package/src/client/websocket/packets/handlers/PresenceUpdate.js +76 -0
  116. package/src/client/websocket/packets/handlers/Ready.js +83 -0
  117. package/src/client/websocket/packets/handlers/RelationshipAdd.js +19 -0
  118. package/src/client/websocket/packets/handlers/RelationshipRemove.js +19 -0
  119. package/src/client/websocket/packets/handlers/Resumed.js +28 -0
  120. package/src/client/websocket/packets/handlers/TypingStart.js +68 -0
  121. package/src/client/websocket/packets/handlers/UserGuildSettingsUpdate.js +21 -0
  122. package/src/client/websocket/packets/handlers/UserNoteUpdate.js +12 -0
  123. package/src/client/websocket/packets/handlers/UserSettingsUpdate.js +18 -0
  124. package/src/client/websocket/packets/handlers/UserUpdate.js +11 -0
  125. package/src/client/websocket/packets/handlers/VoiceServerUpdate.js +19 -0
  126. package/src/client/websocket/packets/handlers/VoiceStateUpdate.js +52 -0
  127. package/src/client/websocket/packets/handlers/WebhooksUpdate.js +19 -0
  128. package/src/index.js +66 -0
  129. package/src/sharding/Shard.js +282 -0
  130. package/src/sharding/ShardClientUtil.js +146 -0
  131. package/src/sharding/ShardingManager.js +220 -0
  132. package/src/structures/Attachment.js +75 -0
  133. package/src/structures/CategoryChannel.js +22 -0
  134. package/src/structures/Channel.js +78 -0
  135. package/src/structures/ClientUser.js +447 -0
  136. package/src/structures/ClientUserChannelOverride.js +30 -0
  137. package/src/structures/ClientUserGuildSettings.js +60 -0
  138. package/src/structures/ClientUserSettings.js +80 -0
  139. package/src/structures/DMChannel.js +76 -0
  140. package/src/structures/Emoji.js +256 -0
  141. package/src/structures/GroupDMChannel.js +246 -0
  142. package/src/structures/Guild.js +1461 -0
  143. package/src/structures/GuildAuditLogs.js +371 -0
  144. package/src/structures/GuildChannel.js +537 -0
  145. package/src/structures/GuildMember.js +613 -0
  146. package/src/structures/Invite.js +164 -0
  147. package/src/structures/Message.js +605 -0
  148. package/src/structures/MessageAttachment.js +68 -0
  149. package/src/structures/MessageCollector.js +100 -0
  150. package/src/structures/MessageEmbed.js +386 -0
  151. package/src/structures/MessageMentions.js +144 -0
  152. package/src/structures/MessageReaction.js +96 -0
  153. package/src/structures/NewsChannel.js +24 -0
  154. package/src/structures/OAuth2Application.js +148 -0
  155. package/src/structures/PartialGuild.js +51 -0
  156. package/src/structures/PartialGuildChannel.js +44 -0
  157. package/src/structures/PermissionOverwrites.js +69 -0
  158. package/src/structures/Presence.js +241 -0
  159. package/src/structures/ReactionCollector.js +85 -0
  160. package/src/structures/ReactionEmoji.js +49 -0
  161. package/src/structures/RichEmbed.js +295 -0
  162. package/src/structures/Role.js +376 -0
  163. package/src/structures/StoreChannel.js +25 -0
  164. package/src/structures/TextChannel.js +154 -0
  165. package/src/structures/User.js +329 -0
  166. package/src/structures/UserConnection.js +48 -0
  167. package/src/structures/UserProfile.js +62 -0
  168. package/src/structures/VoiceChannel.js +146 -0
  169. package/src/structures/VoiceRegion.js +50 -0
  170. package/src/structures/Webhook.js +304 -0
  171. package/src/structures/interfaces/Collector.js +179 -0
  172. package/src/structures/interfaces/TextBasedChannel.js +635 -0
  173. package/src/structures/shared/resolvePermissions.js +26 -0
  174. package/src/util/Collection.js +532 -0
  175. package/src/util/Constants.js +845 -0
  176. package/src/util/Permissions.js +306 -0
  177. package/src/util/Snowflake.js +82 -0
  178. package/src/util/Util.js +221 -0
  179. package/test/random.js +207 -0
  180. package/test/shard.js +31 -0
  181. package/test/sharder.js +7 -0
  182. package/test/voice.js +78 -0
  183. package/test/webpack.html +31 -0
  184. package/tsconfig.json +13 -0
  185. package/tslint.json +62 -0
  186. package/typings/discord.js-test.ts +69 -0
  187. package/typings/index.d.ts +2190 -0
  188. package/webpack.config.js +62 -0
@@ -0,0 +1,371 @@
1
+ const Collection = require('../util/Collection');
2
+ const Snowflake = require('../util/Snowflake');
3
+ const Webhook = require('./Webhook');
4
+ const Invite = require('./Invite');
5
+
6
+ /**
7
+ * The target type of an entry, e.g. `GUILD`. Here are the available types:
8
+ * * GUILD
9
+ * * CHANNEL
10
+ * * USER
11
+ * * ROLE
12
+ * * INVITE
13
+ * * WEBHOOK
14
+ * * EMOJI
15
+ * * MESSAGE
16
+ * @typedef {string} AuditLogTargetType
17
+ */
18
+
19
+ /**
20
+ * Key mirror of all available audit log targets.
21
+ * @name GuildAuditLogs.Targets
22
+ * @type {AuditLogTargetType}
23
+ */
24
+ const Targets = {
25
+ ALL: 'ALL',
26
+ GUILD: 'GUILD',
27
+ CHANNEL: 'CHANNEL',
28
+ USER: 'USER',
29
+ ROLE: 'ROLE',
30
+ INVITE: 'INVITE',
31
+ WEBHOOK: 'WEBHOOK',
32
+ EMOJI: 'EMOJI',
33
+ MESSAGE: 'MESSAGE',
34
+ };
35
+
36
+ /**
37
+ * The action of an entry. Here are the available actions:
38
+ * * ALL: null
39
+ * * GUILD_UPDATE: 1
40
+ * * CHANNEL_CREATE: 10
41
+ * * CHANNEL_UPDATE: 11
42
+ * * CHANNEL_DELETE: 12
43
+ * * CHANNEL_OVERWRITE_CREATE: 13
44
+ * * CHANNEL_OVERWRITE_UPDATE: 14
45
+ * * CHANNEL_OVERWRITE_DELETE: 15
46
+ * * MEMBER_KICK: 20
47
+ * * MEMBER_PRUNE: 21
48
+ * * MEMBER_BAN_ADD: 22
49
+ * * MEMBER_BAN_REMOVE: 23
50
+ * * MEMBER_UPDATE: 24
51
+ * * MEMBER_ROLE_UPDATE: 25
52
+ * * ROLE_CREATE: 30
53
+ * * ROLE_UPDATE: 31
54
+ * * ROLE_DELETE: 32
55
+ * * INVITE_CREATE: 40
56
+ * * INVITE_UPDATE: 41
57
+ * * INVITE_DELETE: 42
58
+ * * WEBHOOK_CREATE: 50
59
+ * * WEBHOOK_UPDATE: 51
60
+ * * WEBHOOK_DELETE: 52
61
+ * * EMOJI_CREATE: 60
62
+ * * EMOJI_UPDATE: 61
63
+ * * EMOJI_DELETE: 62
64
+ * * MESSAGE_DELETE: 72
65
+ * @typedef {?number|string} AuditLogAction
66
+ */
67
+
68
+ /**
69
+ * All available actions keyed under their names to their numeric values.
70
+ * @name GuildAuditLogs.Actions
71
+ * @type {AuditLogAction}
72
+ */
73
+ const Actions = {
74
+ ALL: null,
75
+ GUILD_UPDATE: 1,
76
+ CHANNEL_CREATE: 10,
77
+ CHANNEL_UPDATE: 11,
78
+ CHANNEL_DELETE: 12,
79
+ CHANNEL_OVERWRITE_CREATE: 13,
80
+ CHANNEL_OVERWRITE_UPDATE: 14,
81
+ CHANNEL_OVERWRITE_DELETE: 15,
82
+ MEMBER_KICK: 20,
83
+ MEMBER_PRUNE: 21,
84
+ MEMBER_BAN_ADD: 22,
85
+ MEMBER_BAN_REMOVE: 23,
86
+ MEMBER_UPDATE: 24,
87
+ MEMBER_ROLE_UPDATE: 25,
88
+ ROLE_CREATE: 30,
89
+ ROLE_UPDATE: 31,
90
+ ROLE_DELETE: 32,
91
+ INVITE_CREATE: 40,
92
+ INVITE_UPDATE: 41,
93
+ INVITE_DELETE: 42,
94
+ WEBHOOK_CREATE: 50,
95
+ WEBHOOK_UPDATE: 51,
96
+ WEBHOOK_DELETE: 52,
97
+ EMOJI_CREATE: 60,
98
+ EMOJI_UPDATE: 61,
99
+ EMOJI_DELETE: 62,
100
+ MESSAGE_DELETE: 72,
101
+ };
102
+
103
+
104
+ /**
105
+ * Audit logs entries are held in this class.
106
+ */
107
+ class GuildAuditLogs {
108
+ constructor(guild, data) {
109
+ if (data.users) for (const user of data.users) guild.client.dataManager.newUser(user);
110
+
111
+ /**
112
+ * Cached webhooks
113
+ * @type {Collection<Snowflake, Webhook>}
114
+ * @private
115
+ */
116
+ this.webhooks = new Collection();
117
+ if (data.webhooks) {
118
+ for (const hook of data.webhooks) {
119
+ this.webhooks.set(hook.id, new Webhook(guild.client, hook));
120
+ }
121
+ }
122
+
123
+ /**
124
+ * The entries for this guild's audit logs
125
+ * @type {Collection<Snowflake, GuildAuditLogsEntry>}
126
+ */
127
+ this.entries = new Collection();
128
+ for (const item of data.audit_log_entries) {
129
+ const entry = new GuildAuditLogsEntry(this, guild, item);
130
+ this.entries.set(entry.id, entry);
131
+ }
132
+ }
133
+
134
+ /**
135
+ * Handles possible promises for entry targets.
136
+ * @returns {Promise<GuildAuditLogs>}
137
+ */
138
+ static build(...args) {
139
+ const logs = new GuildAuditLogs(...args);
140
+ return Promise.all(logs.entries.map(e => e.target)).then(() => logs);
141
+ }
142
+
143
+ /**
144
+ * The target of an entry. It can be one of:
145
+ * * A guild
146
+ * * A user
147
+ * * A role
148
+ * * An emoji
149
+ * * An invite
150
+ * * A webhook
151
+ * * An object where the keys represent either the new value or the old value
152
+ * @typedef {?Object|Guild|User|Role|Emoji|Invite|Webhook} AuditLogEntryTarget
153
+ */
154
+
155
+ /**
156
+ * Find target type from entry action.
157
+ * @param {number} target The action target
158
+ * @returns {?string}
159
+ */
160
+ static targetType(target) {
161
+ if (target < 10) return Targets.GUILD;
162
+ if (target < 20) return Targets.CHANNEL;
163
+ if (target < 30) return Targets.USER;
164
+ if (target < 40) return Targets.ROLE;
165
+ if (target < 50) return Targets.INVITE;
166
+ if (target < 60) return Targets.WEBHOOK;
167
+ if (target < 70) return Targets.EMOJI;
168
+ if (target < 80) return Targets.MESSAGE;
169
+ return null;
170
+ }
171
+
172
+ /**
173
+ * The action type of an entry, e.g. `CREATE`. Here are the available types:
174
+ * * CREATE
175
+ * * DELETE
176
+ * * UPDATE
177
+ * * ALL
178
+ * @typedef {string} AuditLogActionType
179
+ */
180
+
181
+
182
+ /**
183
+ * Finds the action type from the entry action.
184
+ * @param {AuditLogAction} action The action target
185
+ * @returns {AuditLogActionType}
186
+ */
187
+ static actionType(action) {
188
+ if ([
189
+ Actions.CHANNEL_CREATE,
190
+ Actions.CHANNEL_OVERWRITE_CREATE,
191
+ Actions.MEMBER_BAN_REMOVE,
192
+ Actions.ROLE_CREATE,
193
+ Actions.INVITE_CREATE,
194
+ Actions.WEBHOOK_CREATE,
195
+ Actions.EMOJI_CREATE,
196
+ ].includes(action)) return 'CREATE';
197
+
198
+ if ([
199
+ Actions.CHANNEL_DELETE,
200
+ Actions.CHANNEL_OVERWRITE_DELETE,
201
+ Actions.MEMBER_KICK,
202
+ Actions.MEMBER_PRUNE,
203
+ Actions.MEMBER_BAN_ADD,
204
+ Actions.ROLE_DELETE,
205
+ Actions.INVITE_DELETE,
206
+ Actions.WEBHOOK_DELETE,
207
+ Actions.EMOJI_DELETE,
208
+ Actions.MESSAGE_DELETE,
209
+ ].includes(action)) return 'DELETE';
210
+
211
+ if ([
212
+ Actions.GUILD_UPDATE,
213
+ Actions.CHANNEL_UPDATE,
214
+ Actions.CHANNEL_OVERWRITE_UPDATE,
215
+ Actions.MEMBER_UPDATE,
216
+ Actions.MEMBER_ROLE_UPDATE,
217
+ Actions.ROLE_UPDATE,
218
+ Actions.INVITE_UPDATE,
219
+ Actions.WEBHOOK_UPDATE,
220
+ Actions.EMOJI_UPDATE,
221
+ ].includes(action)) return 'UPDATE';
222
+
223
+ return 'ALL';
224
+ }
225
+ }
226
+
227
+ /**
228
+ * Audit logs entry.
229
+ */
230
+ class GuildAuditLogsEntry {
231
+ constructor(logs, guild, data) {
232
+ const targetType = GuildAuditLogs.targetType(data.action_type);
233
+ /**
234
+ * The target type of this entry
235
+ * @type {AuditLogTargetType}
236
+ */
237
+ this.targetType = targetType;
238
+
239
+ /**
240
+ * The action type of this entry
241
+ * @type {AuditLogActionType}
242
+ */
243
+ this.actionType = GuildAuditLogs.actionType(data.action_type);
244
+
245
+ /**
246
+ * Specific action type of this entry in its string representation
247
+ * @type {AuditLogAction}
248
+ */
249
+ this.action = Object.keys(Actions).find(k => Actions[k] === data.action_type);
250
+
251
+ /**
252
+ * The reason of this entry
253
+ * @type {?string}
254
+ */
255
+ this.reason = data.reason || null;
256
+
257
+ /**
258
+ * The user that executed this entry
259
+ * @type {User}
260
+ */
261
+ this.executor = guild.client.users.get(data.user_id);
262
+
263
+ /**
264
+ * An entry in the audit log representing a specific change.
265
+ * @typedef {object} AuditLogChange
266
+ * @property {string} key The property that was changed, e.g. `nick` for nickname changes
267
+ * @property {*} [old] The old value of the change, e.g. for nicknames, the old nickname
268
+ * @property {*} [new] The new value of the change, e.g. for nicknames, the new nickname
269
+ */
270
+
271
+ /**
272
+ * Specific property changes
273
+ * @type {AuditLogChange[]}
274
+ */
275
+ this.changes = data.changes ? data.changes.map(c => ({ key: c.key, old: c.old_value, new: c.new_value })) : null;
276
+
277
+ /**
278
+ * The ID of this entry
279
+ * @type {Snowflake}
280
+ */
281
+ this.id = data.id;
282
+
283
+ /**
284
+ * Any extra data from the entry
285
+ * @type {?Object|Role|GuildMember}
286
+ */
287
+ this.extra = null;
288
+ if (data.options) {
289
+ if (data.action_type === Actions.MEMBER_PRUNE) {
290
+ this.extra = {
291
+ removed: data.options.members_removed,
292
+ days: data.options.delete_member_days,
293
+ };
294
+ } else if (data.action_type === Actions.MESSAGE_DELETE) {
295
+ this.extra = {
296
+ count: data.options.count,
297
+ channel: guild.channels.get(data.options.channel_id),
298
+ };
299
+ } else {
300
+ switch (data.options.type) {
301
+ case 'member':
302
+ this.extra = guild.members.get(data.options.id);
303
+ if (!this.extra) this.extra = { id: data.options.id };
304
+ break;
305
+ case 'role':
306
+ this.extra = guild.roles.get(data.options.id);
307
+ if (!this.extra) this.extra = { id: data.options.id, name: data.options.role_name };
308
+ break;
309
+ default:
310
+ break;
311
+ }
312
+ }
313
+ }
314
+
315
+ if ([Targets.USER, Targets.GUILD].includes(targetType)) {
316
+ /**
317
+ * The target of this entry
318
+ * @type {AuditLogEntryTarget}
319
+ */
320
+ this.target = guild.client[`${targetType.toLowerCase()}s`].get(data.target_id);
321
+ } else if (targetType === Targets.WEBHOOK) {
322
+ this.target = logs.webhooks.get(data.target_id) ||
323
+ new Webhook(guild.client,
324
+ this.changes.reduce((o, c) => {
325
+ o[c.key] = c.new || c.old;
326
+ return o;
327
+ }, {
328
+ id: data.target_id,
329
+ guild_id: guild.id,
330
+ }));
331
+ } else if (targetType === Targets.INVITE) {
332
+ const changes = this.changes.reduce((o, c) => {
333
+ o[c.key] = c.new || c.old;
334
+ return o;
335
+ }, {
336
+ id: data.target_id,
337
+ guild,
338
+ });
339
+ changes.channel = { id: changes.channel_id };
340
+ this.target = new Invite(guild.client, changes);
341
+ } else if (targetType === Targets.MESSAGE) {
342
+ this.target = guild.client.users.get(data.target_id);
343
+ } else {
344
+ this.target = guild[`${targetType.toLowerCase()}s`].get(data.target_id);
345
+ }
346
+ }
347
+
348
+ /**
349
+ * The timestamp this entry was created at
350
+ * @type {number}
351
+ * @readonly
352
+ */
353
+ get createdTimestamp() {
354
+ return Snowflake.deconstruct(this.id).timestamp;
355
+ }
356
+
357
+ /**
358
+ * The time this entry was created
359
+ * @type {Date}
360
+ * @readonly
361
+ */
362
+ get createdAt() {
363
+ return new Date(this.createdTimestamp);
364
+ }
365
+ }
366
+
367
+ GuildAuditLogs.Actions = Actions;
368
+ GuildAuditLogs.Targets = Targets;
369
+ GuildAuditLogs.Entry = GuildAuditLogsEntry;
370
+
371
+ module.exports = GuildAuditLogs;