Skip to content

Commit

Permalink
feat(GuildAuditLogs): make #target a channel for channel related logs (
Browse files Browse the repository at this point in the history
…#5781)

Co-authored-by: SpaceEEC <spaceeec@yahoo.com>
  • Loading branch information
iShibi and SpaceEEC committed Jun 10, 2021
1 parent 3578159 commit eb0291d
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions src/structures/GuildAuditLogs.js
Expand Up @@ -79,7 +79,7 @@ const Targets = {
* * INTEGRATION_CREATE: 80
* * INTEGRATION_UPDATE: 81
* * INTEGRATION_DELETE: 82
* @typedef {?number|string} AuditLogAction
* @typedef {?(number|string)} AuditLogAction
*/

/**
Expand Down Expand Up @@ -179,15 +179,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
*/

/**
Expand Down Expand Up @@ -349,7 +351,7 @@ class GuildAuditLogsEntry {

/**
* Any extra data from the entry
* @type {?Object|Role|GuildMember}
* @type {?(Object|Role|GuildMember)}
*/
this.extra = null;
switch (data.action_type) {
Expand Down Expand Up @@ -480,8 +482,18 @@ class GuildAuditLogsEntry {
),
guild,
);
} else if (targetType === Targets.CHANNEL) {
this.target =
guild.channels.cache.get(data.target_id) ||
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 };
this.target = guild[`${targetType.toLowerCase()}s`]?.cache.get(data.target_id) || { id: data.target_id };
}
}

Expand Down

0 comments on commit eb0291d

Please sign in to comment.