From 30b87bcc6a1152d46c49f1b9836e323500e0dd57 Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Tue, 8 Jun 2021 20:58:24 +0530 Subject: [PATCH 1/3] feat(GuildAuditLogs): make #target a channel for channel related logs --- src/structures/GuildAuditLogs.js | 27 ++++++++++++++++++++++----- 1 file changed, 22 insertions(+), 5 deletions(-) diff --git a/src/structures/GuildAuditLogs.js b/src/structures/GuildAuditLogs.js index 9d15dedca60e..ebc916924156 100644 --- a/src/structures/GuildAuditLogs.js +++ b/src/structures/GuildAuditLogs.js @@ -1,5 +1,6 @@ 'use strict'; +const Channel = require('./Channel'); const Integration = require('./Integration'); const Webhook = require('./Webhook'); const Collection = require('../util/Collection'); @@ -79,7 +80,7 @@ const Targets = { * * INTEGRATION_CREATE: 80 * * INTEGRATION_UPDATE: 81 * * INTEGRATION_DELETE: 82 - * @typedef {?number|string} AuditLogAction + * @typedef {?(number|string)} AuditLogAction */ /** @@ -179,15 +180,17 @@ class GuildAuditLogs { /** * The target of an entry. It can be one of: * * A guild + * * A channel * * A user * * A role - * * An emoji * * An invite * * A webhook + * * An emoji + * * A message * * An integration * * An object with an id key if target was deleted * * An object where the keys represent either the new value or the old value - * @typedef {?Object|Guild|User|Role|GuildEmoji|Invite|Webhook|Integration} AuditLogEntryTarget + * @typedef {?(Object|Guild|Channel|User|Role|Invite|Webhook|GuildEmoji|Message|Integration)} AuditLogEntryTarget */ /** @@ -349,7 +352,7 @@ class GuildAuditLogsEntry { /** * Any extra data from the entry - * @type {?Object|Role|GuildMember} + * @type {?(Object|Role|GuildMember|Channel)} */ this.extra = null; switch (data.action_type) { @@ -480,8 +483,22 @@ class GuildAuditLogsEntry { ), guild, ); + } else if (targetType === Targets.CHANNEL) { + this.target = + guild.channels.cache.get(data.target_id) || + Channel.create( + guild.client, + this.changes.reduce( + (o, c) => { + o[c.key] = c.new || c.old; + return o; + }, + { id: data.target_id }, + ), + guild, + ); } else if (data.target_id) { - this.target = guild[`${targetType.toLowerCase()}s`].cache.get(data.target_id) || { id: data.target_id }; + this.target = guild[`${targetType.toLowerCase()}s`]?.cache.get(data.target_id) || { id: data.target_id }; } } From 284315a873d0ca059bae1fa46e20c9c31c9e566b Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Wed, 9 Jun 2021 02:49:51 +0530 Subject: [PATCH 2/3] refactor(GuildAuditLogs): do not create a new channel --- src/structures/GuildAuditLogs.js | 17 ++++++----------- 1 file changed, 6 insertions(+), 11 deletions(-) diff --git a/src/structures/GuildAuditLogs.js b/src/structures/GuildAuditLogs.js index ebc916924156..16b0b1ebfe2b 100644 --- a/src/structures/GuildAuditLogs.js +++ b/src/structures/GuildAuditLogs.js @@ -1,6 +1,5 @@ 'use strict'; -const Channel = require('./Channel'); const Integration = require('./Integration'); const Webhook = require('./Webhook'); const Collection = require('../util/Collection'); @@ -486,16 +485,12 @@ class GuildAuditLogsEntry { } else if (targetType === Targets.CHANNEL) { this.target = guild.channels.cache.get(data.target_id) || - Channel.create( - guild.client, - this.changes.reduce( - (o, c) => { - o[c.key] = c.new || c.old; - return o; - }, - { id: data.target_id }, - ), - guild, + this.changes.reduce( + (o, c) => { + o[c.key] = c.new || c.old; + return o; + }, + { id: data.target_id }, ); } else if (data.target_id) { this.target = guild[`${targetType.toLowerCase()}s`]?.cache.get(data.target_id) || { id: data.target_id }; From 9446ef9f64cab41bf57f1593aafacbecd13d3845 Mon Sep 17 00:00:00 2001 From: Shubham Parihar Date: Wed, 9 Jun 2021 18:55:58 +0530 Subject: [PATCH 3/3] docs(GuildAuditLogs): remove channel type from jsdoc of #extra Co-authored-by: SpaceEEC --- src/structures/GuildAuditLogs.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/GuildAuditLogs.js b/src/structures/GuildAuditLogs.js index 16b0b1ebfe2b..1b32f59e565b 100644 --- a/src/structures/GuildAuditLogs.js +++ b/src/structures/GuildAuditLogs.js @@ -351,7 +351,7 @@ class GuildAuditLogsEntry { /** * Any extra data from the entry - * @type {?(Object|Role|GuildMember|Channel)} + * @type {?(Object|Role|GuildMember)} */ this.extra = null; switch (data.action_type) {