From 084a815f3799764d2dd697e8c693c7f80e0c7ab7 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Wed, 23 Feb 2022 21:38:40 -0500 Subject: feat(hl): make functional, no cool downs yet, restrcited to su --- src/commands/utilities/highlight-add.ts | 61 ++++++++++++++++----------------- 1 file changed, 30 insertions(+), 31 deletions(-) (limited to 'src/commands/utilities/highlight-add.ts') diff --git a/src/commands/utilities/highlight-add.ts b/src/commands/utilities/highlight-add.ts index 316a931..9c7506e 100644 --- a/src/commands/utilities/highlight-add.ts +++ b/src/commands/utilities/highlight-add.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 HighlightAddCommand extends BushCommand { @@ -9,6 +8,28 @@ export default class HighlightAddCommand extends BushCommand { aliases: [], category: 'utilities', description: highlightSubcommands.add, + args: [ + { + id: 'word', + description: highlightCommandArgs.add[0].description, + type: 'string', + match: 'rest', + prompt: highlightCommandArgs.add[0].description, + retry: highlightCommandArgs.add[0].retry, + optional: !highlightCommandArgs.add[0].required, + only: 'text', + slashType: false + }, + { + id: 'regex', + description: highlightCommandArgs.add[1].description, + match: 'flag', + flag: '--regex', + prompt: highlightCommandArgs.add[1].description, + only: 'text', + slashType: false + } + ], usage: [], examples: [], clientPermissions: [], @@ -16,25 +37,6 @@ export default class HighlightAddCommand extends BushCommand { }); } - public override *args(): ArgumentGeneratorReturn { - const word: ArgType<'string'> = yield { - type: 'string', - match: 'rest', - prompt: { - start: highlightCommandArgs.add[0].description, - retry: highlightCommandArgs.add[0].retry, - optional: !highlightCommandArgs.add[0].required - } - }; - - const regex: boolean = yield { - match: 'flag', - flag: 'regex' - }; - - return { word, regex }; - } - public override async exec( message: BushMessage | BushSlashMessage, args: { word: ArgType<'string'>; regex: ArgType<'boolean'> } @@ -58,22 +60,19 @@ export default class HighlightAddCommand extends BushCommand { } } - const [highlight] = await Highlight.findOrCreate({ - where: { - guild: message.guild.id, - user: message.author.id - } + const res = await client.highlightManager.addHighlight(message.guild.id, message.author.id, { + word: args.word, + regex: args.regex }); - 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 already highlighted "${args.word}".`, + content: `${util.emojis.error} There was an error highlighting "${args.word}".`, allowedMentions: AllowedMentions.none() }); - highlight.words = util.addToArray(highlight.words, { word: args.word, regex: args.regex }); - await highlight.save(); - return await message.util.reply({ content: `${util.emojis.success} Successfully added "${args.word}" to your highlight list.`, allowedMentions: AllowedMentions.none() -- cgit