From 67c90eb03ad73024100ff7dfcb520485f125179c Mon Sep 17 00:00:00 2001 From: MARCROCK22 <57925328+MARCROCK22@users.noreply.github.com> Date: Wed, 27 Mar 2024 20:24:45 -0400 Subject: [PATCH] fix: circular --- src/commands/basecontex.ts | 30 +++++++++++++++++++++--------- src/components/handler.ts | 3 +-- src/index.ts | 25 +++++++++---------------- 3 files changed, 31 insertions(+), 27 deletions(-) diff --git a/src/commands/basecontex.ts b/src/commands/basecontex.ts index ab866d1..65e7d6b 100644 --- a/src/commands/basecontex.ts +++ b/src/commands/basecontex.ts @@ -1,7 +1,15 @@ -import { ComponentContext, type ComponentCommandInteractionMap } from '../components/componentcontext'; -import { Message, User, type MessageCommandInteraction, type UserCommandInteraction } from '../structures'; -import { CommandContext } from './applications/chatcontext'; -import { MenuCommandContext } from './applications/menucontext'; +import { ApplicationCommandType, InteractionType } from 'discord-api-types/v10'; +import type { ComponentContext, ComponentCommandInteractionMap } from '../components/componentcontext'; +import { + type ChatInputCommandInteraction, + type ComponentInteraction, + Message, + User, + type MessageCommandInteraction, + type UserCommandInteraction, +} from '../structures'; +import type { CommandContext } from './applications/chatcontext'; +import type { MenuCommandContext } from './applications/menucontext'; import type { UsingClient } from './applications/shared'; export class BaseContext { @@ -12,22 +20,26 @@ export class BaseContext { } isChat(): this is CommandContext { - return this instanceof CommandContext; + //@ts-expect-error + return this.message || (this.interaction as ChatInputCommandInteraction).type === ApplicationCommandType.ChatInput; } isMenu(): this is MenuCommandContext { - return this instanceof MenuCommandContext; + return this.isMenuUser() || this.isMenuMessage(); } isMenuUser(): this is MenuCommandContext { - return this instanceof MenuCommandContext && this.target instanceof User; + //@ts-expect-error + return this.target instanceof User; } isMenuMessage(): this is MenuCommandContext { - return this instanceof MenuCommandContext && this.target instanceof Message; + //@ts-expect-error + return this.target instanceof Message; } isComponent(): this is ComponentContext { - return this instanceof ComponentContext; + //@ts-expect-error + return (this.interaction as ComponentInteraction).type === InteractionType.MessageComponent; } } diff --git a/src/components/handler.ts b/src/components/handler.ts index a55ecda..c2bc564 100644 --- a/src/components/handler.ts +++ b/src/components/handler.ts @@ -223,8 +223,7 @@ export class ComponentHandler extends BaseHandler { const context = new ComponentContext(this.client, interaction); const extended = this.client.options?.context?.(interaction) ?? {}; Object.assign(context, extended); - // @ts-expect-error - if (!(await i.filter(interaction))) continue; + if (!(await i.filter(context))) continue; await i.run(context); break; } diff --git a/src/index.ts b/src/index.ts index fda7e43..0aa86b5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,13 +1,12 @@ -import type { InternalRuntimeConfig, InternalRuntimeConfigHTTP, RuntimeConfig, RuntimeConfigHTTP } from './client/base'; -import type { InferWithPrefix } from './commands'; -import { GatewayIntentBits, type When } from './common'; -import type { ClientNameEvents, EventContext } from './events'; import type { - ChatInputCommandInteraction, - Message, - MessageCommandInteraction, - UserCommandInteraction, -} from './structures'; + BaseClientOptions, + InternalRuntimeConfig, + InternalRuntimeConfigHTTP, + RuntimeConfig, + RuntimeConfigHTTP, +} from './client/base'; +import { GatewayIntentBits } from './common'; +import type { ClientNameEvents, EventContext } from './events'; export { Logger, PermissionFlagsBits, PermissionStrings, Watcher } from './common'; // @@ -104,13 +103,7 @@ export const config = { * }); */ export function extendContext( - cb: ( - interaction: - | ChatInputCommandInteraction - | UserCommandInteraction - | MessageCommandInteraction - | When, - ) => T, + cb: (interaction: Parameters>[0]) => T, ) { return cb; }