fix: some logging changes to permission validator

This commit is contained in:
Marius Begby committed 2023-08-28 16:31:49 +02:00
1 parent a248452f2c
commit 8e9cb308e9
1 file changed
+11 -5
+11 -5
View File
@@ -3,9 +3,7 @@ import { EmbedBuilder, GuildMember, TextChannel, VoiceChannel } from 'discord.js
import loggerModule from '../../services/logger'; import loggerModule from '../../services/logger';
import { EmbedOptions } from '../../types/configTypes'; import { EmbedOptions } from '../../types/configTypes';
import { import { CannotJoinVoiceOrTalkParams, CannotSendMessageInChannelParams } from '../../types/utilTypes';
CannotJoinVoiceOrTalkParams, CannotSendMessageInChannelParams
} from '../../types/utilTypes';
const embedOptions: EmbedOptions = config.get('embedOptions'); const embedOptions: EmbedOptions = config.get('embedOptions');
export const cannotJoinVoiceOrTalk = async ({ interaction, executionId }: CannotJoinVoiceOrTalkParams) => { export const cannotJoinVoiceOrTalk = async ({ interaction, executionId }: CannotJoinVoiceOrTalkParams) => {
@@ -61,9 +59,13 @@ export const cannotSendMessageInChannel = async ({ interaction, executionId }: C
try { try {
// we can still send ephemeral replies in channels we can't view, so sending message to user instead // we can still send ephemeral replies in channels we can't view, so sending message to user instead
if (!interaction.deferred && !interaction.replied) { if (!interaction.deferred && !interaction.replied) {
logger.debug('Interaction was not deferred or replied to yet. Deferring reply as ephemeral.');
await interaction.deferReply({ ephemeral: true }); await interaction.deferReply({ ephemeral: true });
}
await interaction.editReply({ logger.debug(
'Sending ephemeral message in channel about insufficient permissions to send message in channel.'
);
return await interaction.editReply({
embeds: [ embeds: [
new EmbedBuilder() new EmbedBuilder()
.setDescription( .setDescription(
@@ -72,6 +74,9 @@ export const cannotSendMessageInChannel = async ({ interaction, executionId }: C
.setColor(embedOptions.colors.warning) .setColor(embedOptions.colors.warning)
] ]
}); });
} else {
return Promise.resolve();
}
} catch (error) { } catch (error) {
if (error instanceof Error) { if (error instanceof Error) {
if (error.message == 'The reply to this interaction has already been sent or deferred.') { if (error.message == 'The reply to this interaction has already been sent or deferred.') {
@@ -86,6 +91,7 @@ export const cannotSendMessageInChannel = async ({ interaction, executionId }: C
); );
} }
} else { } else {
logger.debug('Throwing error');
throw error; throw error;
} }
} }