From 2ae5a202874f0f16a54f7c4ada71a8dd58cb7ed9 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Tue, 10 May 2022 21:40:57 +0300 Subject: [PATCH] perm checks --- src/structure/components/observers/GuildLogging.js | 12 +++++++----- src/structure/interfaces/Setting.js | 13 +++++++------ 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/structure/components/observers/GuildLogging.js b/src/structure/components/observers/GuildLogging.js index 4085136..fb58386 100644 --- a/src/structure/components/observers/GuildLogging.js +++ b/src/structure/components/observers/GuildLogging.js @@ -159,7 +159,7 @@ class GuildLogger extends Observer { const logChannel = await wrapper.resolveChannel(messageLog.channel); if (!logChannel) return undefined; - const missing = logChannel.permissionsFor(wrapper.me).missing(['VIEW_CHANNEL', 'EMBED_LINKS', 'SEND_MESSAGES']); + const missing = logChannel.permissionsFor(wrapper.me).missing(['VIEW_CHANNEL', 'EMBED_LINKS', 'SEND_MESSAGES', 'MANAGE_WEBHOOKS']); if (missing.length) return this.client.emit('logError', { guild: wrapper, logger: 'messageLogger', reason: 'MSGLOG_NO_PERMS', params: { missing: missing.join(', ') } }); @@ -334,7 +334,7 @@ class GuildLogger extends Observer { const { ignore, bypass } = chatlogs; if (ignore.includes(channel.id)) return; - const missing = logChannel.permissionsFor(guild.me).missing(['VIEW_CHANNEL', 'EMBED_LINKS', 'SEND_MESSAGES']); + const missing = logChannel.permissionsFor(guild.me).missing(['VIEW_CHANNEL', 'EMBED_LINKS', 'SEND_MESSAGES', 'MANAGE_WEBHOOKS']); if (missing.length) return this.client.emit('logError', { guild: wrapper, logger: 'messageLogger', reason: 'MSGLOG_NO_PERMS', params: { missing: missing.join(', ') } }); @@ -517,7 +517,7 @@ class GuildLogger extends Observer { const logChannel = await wrapper.resolveChannel(_channel); if (!logChannel) return undefined; - const missing = logChannel.permissionsFor(guild.me).missing(['VIEW_CHANNEL', 'EMBED_LINKS', 'SEND_MESSAGES']); + const missing = logChannel.permissionsFor(guild.me).missing(['VIEW_CHANNEL', 'EMBED_LINKS', 'SEND_MESSAGES', 'MANAGE_WEBHOOKS']); if (missing.length) return this.client.emit('logError', { guild: wrapper, logger: 'messageLogger', reason: 'MSGLOG_NO_PERMS', params: { missing: missing.join(', ') } }); @@ -580,7 +580,8 @@ class GuildLogger extends Observer { embed.fields.push({ name: wrapper.format('MSGLOG_EDIT_OLD'), // eslint-disable-next-line no-nested-ternary - value: oldCon.length > 1024 ? oldCon.substring(0, 1021) + '...' : oldCon.length ? oldCon : '\u200b' + value: oldCon.length > 1024 ? + oldCon.substring(0, 1021) + '...' : oldCon.length ? oldCon : '\u200b' }); if (oldCon.length > 1024) embed.fields.push({ name: '\u200b', @@ -589,7 +590,8 @@ class GuildLogger extends Observer { //Edited content embed.fields.push({ name: wrapper.format('MSGLOG_EDIT_NEW'), - value: newCon.length > 1024 ? newCon.substring(0, 1021) + '...' : newCon + // eslint-disable-next-line no-nested-ternary + value: newCon.length > 1024 ? newCon.substring(0, 1021) + '...' : newCon.length ? newCon : '\u200b' }); if (newCon.length > 1024) embed.fields.push({ name: '\u200b', diff --git a/src/structure/interfaces/Setting.js b/src/structure/interfaces/Setting.js index 4c9ad7b..7662132 100644 --- a/src/structure/interfaces/Setting.js +++ b/src/structure/interfaces/Setting.js @@ -198,20 +198,21 @@ class Setting extends Component { } // Helper function for prompting for user response by editing the interaction response - async _prompt(interaction, { message= '', params = {}, embed, index, time = 120 }) { + async _prompt(invoker, { message= '', params = {}, embed, index, time = 120 }) { if (!message.length && !index && !embed) throw new Error('Must declare either message, index or embeds'); - const response = await interaction.promptMessage( - index ? interaction.format(index, params) : message, + const response = await invoker.promptMessage( + index ? invoker.format(index, params) : message, { time, editReply: true, embed } ); - if (!response) return { error: true, message: interaction.format('ERR_TIMEOUT') }; + if (!response) return { error: true, message: invoker.format('ERR_TIMEOUT') }; const content = response.content.toLowerCase(); - await response.delete(); + if(invoker.channel.permissionsFor(invoker.guild.me).has('MANAGE_MESSAGES')) + await response.delete(); if (['cancel', 'abort', 'exit'].includes(content)) return { error: true, - message: interaction.format('ERR_CANCEL') + message: invoker.format('ERR_CANCEL') }; else if (!content.length) return { error: true, index: 'SETTING_NOCONTENT' };