diff --git a/src/commands/instances/moderation/CreateAPIKeyCommand.ts b/src/commands/instances/moderation/CreateAPIKeyCommand.ts index cda78182..de0c7540 100644 --- a/src/commands/instances/moderation/CreateAPIKeyCommand.ts +++ b/src/commands/instances/moderation/CreateAPIKeyCommand.ts @@ -37,16 +37,20 @@ class CreateAPIKeyCommand extends Command { if (!requester) throw new Error(); - const key = await createAPIKey(project, requester.user.username); + const sentDM = await requester.send(`Generating API key...`).catch(() => { + throw new CommandError( + `Failed to send DM to <@${requesterId}>. Please go into Privacy Settings and enable Direct Messages.` + ); + }); - // DM the user back with the new API key - await requester - .send( - `Wise Old Man API key for "${project}":\n\`${key.id}\`\n\n` - ) - .catch(() => { - throw new CommandError(`Failed to send DM to <@${requesterId}>.`); - }); + const key = await createAPIKey(project, requester.user.username).catch(e => { + sentDM.edit('Failed to generate API key.'); + throw e; + }); + + sentDM.edit( + `Wise Old Man API key for "${project}":\n\`${key.id}\`\n\n` + ); // Respond on the WOM discord chat with a success status const response = new MessageEmbed() diff --git a/src/commands/instances/moderation/ResetCompetitionCodeCommand.ts b/src/commands/instances/moderation/ResetCompetitionCodeCommand.ts index 9b729698..b3d89d8c 100644 --- a/src/commands/instances/moderation/ResetCompetitionCodeCommand.ts +++ b/src/commands/instances/moderation/ResetCompetitionCodeCommand.ts @@ -3,8 +3,8 @@ import { resetCompetitionCode } from '../../../services/wiseoldman'; import config from '../../../config'; import { Command, CommandConfig, CommandError, sendModLog } from '../../../utils'; -const DM_MESSAGE = (code: string) => - `Hey! Here's your new verification code: \n\`${code}\`\n\nPlease save it somewhere safe and be mindful of who you choose to share it with.`; +const DM_MESSAGE = (code: string, competitionId: number) => + `Hey! Here's your new verification code for competition ${competitionId}: \n\`${code}\`\n\nPlease save it somewhere safe and be mindful of who you choose to share it with.`; const CHAT_MESSAGE = (userId: string) => `Verification code successfully reset. A DM has been sent to <@${userId}>.`; @@ -45,15 +45,22 @@ class ResetCompetitionCodeCommand extends Command { throw new CommandError("Couldn't find that user."); } + const sentDM = await user.send('Resetting competition code...').catch(() => { + throw new CommandError( + `Failed to send DM to ${user}. Please go into Privacy Settings and enable Direct Messages.` + ); + }); + const { newCode } = await resetCompetitionCode(competitionId).catch(e => { + sentDM.edit('Failed to generate a new verification code.'); if (e.statusCode === 400) throw new CommandError(e.message); - if (e.statusCode === 404) throw new CommandError('Competition not found.'); + if (e.statusCode === 404) throw new CommandError(`Competition '${competitionId}' not found.`); throw e; }); // DM the user back with the new verification code - await user.send(DM_MESSAGE(newCode)); + await sentDM.edit(DM_MESSAGE(newCode, competitionId)); // Respond on the WOM discord chat with a success status const response = new MessageEmbed() diff --git a/src/commands/instances/moderation/ResetGroupCodeCommand.ts b/src/commands/instances/moderation/ResetGroupCodeCommand.ts index 18b3be86..1ab5a081 100644 --- a/src/commands/instances/moderation/ResetGroupCodeCommand.ts +++ b/src/commands/instances/moderation/ResetGroupCodeCommand.ts @@ -3,8 +3,8 @@ import { resetGroupCode } from '../../../services/wiseoldman'; import config from '../../../config'; import { Command, CommandConfig, CommandError, sendModLog } from '../../../utils'; -const DM_MESSAGE = (code: string) => - `Hey! Here's your new verification code: \n\`${code}\`\n\nPlease save it somewhere safe and be mindful of who you choose to share it with.`; +const DM_MESSAGE = (code: string, groupId: number) => + `Hey! Here's your new verification code for group ${groupId}: \n\`${code}\`\n\nPlease save it somewhere safe and be mindful of who you choose to share it with.`; const CHAT_MESSAGE = (userId: string) => `Verification code successfully reset. A DM has been sent to <@${userId}>.`; @@ -45,13 +45,20 @@ class ResetGroupCodeCommand extends Command { throw new CommandError("Couldn't find that user."); } + const sentDM = await user.send('Resetting group code...').catch(() => { + throw new CommandError( + `Failed to send DM to ${user}. Please go into Privacy Settings and enable Direct Messages.` + ); + }); + const { newCode } = await resetGroupCode(groupId).catch(e => { - if (e.statusCode === 404) throw new CommandError('Competition not found.'); + sentDM.edit('Failed to generate a new verification code.'); + if (e.statusCode === 404) throw new CommandError(`Group '${groupId}' not found.`); throw e; }); // DM the user back with the new verification code - await user.send(DM_MESSAGE(newCode)); + await sentDM.edit(DM_MESSAGE(newCode, groupId)); // Respond on the WOM discord chat with a success status const response = new MessageEmbed()