From e05f25f4b98cac3c2409cee9a664ab5ea6251467 Mon Sep 17 00:00:00 2001 From: IRONM00N <64110067+IRONM00N@users.noreply.github.com> Date: Mon, 27 Dec 2021 13:12:49 -0500 Subject: better typings and some other stuff --- .../extensions/discord-akairo/BushClientUtil.ts | 5 +- src/lib/extensions/discord-akairo/BushCommand.ts | 121 +++++++++++++++++---- .../extensions/discord-akairo/BushSlashMessage.ts | 16 ++- 3 files changed, 117 insertions(+), 25 deletions(-) (limited to 'src/lib') diff --git a/src/lib/extensions/discord-akairo/BushClientUtil.ts b/src/lib/extensions/discord-akairo/BushClientUtil.ts index 5ae2ac0..f44c80d 100644 --- a/src/lib/extensions/discord-akairo/BushClientUtil.ts +++ b/src/lib/extensions/discord-akairo/BushClientUtil.ts @@ -513,7 +513,7 @@ export class BushClientUtil extends ClientUtil { if (!content) return { duration: 0, contentWithoutTime: null }; // eslint-disable-next-line prefer-const - let duration = null; + let duration: number | null = null; // Try to reduce false positives by requiring a space before the duration, this makes sure it still matches if it is // in the beginning of the argument let contentWithoutTime = ` ${content}`; @@ -522,8 +522,7 @@ export class BushClientUtil extends ClientUtil { const regex = BushConstants.TimeUnits[unit as keyof typeof BushConstants.TimeUnits].match; const match = regex.exec(contentWithoutTime); const value = Number(match?.groups?.[unit]); - if (!isNaN(value)) - (duration as unknown as number) += value * BushConstants.TimeUnits[unit as keyof typeof BushConstants.TimeUnits].value; + if (!isNaN(value)) duration! += value * BushConstants.TimeUnits[unit as keyof typeof BushConstants.TimeUnits].value; if (remove) contentWithoutTime = contentWithoutTime.replace(regex, ''); } diff --git a/src/lib/extensions/discord-akairo/BushCommand.ts b/src/lib/extensions/discord-akairo/BushCommand.ts index 6b54e20..0d0a0a8 100644 --- a/src/lib/extensions/discord-akairo/BushCommand.ts +++ b/src/lib/extensions/discord-akairo/BushCommand.ts @@ -1,34 +1,109 @@ +import { type DiscordEmojiInfo, type RoleWithDuration } from '#args'; import { - BushArgumentTypeCaster, - BushUser, - ParsedDuration, + type BushArgumentTypeCaster, + type BushBaseGuildVoiceChannel, + type BushCategoryChannel, type BushClient, type BushCommandHandler, + type BushEmoji, + type BushGuild, + type BushGuildBasedChannel, + type BushGuildChannel, + type BushGuildEmoji, + type BushGuildMember, + type BushInhibitor, + type BushListener, type BushMessage, - type BushSlashMessage + type BushNewsChannel, + type BushRole, + type BushSlashMessage, + type BushStageChannel, + type BushStoreChannel, + type BushTask, + type BushTextChannel, + type BushThreadChannel, + type BushUser, + type BushVoiceChannel, + type ParsedDuration } from '#lib'; import { - AkairoApplicationCommandAutocompleteOption, - AkairoApplicationCommandChannelOptionData, - AkairoApplicationCommandChoicesData, - AkairoApplicationCommandNonOptionsData, - AkairoApplicationCommandNumericOptionData, - AkairoApplicationCommandOptionData, - AkairoApplicationCommandSubCommandData, - AkairoApplicationCommandSubGroupData, Command, - MissingPermissionSupplier, - SlashOption, - SlashResolveTypes, + type AkairoApplicationCommandAutocompleteOption, + type AkairoApplicationCommandChannelOptionData, + type AkairoApplicationCommandChoicesData, + type AkairoApplicationCommandNonOptionsData, + type AkairoApplicationCommandNumericOptionData, + type AkairoApplicationCommandOptionData, + type AkairoApplicationCommandSubCommandData, + type AkairoApplicationCommandSubGroupData, type ArgumentOptions, - type CommandOptions + type ArgumentType, + type ArgumentTypeCaster, + type BaseArgumentType, + type CommandOptions, + type ContextMenuCommand, + type MissingPermissionSupplier, + type SlashOption, + type SlashResolveTypes } from 'discord-akairo'; -import { ArgumentType, ArgumentTypeCaster, BaseArgumentType } from 'discord-akairo/dist/src/struct/commands/arguments/Argument'; -import { ApplicationCommandOptionChoice, PermissionString, type PermissionResolvable, type Snowflake } from 'discord.js'; -import { DiscordEmojiInfo } from '../../../arguments/discordEmoji'; -import { RoleWithDuration } from '../../../arguments/roleWithDuration'; +import { + type ApplicationCommandOptionChoice, + type Collection, + type Invite, + type PermissionResolvable, + type PermissionString, + type Snowflake +} from 'discord.js'; + +export interface OverriddenBaseArgumentType extends BaseArgumentType { + user: BushUser | null; + users: Collection | null; + member: BushGuildMember | null; + members: Collection | null; + relevant: BushUser | BushGuildMember | null; + relevants: Collection | Collection | null; + channel: BushGuildBasedChannel | BushBaseGuildVoiceChannel | null; + channels: Collection | null; + textChannel: BushTextChannel | null; + textChannels: Collection | null; + voiceChannel: BushVoiceChannel | null; + voiceChannels: Collection | null; + categoryChannel: BushCategoryChannel | null; + categoryChannels: Collection | null; + newsChannel: BushNewsChannel | null; + newsChannels: Collection | null; + // eslint-disable-next-line deprecation/deprecation + storeChannel: BushStoreChannel | null; + // eslint-disable-next-line deprecation/deprecation + storeChannels: Collection | null; + stageChannel: BushStageChannel | null; + stageChannels: Collection | null; + threadChannel: BushThreadChannel | null; + threadChannels: Collection | null; + role: BushRole | null; + roles: Collection | null; + emoji: BushEmoji | null; + emojis: Collection | null; + guild: BushGuild | null; + guilds: Collection | null; + message: BushMessage | null; + guildMessage: BushMessage | null; + relevantMessage: BushMessage | null; + invite: Invite | null; + userMention: BushUser | null; + memberMention: BushGuildMember | null; + channelMention: BushThreadChannel | BushGuildChannel | null; + roleMention: BushRole | null; + emojiMention: BushGuildEmoji | null; + commandAlias: BushCommand | null; + command: BushCommand | null; + inhibitor: BushInhibitor | null; + listener: BushListener | null; + task: BushTask | null; + contextMenuCommand: ContextMenuCommand | null; +} -export interface BaseBushArgumentType extends BaseArgumentType { +export interface BaseBushArgumentType extends OverriddenBaseArgumentType { duration: number | null; contentWithDuration: ParsedDuration; permission: PermissionString | null; @@ -38,6 +113,7 @@ export interface BaseBushArgumentType extends BaseArgumentType { abbreviatedNumber: number | null; globalUser: BushUser | null; messageLink: BushMessage | null; + durationSeconds: number | null; } export type BushArgumentType = keyof BaseBushArgumentType | RegExp; @@ -446,3 +522,6 @@ type SlashOptionKeys = | keyof AkairoApplicationCommandAutocompleteOption | keyof AkairoApplicationCommandNumericOptionData | keyof AkairoApplicationCommandSubCommandData; + +export type ArgType = NonNullable; +export type OptionalArgType = BaseBushArgumentType[T]; diff --git a/src/lib/extensions/discord-akairo/BushSlashMessage.ts b/src/lib/extensions/discord-akairo/BushSlashMessage.ts index 448963b..3cd167d 100644 --- a/src/lib/extensions/discord-akairo/BushSlashMessage.ts +++ b/src/lib/extensions/discord-akairo/BushSlashMessage.ts @@ -1,4 +1,11 @@ -import { type BushClient, type BushCommandUtil, type BushGuild, type BushGuildMember, type BushUser } from '#lib'; +import { + type BushClient, + type BushCommandUtil, + type BushGuild, + type BushGuildMember, + type BushTextBasedChannel, + type BushUser +} from '#lib'; import { AkairoMessage } from 'discord-akairo'; import { type CommandInteraction } from 'discord.js'; @@ -12,6 +19,13 @@ export class BushSlashMessage extends AkairoMessage { } } +export interface BushSlashMessage extends AkairoMessage { + /** + * The channel that the interaction was sent in. + */ + get channel(): BushTextBasedChannel | null; +} + export interface BushSlashMessage extends AkairoMessage { get guild(): BushGuild | null; } -- cgit