From 7ca623c3c7873b5a88aee94847c54f791b731de7 Mon Sep 17 00:00:00 2001 From: "Navy.gif" Date: Sat, 16 Dec 2023 20:13:59 +0200 Subject: [PATCH] proper perms checks --- src/client/components/settings/logging/Moderation.ts | 12 +++++++++--- src/client/interfaces/Infraction.ts | 6 +++--- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/client/components/settings/logging/Moderation.ts b/src/client/components/settings/logging/Moderation.ts index 3c75b47..180ab03 100644 --- a/src/client/components/settings/logging/Moderation.ts +++ b/src/client/components/settings/logging/Moderation.ts @@ -89,17 +89,23 @@ class ModerationLog extends Setting async execute (invoker: InvokerWrapper, opts: CommandParams, setting: ModerationSettings) { - const { channel, infractions, anonymous, enabled } = opts, langParams: FormatParams = {}; let index = 'SETTING_SUCCESS_ALT'; - if (anonymous) - setting.anonymous = anonymous.asBool; if (channel) + { + const ch = channel.asChannel; + const perms = ch.permissionsFor(this.client.user!); + const missing = perms?.missing([ 'ViewChannel', 'SendMessages', 'EmbedLinks' ]); + if (!missing || missing.length) + return { error: true, index: 'ERR_BOT_MISSING_PERMISSIONS', params: { missing: missing?.join(', ') || 'Any' } }; setting.channel = channel.asChannel.id; + } if (enabled) setting.enabled = enabled.asBool; + if (anonymous) + setting.anonymous = anonymous.asBool; if (infractions) { diff --git a/src/client/interfaces/Infraction.ts b/src/client/interfaces/Infraction.ts index c0d38a1..05e1fe3 100644 --- a/src/client/interfaces/Infraction.ts +++ b/src/client/interfaces/Infraction.ts @@ -191,14 +191,14 @@ class Infraction { this.#moderationLog = await this.#guild.resolveChannel(moderation.channel, true); const perms = this.#moderationLog?.permissionsFor(this.client.user!); - const missing = perms?.missing([ 'SendMessages', 'EmbedLinks' ]); + const missing = perms?.missing([ 'ViewChannel', 'SendMessages', 'EmbedLinks' ]); if (this.#moderationLog && !missing?.length) { this.#modLogId = this.#moderationLog.id; - this.#dmLogMessage = await this.#moderationLog + this.#modLogMessage = await this.#moderationLog .send({ embeds: [ await this.#embed() ] }) .catch((err) => this.logger.error(err)) ?? null; - this.#modLogMessageId = this.#dmLogMessage?.id || null; + this.#modLogMessageId = this.#modLogMessage?.id || null; } } else