diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-08-23 20:17:13 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-08-23 20:17:13 -0400 |
commit | 5d33e1aa43444850084b4794b7d870e67dbb474e (patch) | |
tree | 3c98cbb49ce896d0ca3e65b13c5cded0f8580359 /src/listeners/commands | |
parent | fa9e2fea668f0f1aaa766288599393e6816c58bc (diff) | |
download | tanzanite-5d33e1aa43444850084b4794b7d870e67dbb474e.tar.gz tanzanite-5d33e1aa43444850084b4794b7d870e67dbb474e.tar.bz2 tanzanite-5d33e1aa43444850084b4794b7d870e67dbb474e.zip |
bunch of shit
Diffstat (limited to 'src/listeners/commands')
-rw-r--r-- | src/listeners/commands/commandBlocked.ts | 52 | ||||
-rw-r--r-- | src/listeners/commands/messageBlocked.ts | 17 |
2 files changed, 52 insertions, 17 deletions
diff --git a/src/listeners/commands/commandBlocked.ts b/src/listeners/commands/commandBlocked.ts index 485de37..03e34f5 100644 --- a/src/listeners/commands/commandBlocked.ts +++ b/src/listeners/commands/commandBlocked.ts @@ -1,4 +1,5 @@ -import { BushCommandHandlerEvents, BushListener, BushMessage } from '@lib'; +import { BushCommand, BushCommandHandlerEvents, BushListener, BushMessage, BushSlashMessage } from '@lib'; +import { InteractionReplyOptions, Message, MessagePayload, ReplyMessageOptions } from 'discord.js'; export default class CommandBlockedListener extends BushListener { public constructor() { @@ -13,38 +14,42 @@ export default class CommandBlockedListener extends BushListener { } public static async handleBlocked( - ...[message, command, reason]: BushCommandHandlerEvents['commandBlocked'] | BushCommandHandlerEvents['slashBlocked'] + message: Message | BushMessage | BushSlashMessage, + command: BushCommand | null, + reason?: string ): Promise<unknown> { - const isSlash = message.util.isSlash; + const isSlash = !!command && !!message.util?.isSlash; void client.console.info( `${isSlash ? 'Slash' : 'Command'}Blocked`, - `<<${message.author.tag}>> tried to run <<${command}>> but was blocked because <<${reason}>>.`, + `<<${message.author.tag}>>${ + command ? ` tried to run <<${command}>> but` : "'s message" + } was blocked because <<${reason}>>.`, true ); const reasons = client.consts.BlockedReasons; switch (reason) { case reasons.OWNER: { - return await message.util.reply({ + return await respond({ content: `${util.emojis.error} Only my developers can run the \`${command}\` command.`, ephemeral: true }); } case reasons.SUPER_USER: { - return await message.util.reply({ + return await respond({ content: `${util.emojis.error} You must be a superuser to run the \`${command}\` command.`, ephemeral: true }); } case reasons.DISABLED_GLOBAL: { - return await message.util.reply({ + return await respond({ content: `${util.emojis.error} My developers disabled the \`${command}\` command.`, ephemeral: true }); } case reasons.DISABLED_GUILD: { - return await message.util.reply({ + return await respond({ content: `${util.emojis.error} The \`${command}\` command is currently disabled in \`${message.guild?.name}\`.`, ephemeral: true }); @@ -52,51 +57,64 @@ export default class CommandBlockedListener extends BushListener { case reasons.CHANNEL_GLOBAL_BLACKLIST: case reasons.CHANNEL_GUILD_BLACKLIST: return isSlash - ? message.util.reply({ content: `${util.emojis.error} You cannot use this bot in this channel.`, ephemeral: true }) - : (message as BushMessage).react(util.emojis.error); + ? await respond({ + content: `${util.emojis.error} You cannot use this bot in this channel.`, + ephemeral: true + }) + : await (message as BushMessage).react(util.emojis.cross); case reasons.USER_GLOBAL_BLACKLIST: case reasons.USER_GUILD_BLACKLIST: return isSlash - ? message.util.reply({ content: `${util.emojis.error} You are blacklisted from using this bot.`, ephemeral: true }) - : (message as BushMessage).react(util.emojis.error); + ? await respond({ + content: `${util.emojis.error} You are blacklisted from using this bot.`, + ephemeral: true + }) + : await (message as BushMessage).react(util.emojis.cross); case reasons.ROLE_BLACKLIST: { return isSlash - ? message.util.reply({ + ? await respond({ content: `${util.emojis.error} One of your roles blacklists you from using this bot.`, ephemeral: true }) - : (message as BushMessage).react(util.emojis.error); + : await (message as BushMessage).react(util.emojis.cross); } case reasons.RESTRICTED_CHANNEL: { + if (!command) break; const channels = command.restrictedChannels; const names: string[] = []; channels.forEach((c) => { names.push(`<#${c}>`); }); const pretty = util.oxford(names, 'and'); - return await message.util.reply({ + return await respond({ content: `${util.emojis.error} \`${command}\` can only be run in ${pretty}.`, ephemeral: true }); } case reasons.RESTRICTED_GUILD: { + if (!command) break; const guilds = command.restrictedGuilds; const names: string[] = []; guilds.forEach((g) => { names.push(`\`${client.guilds.cache.get(g)?.name}\``); }); const pretty = util.oxford(names, 'and'); - return await message.util.reply({ + return await respond({ content: `${util.emojis.error} \`${command}\` can only be run in ${pretty}.`, ephemeral: true }); } default: { - return await message.util.reply({ + return await respond({ content: `${util.emojis.error} Command blocked with reason \`${reason}\``, ephemeral: true }); } } + + // some inhibitors do not have message.util yet + function respond(content: string | MessagePayload | ReplyMessageOptions | InteractionReplyOptions) { + return message.util ? message.util.reply(content) : message.reply(content); + } } } diff --git a/src/listeners/commands/messageBlocked.ts b/src/listeners/commands/messageBlocked.ts new file mode 100644 index 0000000..a36c03d --- /dev/null +++ b/src/listeners/commands/messageBlocked.ts @@ -0,0 +1,17 @@ +import { BushCommandHandlerEvents, BushListener } from '@lib'; + +export default class MessageBlockedListener extends BushListener { + public constructor() { + super('messageBlocked', { + emitter: 'commandHandler', + event: 'messageBlocked' + }); + } + + public override async exec(...[message, reason]: BushCommandHandlerEvents['messageBlocked']): Promise<unknown> { + const reasons = client.consts.BlockedReasons; + if ([reasons.CLIENT, reasons.BOT].includes(reason)) return; + // return await CommandBlockedListener.handleBlocked(message as Message, null, reason); + return void client.console.verbose(`MessageBlocked`, `<<${message.author.tag}>>'s message was blocked because ${reason}`); + } +} |