Add a couple possible fixes to the somethingWentWrong function

This commit is contained in:
Ean Milligan 2024-05-21 04:42:12 -04:00
parent 9869a602af
commit acc168673a
3 changed files with 14 additions and 5 deletions

View File

@ -2,7 +2,7 @@ import { ApplicationCommandFlags, Bot, Interaction, InteractionResponseTypes, Me
import { generateLFGButtons } from './utils.ts'; import { generateLFGButtons } from './utils.ts';
import { idSeparator, LfgEmbedIndexes } from '../eventUtils.ts'; import { idSeparator, LfgEmbedIndexes } from '../eventUtils.ts';
import { deleteTokenEarly } from '../tokenCleanup.ts'; import { deleteTokenEarly } from '../tokenCleanup.ts';
import { dmTestMessage, safelyDismissMsg, sendDirectMessage, somethingWentWrong, warnColor } from '../../commandUtils.ts'; import { commonFixes, dmTestMessage, safelyDismissMsg, sendDirectMessage, somethingWentWrong, warnColor } from '../../commandUtils.ts';
import { dbClient } from '../../db/client.ts'; import { dbClient } from '../../db/client.ts';
import { queries } from '../../db/common.ts'; import { queries } from '../../db/common.ts';
import utils from '../../utils.ts'; import utils from '../../utils.ts';
@ -52,7 +52,7 @@ const execute = async (bot: Bot, interaction: Interaction) => {
}], }],
}).catch((e: Error) => utils.commonLoggers.messageSendError('step3-createEvent.ts', 'createEvent', e)); }).catch((e: Error) => utils.commonLoggers.messageSendError('step3-createEvent.ts', 'createEvent', e));
if (!eventMessage) { if (!eventMessage) {
somethingWentWrong(bot, interaction, 'creatingEventSendMessageFinalizeEventStep'); somethingWentWrong(bot, interaction, 'creatingEventSendMessageFinalizeEventStep', commonFixes.CANT_SEND_MESSAGE);
return; return;
} }

View File

@ -106,7 +106,7 @@ ${safelyDismissMsg}`,
timestamp: new Date().getTime(), timestamp: new Date().getTime(),
}); });
}).catch((e: Error) => { }).catch((e: Error) => {
somethingWentWrong(bot, interaction, 'failedToDMOwnerInRequestToJoinEventButton'); somethingWentWrong(bot, interaction, 'failedToDMOwnerInRequestToJoinEventButton', `${config.name} could not message <@${ownerId}>. This likely means <@${ownerId}> has turned off DMs.`);
utils.commonLoggers.messageSendError('joinEvent.ts@dmOwner', 'failed to DM owner for join request', e); utils.commonLoggers.messageSendError('joinEvent.ts@dmOwner', 'failed to DM owner for join request', e);
}); });
} }

View File

@ -27,7 +27,7 @@ export const isLFGChannel = (guildId: bigint, channelId: bigint) => {
}; };
// Tell user to try again or report issue // Tell user to try again or report issue
export const somethingWentWrong = (bot: Bot, interaction: Interaction, errorCode: string) => export const somethingWentWrong = (bot: Bot, interaction: Interaction, errorCode: string, possibleFix = 'No fix provided.') =>
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, { bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {
type: InteractionResponseTypes.ChannelMessageWithSource, type: InteractionResponseTypes.ChannelMessageWithSource,
data: { data: {
@ -35,15 +35,24 @@ export const somethingWentWrong = (bot: Bot, interaction: Interaction, errorCode
embeds: [{ embeds: [{
color: failColor, color: failColor,
title: 'Something went wrong...', title: 'Something went wrong...',
description: `You should not be able to get here. Please try again and if the issue continues, \`/${reportSlashName}\` this issue to the developers with the error code below.`, description:
`You should not be able to get here. If ${config.name} has seen this error before, the developer may have a possible fix for you to try. If one is provided, please attempt it before \`/${reportSlashName}\`ing it. If the issue continues, please \`/${reportSlashName}\` this issue to the developer with the error code below.`,
fields: [{ fields: [{
name: 'Error Code:', name: 'Error Code:',
value: `\`${errorCode}\``, value: `\`${errorCode}\``,
}, {
name: 'Possible Fix:',
value: possibleFix,
}], }],
}], }],
}, },
}).catch((e: Error) => utils.commonLoggers.interactionSendError('commandUtils.ts@somethingWentWrong', interaction, e)); }).catch((e: Error) => utils.commonLoggers.interactionSendError('commandUtils.ts@somethingWentWrong', interaction, e));
// Possible fixes for the user to try before reporting.
export const commonFixes = {
CANT_SEND_MESSAGE: `Please verify ${config.name} has permission to send messages in this channel.`,
};
// Smack the user for trying to modify an event that isn't theirs // Smack the user for trying to modify an event that isn't theirs
export const stopThat = (bot: Bot, interaction: Interaction, stopWhat: string) => export const stopThat = (bot: Bot, interaction: Interaction, stopWhat: string) =>
bot.helpers.sendInteractionResponse(interaction.id, interaction.token, { bot.helpers.sendInteractionResponse(interaction.id, interaction.token, {