fix(GuildAuditLogs): incorrect webhook reference (#2004)

* fix(GuildAuditLogs): incorrect webhook reference

* i cant trust my linter anymore

* use changes object
This commit is contained in:
Isabella
2017-10-06 17:55:53 -06:00
committed by Crawl
parent f178f9ba6c
commit 8fbae13040

View File

@@ -70,7 +70,7 @@ class GuildAuditLogs {
*/ */
this.entries = new Collection(); this.entries = new Collection();
for (const item of data.audit_log_entries) { for (const item of data.audit_log_entries) {
const entry = new GuildAuditLogsEntry(guild, item); const entry = new GuildAuditLogsEntry(this, guild, item);
this.entries.set(entry.id, entry); this.entries.set(entry.id, entry);
} }
} }
@@ -183,7 +183,7 @@ class GuildAuditLogs {
* Audit logs entry. * Audit logs entry.
*/ */
class GuildAuditLogsEntry { class GuildAuditLogsEntry {
constructor(guild, data) { constructor(logs, guild, data) {
const targetType = GuildAuditLogs.targetType(data.action_type); const targetType = GuildAuditLogs.targetType(data.action_type);
/** /**
* The target type of this entry * The target type of this entry
@@ -281,7 +281,15 @@ class GuildAuditLogsEntry {
} else if ([Targets.USER, Targets.GUILD].includes(targetType)) { } else if ([Targets.USER, Targets.GUILD].includes(targetType)) {
this.target = guild.client[`${targetType.toLowerCase()}s`].get(data.target_id); this.target = guild.client[`${targetType.toLowerCase()}s`].get(data.target_id);
} else if (targetType === Targets.WEBHOOK) { } else if (targetType === Targets.WEBHOOK) {
this.target = this.webhooks.get(data.target_id); this.target = logs.webhooks.get(data.target_id) ||
new Webhook(guild.client,
this.changes.reduce((o, c) => {
o[c.key] = c.new || c.old;
return o;
}, {
id: data.target_id,
guild_id: guild.id,
}));
} else if (targetType === Targets.INVITE) { } else if (targetType === Targets.INVITE) {
if (guild.me.permissions.has('MANAGE_GUILD')) { if (guild.me.permissions.has('MANAGE_GUILD')) {
const change = this.changes.find(c => c.key === 'code'); const change = this.changes.find(c => c.key === 'code');