From 2db1d85a24c8a4d7e519d527e5bdb8fa469c4c85 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Fri, 27 May 2022 19:14:44 -0400 Subject: fix: replace '{error}' in retry prompts --- src/commands/fun/minesweeper.ts | 2 +- src/commands/leveling/levelRoles.ts | 56 ++++++++++--------------- src/lib/extensions/discord-akairo/BushClient.ts | 34 +++++++++++---- 3 files changed, 49 insertions(+), 43 deletions(-) diff --git a/src/commands/fun/minesweeper.ts b/src/commands/fun/minesweeper.ts index 41daa8e..72551e9 100644 --- a/src/commands/fun/minesweeper.ts +++ b/src/commands/fun/minesweeper.ts @@ -56,7 +56,7 @@ export default class MinesweeperCommand extends BushCommand { id: 'do_not_reveal_first_cell', description: 'Whether to not reveal the first cell automatically.', match: 'flag', - flag: '--doNotRevealFirstCell', + flag: ['--doNotRevealFirstCell', 'do_not_reveal_first_cell'], prompt: 'Would you like to not automatically reveal the first cell?', slashType: ApplicationCommandOptionType.Boolean, optional: true diff --git a/src/commands/leveling/levelRoles.ts b/src/commands/leveling/levelRoles.ts index 893e602..3d95933 100644 --- a/src/commands/leveling/levelRoles.ts +++ b/src/commands/leveling/levelRoles.ts @@ -46,34 +46,20 @@ export default class LevelRolesCommand extends BushCommand { assert(message.member); if (!(await message.guild.hasFeature('leveling'))) { - return await message.util.reply( - `${util.emojis.error} This command can only be run in servers with the leveling feature enabled.` - ); + return await reply(`${util.emojis.error} This command can only be run in servers with the leveling feature enabled.`); } - if (args.level < 1) return await message.util.reply(`${util.emojis.error} You cannot set a level role less that 1.`); + if (args.level < 1) return await reply(`${util.emojis.error} You cannot set a level role less that 1.`); if (args.role) { if (args.role.managed) - return await message.util.reply({ - content: `${util.emojis.error} You cannot set <@${args.role.id}> as a level role since it is managed.`, - allowedMentions: AllowedMentions.none() - }); + return await reply(`${util.emojis.error} You cannot set <@${args.role.id}> as a level role since it is managed.`); else if (args.role.id === message.guild.id) - return await message.util.reply({ - content: `${util.emojis.error} You cannot set the @everyone role as a level role.`, - allowedMentions: AllowedMentions.none() - }); + return await reply(`${util.emojis.error} You cannot set the @everyone role as a level role.`); else if (args.role.comparePositionTo(message.member.roles.highest) >= 0) - return await message.util.reply({ - content: `${util.emojis.error} <@${args.role.id}> is higher or equal to your highest role.`, - allowedMentions: AllowedMentions.none() - }); + return await reply(`${util.emojis.error} <@${args.role.id}> is higher or equal to your highest role.`); else if (args.role.comparePositionTo(message.guild.members.me!.roles.highest) >= 0) - return await message.util.reply({ - content: `${util.emojis.error} <@${args.role.id}> is higher or equal to my highest role.`, - allowedMentions: AllowedMentions.none() - }); + return await reply(`${util.emojis.error} <@${args.role.id}> is higher or equal to my highest role.`); } const oldRoles = Object.freeze(await message.guild.getSetting('levelRoles')); @@ -88,25 +74,25 @@ export default class LevelRolesCommand extends BushCommand { const success = await message.guild.setSetting('levelRoles', newRoles, message.member).catch(() => false); - if (!success) return await message.util.reply(`${util.emojis.error} An error occurred while setting the level roles.`); + if (!success) return await reply(`${util.emojis.error} An error occurred while setting the level roles.`); if (!oldRoles[args.level] && newRoles[args.level]) { - return await message.util.reply({ - content: `${util.emojis.success} The level role for **${args.level}** is now <@&${newRoles[args.level]}>.`, - allowedMentions: AllowedMentions.none() - }); + return await reply(`${util.emojis.success} The level role for **${args.level}** is now <@&${newRoles[args.level]}>.`); } else if (oldRoles[args.level] && !newRoles[args.level]) { - return await message.util.reply({ - content: `${util.emojis.success} The level role for **${args.level}** was <@&${ - oldRoles[args.level] - }> but is now disabled.`, - allowedMentions: AllowedMentions.none() - }); + return await reply( + `${util.emojis.success} The level role for **${args.level}** was <@&${oldRoles[args.level]}> but is now disabled.` + ); } else if (oldRoles[args.level] && newRoles[args.level]) { - return await message.util.reply({ - content: `${util.emojis.success} The level role for **${args.level}** has been updated from <@&${ - oldRoles[args.level] - }> to <@&${newRoles[args.level]}>.`, + return await reply( + `${util.emojis.success} The level role for **${args.level}** has been updated from <@&${oldRoles[args.level]}> to <@&${ + newRoles[args.level] + }>.` + ); + } + + function reply(str: string) { + return message.util.reply({ + content: str, allowedMentions: AllowedMentions.none() }); } diff --git a/src/lib/extensions/discord-akairo/BushClient.ts b/src/lib/extensions/discord-akairo/BushClient.ts index 4df751d..c56c9ad 100644 --- a/src/lib/extensions/discord-akairo/BushClient.ts +++ b/src/lib/extensions/discord-akairo/BushClient.ts @@ -22,7 +22,13 @@ import type { } from '#lib'; import { patch, type PatchedElements } from '@notenoughupdates/events-intercept'; import * as Sentry from '@sentry/node'; -import { AkairoClient, ContextMenuCommandHandler, PromptContentModifier, version as akairoVersion } from 'discord-akairo'; +import { + AkairoClient, + ArgumentPromptData, + ContextMenuCommandHandler, + OtherwiseContentSupplier, + version as akairoVersion +} from 'discord-akairo'; import { GatewayIntentBits } from 'discord-api-types/v10'; import { ActivityType, @@ -236,13 +242,27 @@ export class BushClient extends AkairoClient { + const modify = async ( + message: Message, + text: string | MessagePayload | MessageOptions | OtherwiseContentSupplier, + data: ArgumentPromptData, + replaceError: boolean + ) => { const ending = '\n\n Type **cancel** to cancel the command'; const options = typeof text === 'function' ? await text(message, data) : text; - if (typeof options === 'string') return options + ending; + + if (typeof options === 'string') + return (replaceError ? options.replace('{error}', this.consts.emojis.error) : options) + ending; + if (options instanceof MessagePayload) { - if (options.options.content) options.options.content += ending; - } else options.content += ending; + if (options.options.content) { + if (replaceError) options.options.content = options.options.content.replace('{error}', this.consts.emojis.error); + options.options.content += ending; + } + } else if (options.content) { + if (replaceError) options.content = options.content.replace('{error}', this.consts.emojis.error); + options.content += ending; + } return options; }; @@ -262,8 +282,8 @@ export class BushClient extends AkairoClient modify(message, text, data), - modifyRetry: (message, text, data) => modify(message, text, data), + modifyStart: (message, text, data) => modify(message, text, data, false), + modifyRetry: (message, text, data) => modify(message, text, data, true), timeout: ':hourglass: You took too long the command has been cancelled.', ended: 'You exceeded the maximum amount of tries the command has been cancelled', cancel: 'The command has been cancelled', -- cgit