Rework bot function #13

Merged
AstroGD merged 15 commits from feature/12-show-warning-if-logchannel-is-unreachable into dev 2022-11-29 03:07:01 +01:00
Showing only changes of commit f7c878854b - Show all commits

View File

@ -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<void>
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<void>
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();
}