aboutsummaryrefslogtreecommitdiff
path: root/src/commands/utilities/highlight-block.ts
diff options
context:
space:
mode:
authorIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-06-19 17:08:00 -0400
committerIRONM00N <64110067+IRONM00N@users.noreply.github.com>2022-06-19 17:08:00 -0400
commite17419dcb00b228afdc0ffca5b987e1e2da70065 (patch)
tree4f014c5a4454478b483015058c142a0d359107a9 /src/commands/utilities/highlight-block.ts
parent8ef314c63ad5c3fa160b5ad876ef7ec315c7aa9e (diff)
downloadtanzanite-e17419dcb00b228afdc0ffca5b987e1e2da70065.tar.gz
tanzanite-e17419dcb00b228afdc0ffca5b987e1e2da70065.tar.bz2
tanzanite-e17419dcb00b228afdc0ffca5b987e1e2da70065.zip
actually fix highlight (un)block
Diffstat (limited to 'src/commands/utilities/highlight-block.ts')
-rw-r--r--src/commands/utilities/highlight-block.ts70
1 files changed, 29 insertions, 41 deletions
diff --git a/src/commands/utilities/highlight-block.ts b/src/commands/utilities/highlight-block.ts
index 5429071..9ee8a5a 100644
--- a/src/commands/utilities/highlight-block.ts
+++ b/src/commands/utilities/highlight-block.ts
@@ -1,25 +1,16 @@
-import {
- addToArray,
- AllowedMentions,
- Arg,
- BushCommand,
- emojis,
- Highlight,
- type ArgType,
- type CommandMessage,
- type SlashMessage
-} from '#lib';
+import { AllowedMentions, BushCommand, emojis, type ArgType, type CommandMessage, type SlashMessage } from '#lib';
import assert from 'assert';
import { Argument, ArgumentGeneratorReturn } from 'discord-akairo';
-import { Channel, GuildMember } from 'discord.js';
-import { highlightCommandArgs, highlightSubcommands } from './highlight-!.js';
+import { Channel, GuildMember, User } from 'discord.js';
+import { BlockResult } from '../../lib/common/HighlightManager.js';
+import { highlightSubcommands } from './highlight-!.js';
export default class HighlightBlockCommand extends BushCommand {
public constructor() {
super('highlight-block', {
aliases: [],
category: 'utilities',
- description: highlightSubcommands.block,
+ description: highlightSubcommands.block.description,
usage: [],
examples: [],
clientPermissions: [],
@@ -28,24 +19,26 @@ export default class HighlightBlockCommand extends BushCommand {
}
public override *args(): ArgumentGeneratorReturn {
- const target: ArgType<'member' | 'channel'> = yield {
- type: Argument.union('member', 'channel'),
+ const target: ArgType<'member' | 'textBasedChannel'> = yield {
+ type: Argument.union('member', 'textBasedChannel'),
match: 'rest',
prompt: {
- start: highlightCommandArgs.block[0].description,
- retry: highlightCommandArgs.block[0].retry,
- optional: !highlightCommandArgs.block[0].required
+ start: highlightSubcommands.block.options[0].start,
+ retry: highlightSubcommands.block.options[0].options[0].retry,
+ optional: !highlightSubcommands.block.options[0].options[0].required
}
};
return { target };
}
- public override async exec(message: CommandMessage | SlashMessage, args: { target: string | ArgType<'member' | 'channel'> }) {
+ public override async exec(message: CommandMessage | SlashMessage, args: { target: ArgType<'member' | 'textBasedChannel'> }) {
assert(message.inGuild());
- args.target =
- typeof args.target === 'string' ? (await Arg.cast(Arg.union('member', 'channel'), message, args.target))! : args.target;
+ if (args.target instanceof User && message.util.isSlashMessage(message))
+ args.target = message.interaction.options.getMember('target')!;
+
+ if (!args.target) return message.util.reply(`${emojis.error} Could not resolve member.`);
if (!args.target || !(args.target instanceof GuildMember || args.target instanceof Channel))
return await message.util.reply(`${emojis.error} You can only block users or channels.`);
@@ -53,26 +46,21 @@ export default class HighlightBlockCommand extends BushCommand {
if (args.target instanceof Channel && !args.target.isTextBased())
return await message.util.reply(`${emojis.error} You can only block text-based channels.`);
- const [highlight] = await Highlight.findOrCreate({
- where: { guild: message.guild.id, user: message.author.id }
- });
-
- const key = `blacklisted${args.target instanceof Channel ? 'Channels' : 'Users'}` as const;
+ const res = await this.client.highlightManager.addBlock(message.guildId, message.author.id, args.target);
- if (highlight[key].includes(args.target.id))
- return await message.util.reply({
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
- content: `${emojis.error} You have already blocked ${args.target}.`,
- allowedMentions: AllowedMentions.none()
- });
-
- highlight[key] = addToArray(highlight[key], args.target.id);
- await highlight.save();
+ /* eslint-disable @typescript-eslint/no-base-to-string */
+ const content = (() => {
+ switch (res) {
+ case BlockResult.ALREADY_BLOCKED:
+ return `${emojis.error} You have already blocked ${args.target}.`;
+ case BlockResult.ERROR:
+ return `${emojis.error} An error occurred while blocking ${args.target}.`;
+ case BlockResult.SUCCESS:
+ return `${emojis.success} Successfully blocked ${args.target} from triggering your highlights.`;
+ }
+ })();
+ /* eslint-enable @typescript-eslint/no-base-to-string */
- return await message.util.reply({
- // eslint-disable-next-line @typescript-eslint/no-base-to-string
- content: `${emojis.success} Successfully blocked ${args.target} from triggering your highlights.`,
- allowedMentions: AllowedMentions.none()
- });
+ return await message.util.reply({ content, allowedMentions: AllowedMentions.none() });
}
}