diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-06-19 17:08:00 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2022-06-19 17:08:00 -0400 |
commit | e17419dcb00b228afdc0ffca5b987e1e2da70065 (patch) | |
tree | 4f014c5a4454478b483015058c142a0d359107a9 /src/commands/utilities/highlight-unblock.ts | |
parent | 8ef314c63ad5c3fa160b5ad876ef7ec315c7aa9e (diff) | |
download | tanzanite-e17419dcb00b228afdc0ffca5b987e1e2da70065.tar.gz tanzanite-e17419dcb00b228afdc0ffca5b987e1e2da70065.tar.bz2 tanzanite-e17419dcb00b228afdc0ffca5b987e1e2da70065.zip |
actually fix highlight (un)block
Diffstat (limited to 'src/commands/utilities/highlight-unblock.ts')
-rw-r--r-- | src/commands/utilities/highlight-unblock.ts | 66 |
1 files changed, 30 insertions, 36 deletions
diff --git a/src/commands/utilities/highlight-unblock.ts b/src/commands/utilities/highlight-unblock.ts index 7f416eb..d70fb28 100644 --- a/src/commands/utilities/highlight-unblock.ts +++ b/src/commands/utilities/highlight-unblock.ts @@ -1,24 +1,16 @@ -import { - AllowedMentions, - BushCommand, - emojis, - Highlight, - removeFromArray, - 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 { UnblockResult } from '../../lib/common/HighlightManager.js'; +import { highlightSubcommands } from './highlight-!.js'; export default class HighlightUnblockCommand extends BushCommand { public constructor() { super('highlight-unblock', { aliases: [], category: 'utilities', - description: highlightSubcommands.unblock, + description: highlightSubcommands.unblock.description, usage: [], examples: [], clientPermissions: [], @@ -27,46 +19,48 @@ export default class HighlightUnblockCommand 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.unblock[0].description, - retry: highlightCommandArgs.unblock[0].retry, - optional: !highlightCommandArgs.unblock[0].required + start: highlightSubcommands.unblock.options[0].start, + retry: highlightSubcommands.unblock.options[0].options[0].retry, + optional: !highlightSubcommands.unblock.options[0].options[0].retry } }; return { target }; } - public override async exec(message: CommandMessage | SlashMessage, args: { target: ArgType<'user' | 'role' | 'member'> }) { + public override async exec(message: CommandMessage | SlashMessage, args: { target: ArgType<'member' | 'textBasedChannel'> }) { assert(message.inGuild()); + 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 instanceof GuildMember || args.target instanceof Channel)) return await message.util.reply(`${emojis.error} You can only unblock users or channels.`); if (args.target instanceof Channel && !args.target.isTextBased()) return await message.util.reply(`${emojis.error} You can only unblock 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.removeBlock(message.guildId, message.author.id, args.target); - if (!highlight[key].includes(args.target.id)) - return await message.util.reply({ - content: `${emojis.error} ${args.target} is not blocked so cannot be unblock.`, - allowedMentions: AllowedMentions.none() - }); - - highlight[key] = removeFromArray(highlight[key], args.target.id); - await highlight.save(); + /* eslint-disable @typescript-eslint/no-base-to-string */ + const content = (() => { + switch (res) { + case UnblockResult.NOT_BLOCKED: + return `${emojis.error} ${args.target} is not blocked so cannot be unblock.`; + case UnblockResult.ERROR: + return `${emojis.error} An error occurred while unblocking ${args.target}.`; + case UnblockResult.SUCCESS: + return `${emojis.success} Successfully allowed ${args.target} to trigger your highlights.`; + } + })(); + /* eslint-enable @typescript-eslint/no-base-to-string */ - return await message.util.reply({ - content: `${emojis.success} Successfully allowed ${args.target} to trigger your highlights.`, - allowedMentions: AllowedMentions.none() - }); + return await message.util.reply({ content, allowedMentions: AllowedMentions.none() }); } } |