diff options
Diffstat (limited to 'src/commands/utilities/highlight-remove.ts')
-rw-r--r-- | src/commands/utilities/highlight-remove.ts | 46 |
1 files changed, 19 insertions, 27 deletions
diff --git a/src/commands/utilities/highlight-remove.ts b/src/commands/utilities/highlight-remove.ts index 1f7c4c0..7e8c416 100644 --- a/src/commands/utilities/highlight-remove.ts +++ b/src/commands/utilities/highlight-remove.ts @@ -1,6 +1,5 @@ -import { AllowedMentions, BushCommand, Highlight, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; +import { AllowedMentions, BushCommand, type ArgType, type BushMessage, type BushSlashMessage } from '#lib'; import assert from 'assert'; -import { ArgumentGeneratorReturn } from 'discord-akairo'; import { highlightCommandArgs, highlightSubcommands } from './highlight-!.js'; export default class HighlightRemoveCommand extends BushCommand { @@ -9,6 +8,19 @@ export default class HighlightRemoveCommand extends BushCommand { aliases: [], category: 'utilities', description: highlightSubcommands.remove, + args: [ + { + id: 'word', + description: highlightCommandArgs.remove[0].description, + type: 'string', + match: 'rest', + prompt: highlightCommandArgs.remove[0].description, + retry: highlightCommandArgs.remove[0].retry, + optional: !highlightCommandArgs.remove[0].required, + only: 'text', + slashType: false + } + ], usage: [], examples: [], clientPermissions: [], @@ -16,39 +28,19 @@ export default class HighlightRemoveCommand extends BushCommand { }); } - public override *args(): ArgumentGeneratorReturn { - const word: ArgType<'string'> = yield { - type: 'string', - match: 'rest', - prompt: { - start: highlightCommandArgs.remove[0].description, - retry: highlightCommandArgs.remove[0].retry, - optional: !highlightCommandArgs.remove[0].required - } - }; - - return { word }; - } - public override async exec(message: BushMessage | BushSlashMessage, args: { word: ArgType<'string'> }) { assert(message.inGuild()); - const [highlight] = await Highlight.findOrCreate({ - where: { - guild: message.guild.id, - user: message.author.id - } - }); + const res = await client.highlightManager.removeHighlight(message.guild.id, message.author.id, args.word); - if (!highlight.words.some((w) => w.word === args.word)) + if (typeof res === 'string') + return await message.util.reply({ content: `${util.emojis.error} ${res}`, allowedMentions: AllowedMentions.none() }); + else if (!res) return await message.util.reply({ - content: `${util.emojis.error} You have not highlighted "${args.word}".`, + content: `${util.emojis.error} There was an error unhighlighting "${args.word}".`, allowedMentions: AllowedMentions.none() }); - highlight.words = util.removeFromArray(highlight.words, highlight.words.find((w) => w.word === args.word)!); - await highlight.save(); - return await message.util.reply({ content: `${util.emojis.success} Successfully removed "${args.word}" from your highlight list.`, allowedMentions: AllowedMentions.none() |