diff options
author | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-08-17 12:31:09 -0400 |
---|---|---|
committer | IRONM00N <64110067+IRONM00N@users.noreply.github.com> | 2021-08-17 12:31:09 -0400 |
commit | d40527d0a2d9f209905750258f71bedff1cdf089 (patch) | |
tree | e017fd844c2135bfc85228d00ef2617d24ce0a3f /src/listeners/commands | |
parent | d431ad00754f3f250103deedea495b9bcee73fc0 (diff) | |
download | tanzanite-d40527d0a2d9f209905750258f71bedff1cdf089.tar.gz tanzanite-d40527d0a2d9f209905750258f71bedff1cdf089.tar.bz2 tanzanite-d40527d0a2d9f209905750258f71bedff1cdf089.zip |
turned on ts strict option
Diffstat (limited to 'src/listeners/commands')
-rw-r--r-- | src/listeners/commands/commandBlocked.ts | 12 | ||||
-rw-r--r-- | src/listeners/commands/commandError.ts | 20 | ||||
-rw-r--r-- | src/listeners/commands/commandMissingPermissions.ts | 9 | ||||
-rw-r--r-- | src/listeners/commands/slashStarted.ts | 6 |
4 files changed, 30 insertions, 17 deletions
diff --git a/src/listeners/commands/commandBlocked.ts b/src/listeners/commands/commandBlocked.ts index 5d6bcfb..485de37 100644 --- a/src/listeners/commands/commandBlocked.ts +++ b/src/listeners/commands/commandBlocked.ts @@ -45,7 +45,7 @@ export default class CommandBlockedListener extends BushListener { } case reasons.DISABLED_GUILD: { return await message.util.reply({ - content: `${util.emojis.error} The \`${command}\` command is currently disabled in \`${message.guild.name}\`.`, + content: `${util.emojis.error} The \`${command}\` command is currently disabled in \`${message.guild?.name}\`.`, ephemeral: true }); } @@ -69,11 +69,11 @@ export default class CommandBlockedListener extends BushListener { } case reasons.RESTRICTED_CHANNEL: { const channels = command.restrictedChannels; - const names = []; + const names: string[] = []; channels.forEach((c) => { names.push(`<#${c}>`); }); - const pretty = util.oxford(names, 'and', undefined); + const pretty = util.oxford(names, 'and'); return await message.util.reply({ content: `${util.emojis.error} \`${command}\` can only be run in ${pretty}.`, ephemeral: true @@ -81,11 +81,11 @@ export default class CommandBlockedListener extends BushListener { } case reasons.RESTRICTED_GUILD: { const guilds = command.restrictedGuilds; - const names = []; + const names: string[] = []; guilds.forEach((g) => { - names.push(`\`${client.guilds.cache.get(g).name}\``); + names.push(`\`${client.guilds.cache.get(g)?.name}\``); }); - const pretty = util.oxford(names, 'and', undefined); + const pretty = util.oxford(names, 'and'); return await message.util.reply({ content: `${util.emojis.error} \`${command}\` can only be run in ${pretty}.`, ephemeral: true diff --git a/src/listeners/commands/commandError.ts b/src/listeners/commands/commandError.ts index e5de0cc..d4f68f2 100644 --- a/src/listeners/commands/commandError.ts +++ b/src/listeners/commands/commandError.ts @@ -1,5 +1,6 @@ import { BushCommandHandlerEvents, BushListener } from '@lib'; -import { MessageEmbed } from 'discord.js'; +import { GuildTextBasedChannels } from 'discord-akairo'; +import { DMChannel, MessageEmbed } from 'discord.js'; export default class CommandErrorListener extends BushListener { public constructor() { @@ -16,13 +17,16 @@ export default class CommandErrorListener extends BushListener { public static async handleError( ...[error, message, command]: BushCommandHandlerEvents['error'] | BushCommandHandlerEvents['slashError'] ): Promise<void> { - const isSlash = message.util.isSlash; + const isSlash = message.util!.isSlash; const errorNo = Math.floor(Math.random() * 6969696969) + 69; // hehe funny number - const channel = message.channel.type === 'DM' ? message.channel.recipient.tag : message.channel.name; + const channel = + message.channel!.type === 'DM' + ? (message.channel as DMChannel)!.recipient.tag + : (message.channel as GuildTextBasedChannels)!.name; const errorEmbed: MessageEmbed = new MessageEmbed() .setTitle(`${isSlash ? 'Slash ' : ''}Error # \`${errorNo}\`: An error occurred`) - .addField('Error', await util.inspectCleanRedactCodeblock(error?.stack || error, 'js', undefined)) + .addField('Error', await util.inspectCleanRedactCodeblock(error?.stack ?? error, 'js', undefined)) .setColor(util.colors.error) .setTimestamp(); const description = [ @@ -58,9 +62,13 @@ export default class CommandErrorListener extends BushListener { .setTitle(`A Command Error Occurred ${'code' in error ? `\`${(error as any).code}\`` : ''}`) .setColor(util.colors.error) .setTimestamp() - .setDescription(await util.inspectCleanRedactCodeblock(error?.stack || error, 'js', undefined, 4096)); + .setDescription(await util.inspectCleanRedactCodeblock(error?.stack ?? error, 'js', undefined, 4096)); (await message.util?.send({ embeds: [errorDevEmbed] }).catch((e) => { - const channel = message.channel.type === 'DM' ? message.channel.recipient.tag : message.channel.name; + const channel = message.channel + ? message.channel.type === 'DM' + ? message.channel.recipient.tag + : message.channel.name + : 'unknown'; void client.console.warn(heading, `Failed to send owner error stack in <<${channel}>>.` + e?.stack || e); })) ?? client.console.error(heading, `Failed to send owner error stack.` + error?.stack || error, false); } diff --git a/src/listeners/commands/commandMissingPermissions.ts b/src/listeners/commands/commandMissingPermissions.ts index fdca5d3..dc04ac2 100644 --- a/src/listeners/commands/commandMissingPermissions.ts +++ b/src/listeners/commands/commandMissingPermissions.ts @@ -1,4 +1,5 @@ import { BushCommandHandlerEvents, BushListener } from '@lib'; +import { PermissionString } from 'discord.js'; export default class CommandMissingPermissionsListener extends BushListener { public constructor() { @@ -20,10 +21,10 @@ export default class CommandMissingPermissionsListener extends BushListener { | BushCommandHandlerEvents['missingPermissions'] | BushCommandHandlerEvents['slashMissingPermissions'] ): Promise<unknown> { - const niceMissing = []; - missing.forEach((missing) => { - if (client.consts.mappings.permissions[missing]) { - niceMissing.push(client.consts.mappings.permissions[missing].name); + const niceMissing: string[] = []; + missing.forEach((missing: PermissionString) => { + if (client.consts.mappings.permissions[missing as keyof typeof client.consts.mappings.permissions]) { + niceMissing.push(client.consts.mappings.permissions[missing as keyof typeof client.consts.mappings.permissions].name); } else { niceMissing.push(missing); } diff --git a/src/listeners/commands/slashStarted.ts b/src/listeners/commands/slashStarted.ts index e64df54..855c026 100644 --- a/src/listeners/commands/slashStarted.ts +++ b/src/listeners/commands/slashStarted.ts @@ -12,7 +12,11 @@ export default class SlashStartedListener extends BushListener { return void client.logger.info( 'SlashCommand', `The <<${command.id}>> command was used by <<${message.author.tag}>> in ${ - message.channel.type === 'DM' ? `their <<DMs>>` : `<<#${message.channel.name}>> in <<${message.guild?.name}>>` + message.channel + ? message.channel.type === 'DM' + ? `their <<DMs>>` + : `<<#${message.channel.name}>> in <<${message.guild?.name}>>` + : 'unknown' }.`, true ); |