fix: circular

This commit is contained in:
MARCROCK22 2024-03-27 20:24:45 -04:00
parent 776c604b3b
commit 67c90eb03a
3 changed files with 31 additions and 27 deletions

View File

@ -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<any> {
return this instanceof MenuCommandContext;
return this.isMenuUser() || this.isMenuMessage();
}
isMenuUser(): this is MenuCommandContext<UserCommandInteraction> {
return this instanceof MenuCommandContext && this.target instanceof User;
//@ts-expect-error
return this.target instanceof User;
}
isMenuMessage(): this is MenuCommandContext<MessageCommandInteraction> {
return this instanceof MenuCommandContext && this.target instanceof Message;
//@ts-expect-error
return this.target instanceof Message;
}
isComponent(): this is ComponentContext<keyof ComponentCommandInteractionMap> {
return this instanceof ComponentContext;
//@ts-expect-error
return (this.interaction as ComponentInteraction).type === InteractionType.MessageComponent;
}
}

View File

@ -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;
}

View File

@ -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<T extends {}>(
cb: (
interaction:
| ChatInputCommandInteraction
| UserCommandInteraction
| MessageCommandInteraction
| When<InferWithPrefix, Message, never>,
) => T,
cb: (interaction: Parameters<NonNullable<BaseClientOptions['context']>>[0]) => T,
) {
return cb;
}