From bcbf834c9545599a4e71bf15235e87f015462be9 Mon Sep 17 00:00:00 2001 From: Gus Caplan Date: Wed, 5 Jul 2017 03:08:13 -0500 Subject: [PATCH] use webhooks cache in guild audit log (#1660) * Update GuildAuditLogs.js * Update GuildAuditLogs.js * Update GuildAuditLogs.js --- src/structures/GuildAuditLogs.js | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/structures/GuildAuditLogs.js b/src/structures/GuildAuditLogs.js index 744121d23..b1f1e9db8 100644 --- a/src/structures/GuildAuditLogs.js +++ b/src/structures/GuildAuditLogs.js @@ -1,5 +1,6 @@ const Collection = require('../util/Collection'); const Snowflake = require('../util/Snowflake'); +const Webhook = require('./Webhook'); const Targets = { ALL: 'ALL', @@ -51,6 +52,17 @@ const Actions = { class GuildAuditLogs { constructor(guild, data) { if (data.users) for (const user of data.users) guild.client.dataManager.newUser(user); + /** + * Cached webhooks + * @type {Collection} + * @private + */ + this.webhooks = new Collection(); + if (data.webhooks) { + for (const hook of data.webhooks) { + this.webhooks.set(hook.id, new Webhook(guild.client, hook)); + } + } /** * The entries for this guild's audit logs @@ -233,11 +245,7 @@ class GuildAuditLogsEntry { } else if ([Targets.USER, Targets.GUILD].includes(targetType)) { this.target = guild.client[`${targetType.toLowerCase()}s`].get(data.target_id); } else if (targetType === Targets.WEBHOOK) { - this.target = guild.fetchWebhooks() - .then(hooks => { - this.target = hooks.find(h => h.id === data.target_id); - return this.target; - }); + this.target = this.webhooks.get(data.target_id); } else if (targetType === Targets.INVITE) { const change = this.changes.find(c => c.key === 'code'); this.target = guild.fetchInvites()