From ccb07ad5785a05ea152ddb024c34c98aa37b8595 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Mon, 18 Jul 2022 22:01:06 +0300 Subject: [PATCH] bugfix --- .../en_gb/observers/en_gb_guildLogging.lang | 1 - .../components/observers/GuildLogging.js | 20 +++++++++++-------- 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/localization/en_gb/observers/en_gb_guildLogging.lang b/src/localization/en_gb/observers/en_gb_guildLogging.lang index dc0e185..d4b6d64 100644 --- a/src/localization/en_gb/observers/en_gb_guildLogging.lang +++ b/src/localization/en_gb/observers/en_gb_guildLogging.lang @@ -105,7 +105,6 @@ A thread was {action} in #{channel} [MSGLOG_THREAD_DESC_CREATE] **Thread:** {name} <#{id}> **Owner:** {owner} -**Created by:** {actor} [MSGLOG_THREAD_DESC_ARCHIVE] **Thread:** {name} <#{id}> diff --git a/src/structure/components/observers/GuildLogging.js b/src/structure/components/observers/GuildLogging.js index 87a1d70..f948f20 100644 --- a/src/structure/components/observers/GuildLogging.js +++ b/src/structure/components/observers/GuildLogging.js @@ -108,23 +108,27 @@ class GuildLogger extends Observer { } let actor = null; + const auditLogPerm = guild.me.permissions.has('VIEW_AUDIT_LOG'); if (type === 'CREATE') actor = owner; - else if (type === 'DELETE') { + else if (type === 'DELETE' && auditLogPerm) { const auditLogs = await guild.fetchAuditLogs({ type: 'THREAD_DELETE', limit: 1 }); const log = auditLogs.entries.first(); - if (thread.id !== log.target.id) return; - actor = log.executor; - } else if (['ARCHIVE', 'UNARCHIVE'].includes(type)) { + if (log) { + if (thread.id !== log.target.id) return; + actor = log.executor; + } + } else if (['ARCHIVE', 'UNARCHIVE'].includes(type) && auditLogPerm) { const auditLogs = await guild.fetchAuditLogs({ type: 'THREAD_UPDATE', limit: 1 }); const log = auditLogs.entries.first(); - if (thread.id !== log.target.id) return; - actor = log.executor; + if (log) { + if (thread.id !== log.target.id) return; + actor = log.executor; + } } - if (!actor) return; const embed = { title: guild.format(`MSGLOG_THREAD_TITLE`, { action: guild.format('THREAD_SWITCH', { type }, { code: true }), channel: parent.name }), - description: guild.format(`MSGLOG_THREAD_DESC_${type}`, { owner: owner.tag, actor: actor.tag, name: thread.name, id: thread.id }), + description: guild.format(`MSGLOG_THREAD_DESC_${type}`, { owner: owner.tag, actor: actor?.tag || 'Unknown', name: thread.name, id: thread.id }), footer: { text: guild.format('MSGLOG_THREAD_FOOTER', { ownerId: owner.id, channelId: parent.id, threadId: thread.id }) }, color: CONSTANTS.COLORS[`THREAD_${type}`] };