From f7c878854bec1321215787c9f72cdccead5c42ae Mon Sep 17 00:00:00 2001 From: Lukas | AstroGD Date: Tue, 29 Nov 2022 00:22:50 +0100 Subject: [PATCH] Warn if logchannel is misconfigured --- src/commands/showSettings.ts | 25 ++++++++++++++++++++++--- 1 file changed, 22 insertions(+), 3 deletions(-) diff --git a/src/commands/showSettings.ts b/src/commands/showSettings.ts index 2455fb3..dc003f9 100644 --- a/src/commands/showSettings.ts +++ b/src/commands/showSettings.ts @@ -4,7 +4,7 @@ import { getGuildSetting, isPremiumActive } from "../tools/data"; import getDefaultEmbed from "../tools/defaultEmbeds"; import moment from "moment"; import { Color, Emoji } from "../tools/design"; -import { getGuildChannel } from "../tools/discord"; +import { getGuildChannel, getChannelPermission } from "../tools/discord"; const builder = new SlashCommandBuilder(); builder.setName("showsettings"); @@ -35,7 +35,7 @@ async function execute(interaction: ChatInputCommandInteraction): Promise inline: true }, { name: "Logchannel", - value: logChannel && logChannel.isTextBased() ? `<#${logChannel.id}>` : "Not configured", + value: settings.notificationChannelID ? `<#${settings.notificationChannelID}>` : "Not configured", inline: true }, { name: "Words in Blocklist", @@ -49,8 +49,27 @@ async function execute(interaction: ChatInputCommandInteraction): Promise value: "Join the support server at https://go.astrogd.eu/discord" }); + const embeds = []; + embeds.push(embed); + + const invalidLogChannelEmbed = getDefaultEmbed(); + invalidLogChannelEmbed.setColor(Color.WARNING_YELLOW); + invalidLogChannelEmbed.setTitle(`${Emoji.SECURITY_CHALLENGE_FAILED} Logchannel is misconfigured!`); + invalidLogChannelEmbed.setDescription("The bot is unable to read and/or write in the configured logChannel. Please adjust your permissions."); + + if (logChannel && logChannel.isTextBased()) { + const permissions = await getChannelPermission(logChannel); + if (!permissions || !permissions.has(PermissionFlagsBits.ViewChannel) || !permissions.has(PermissionFlagsBits.SendMessages)) { + embeds.push(invalidLogChannelEmbed); + } + } + + if ((!logChannel || !logChannel.isTextBased()) && settings.notificationChannelID) { + embeds.push(invalidLogChannelEmbed); + } + interaction.reply({ - embeds: [embed], + embeds: embeds, ephemeral: true }).catch(); }