aboutsummaryrefslogtreecommitdiff
path: root/src/commands/utilities/highlight-add.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/commands/utilities/highlight-add.ts')
-rw-r--r--src/commands/utilities/highlight-add.ts61
1 files changed, 30 insertions, 31 deletions
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()