mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-03 05:26:07 +00:00
fix: circular
This commit is contained in:
parent
776c604b3b
commit
67c90eb03a
@ -1,7 +1,15 @@
|
|||||||
import { ComponentContext, type ComponentCommandInteractionMap } from '../components/componentcontext';
|
import { ApplicationCommandType, InteractionType } from 'discord-api-types/v10';
|
||||||
import { Message, User, type MessageCommandInteraction, type UserCommandInteraction } from '../structures';
|
import type { ComponentContext, ComponentCommandInteractionMap } from '../components/componentcontext';
|
||||||
import { CommandContext } from './applications/chatcontext';
|
import {
|
||||||
import { MenuCommandContext } from './applications/menucontext';
|
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';
|
import type { UsingClient } from './applications/shared';
|
||||||
|
|
||||||
export class BaseContext {
|
export class BaseContext {
|
||||||
@ -12,22 +20,26 @@ export class BaseContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isChat(): this is CommandContext {
|
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> {
|
isMenu(): this is MenuCommandContext<any> {
|
||||||
return this instanceof MenuCommandContext;
|
return this.isMenuUser() || this.isMenuMessage();
|
||||||
}
|
}
|
||||||
|
|
||||||
isMenuUser(): this is MenuCommandContext<UserCommandInteraction> {
|
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> {
|
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> {
|
isComponent(): this is ComponentContext<keyof ComponentCommandInteractionMap> {
|
||||||
return this instanceof ComponentContext;
|
//@ts-expect-error
|
||||||
|
return (this.interaction as ComponentInteraction).type === InteractionType.MessageComponent;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -223,8 +223,7 @@ export class ComponentHandler extends BaseHandler {
|
|||||||
const context = new ComponentContext(this.client, interaction);
|
const context = new ComponentContext(this.client, interaction);
|
||||||
const extended = this.client.options?.context?.(interaction) ?? {};
|
const extended = this.client.options?.context?.(interaction) ?? {};
|
||||||
Object.assign(context, extended);
|
Object.assign(context, extended);
|
||||||
// @ts-expect-error
|
if (!(await i.filter(context))) continue;
|
||||||
if (!(await i.filter(interaction))) continue;
|
|
||||||
await i.run(context);
|
await i.run(context);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
25
src/index.ts
25
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 {
|
import type {
|
||||||
ChatInputCommandInteraction,
|
BaseClientOptions,
|
||||||
Message,
|
InternalRuntimeConfig,
|
||||||
MessageCommandInteraction,
|
InternalRuntimeConfigHTTP,
|
||||||
UserCommandInteraction,
|
RuntimeConfig,
|
||||||
} from './structures';
|
RuntimeConfigHTTP,
|
||||||
|
} from './client/base';
|
||||||
|
import { GatewayIntentBits } from './common';
|
||||||
|
import type { ClientNameEvents, EventContext } from './events';
|
||||||
|
|
||||||
export { Logger, PermissionFlagsBits, PermissionStrings, Watcher } from './common';
|
export { Logger, PermissionFlagsBits, PermissionStrings, Watcher } from './common';
|
||||||
//
|
//
|
||||||
@ -104,13 +103,7 @@ export const config = {
|
|||||||
* });
|
* });
|
||||||
*/
|
*/
|
||||||
export function extendContext<T extends {}>(
|
export function extendContext<T extends {}>(
|
||||||
cb: (
|
cb: (interaction: Parameters<NonNullable<BaseClientOptions['context']>>[0]) => T,
|
||||||
interaction:
|
|
||||||
| ChatInputCommandInteraction
|
|
||||||
| UserCommandInteraction
|
|
||||||
| MessageCommandInteraction
|
|
||||||
| When<InferWithPrefix, Message, never>,
|
|
||||||
) => T,
|
|
||||||
) {
|
) {
|
||||||
return cb;
|
return cb;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user