From faa0abbd82ddecd90fe1d952d6daf596a957490b Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Mon, 2 May 2022 01:39:52 +0300 Subject: [PATCH] bugfix --- src/structure/components/observers/AuditLog.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/structure/components/observers/AuditLog.js b/src/structure/components/observers/AuditLog.js index 933244c..dcf878e 100644 --- a/src/structure/components/observers/AuditLog.js +++ b/src/structure/components/observers/AuditLog.js @@ -83,10 +83,9 @@ class AuditLogObserver extends Observer { // console.log(oldMember.communicationDisabledUntilTimestamp, newMember.communicationDisabledUntilTimestamp); const now = Date.now(); const mute = newMember.communicationDisabledUntilTimestamp !== null; - const auditLogs = await wrapper.fetchAuditLogs({ limit: 1, type: 'MEMBER_UPDATE' }); - if (!auditLogs.entries.size) return undefined; + const entry = await this._fetchFirstEntry(wrapper, newMember.user, 'MEMBER_UPDATE', 'communication_disabled_until'); - const entry = auditLogs.entries.find((e) => e.changes?.some((e) => e.key === 'communication_disabled_until')); + // const entry = auditLogs.entries.find((e) => e.changes?.some((e) => e.key === 'communication_disabled_until')); if (!entry) return undefined; // || newMember.communicationDisabledUntilTimestamp < now let type = null, @@ -147,12 +146,14 @@ class AuditLogObserver extends Observer { }).handle(); } - async _fetchFirstEntry(guild, user, type) { + async _fetchFirstEntry(guild, user, type, subtype = null) { if (!guild.me.permissions.has('VIEW_AUDIT_LOG')) return null; const audit = await guild.fetchAuditLogs({ limit: 1, type }); if (audit.entries.size === 0) return null; - const entry = audit.entries.filter((e) => e?.target?.id === user.id).first(); + const entry = audit.entries.filter((e) => e?.target?.id === user.id && + subtype ? e.changes.some((e) => e.key === subtype) : true).first(); + if (!entry || entry.executor.id === this.client.user.id) return null; if (entry.target.id !== user.id) return null; if (entry.action !== type) return null;