mirror of
https://github.com/tiramisulabs/seyfert.git
synced 2025-07-04 14:06:07 +00:00
fix: contexts guards
This commit is contained in:
parent
1077402ce8
commit
e3aa0a932a
@ -177,4 +177,8 @@ export class CommandContext<
|
|||||||
> {
|
> {
|
||||||
return this.interaction?.member || ((this.message! as Message)?.member as any);
|
return this.interaction?.member || ((this.message! as Message)?.member as any);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isChat(): this is CommandContext {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,9 @@ import {
|
|||||||
toSnakeCase,
|
toSnakeCase,
|
||||||
type InteractionCreateBodyRequest,
|
type InteractionCreateBodyRequest,
|
||||||
type InteractionMessageUpdateBodyRequest,
|
type InteractionMessageUpdateBodyRequest,
|
||||||
|
type ModalCreateBodyRequest,
|
||||||
type UnionToTuple,
|
type UnionToTuple,
|
||||||
type When,
|
type When,
|
||||||
type ModalCreateBodyRequest,
|
|
||||||
} from '../../common';
|
} from '../../common';
|
||||||
import {
|
import {
|
||||||
Message,
|
Message,
|
||||||
@ -152,4 +152,16 @@ export class MenuCommandContext<
|
|||||||
get member() {
|
get member() {
|
||||||
return this.interaction.member;
|
return this.interaction.member;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isMenu(): this is MenuCommandContext<UserCommandInteraction | MessageCommandInteraction> {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
isMenuUser(): this is MenuCommandContext<UserCommandInteraction> {
|
||||||
|
return this.target instanceof User;
|
||||||
|
}
|
||||||
|
|
||||||
|
isMenuMessage(): this is MenuCommandContext<MessageCommandInteraction> {
|
||||||
|
return this.target instanceof Message;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,13 +1,5 @@
|
|||||||
import { ApplicationCommandType, InteractionType } from 'discord-api-types/v10';
|
|
||||||
import type { ComponentCommandInteractionMap, ComponentContext } from '../components/componentcontext';
|
import type { ComponentCommandInteractionMap, ComponentContext } from '../components/componentcontext';
|
||||||
import {
|
import type { MessageCommandInteraction, UserCommandInteraction } from '../structures';
|
||||||
Message,
|
|
||||||
User,
|
|
||||||
type ChatInputCommandInteraction,
|
|
||||||
type ComponentInteraction,
|
|
||||||
type MessageCommandInteraction,
|
|
||||||
type UserCommandInteraction,
|
|
||||||
} from '../structures';
|
|
||||||
import type { CommandContext } from './applications/chatcontext';
|
import type { CommandContext } from './applications/chatcontext';
|
||||||
import type { MenuCommandContext } from './applications/menucontext';
|
import type { MenuCommandContext } from './applications/menucontext';
|
||||||
import type { UsingClient } from './applications/shared';
|
import type { UsingClient } from './applications/shared';
|
||||||
@ -20,26 +12,22 @@ export class BaseContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isChat(): this is CommandContext {
|
isChat(): this is CommandContext {
|
||||||
//@ts-expect-error
|
return false;
|
||||||
return this.message || (this.interaction as ChatInputCommandInteraction).type === ApplicationCommandType.ChatInput;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isMenu(): this is MenuCommandContext<UserCommandInteraction | MessageCommandInteraction> {
|
isMenu(): this is MenuCommandContext<UserCommandInteraction | MessageCommandInteraction> {
|
||||||
return this.isMenuUser() || this.isMenuMessage();
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
isMenuUser(): this is MenuCommandContext<UserCommandInteraction> {
|
isMenuUser(): this is MenuCommandContext<UserCommandInteraction> {
|
||||||
//@ts-expect-error
|
return false;
|
||||||
return this.target instanceof User;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isMenuMessage(): this is MenuCommandContext<MessageCommandInteraction> {
|
isMenuMessage(): this is MenuCommandContext<MessageCommandInteraction> {
|
||||||
//@ts-expect-error
|
return false;
|
||||||
return this.target instanceof Message;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isComponent(): this is ComponentContext<keyof ComponentCommandInteractionMap> {
|
isComponent(): this is ComponentContext<keyof ComponentCommandInteractionMap> {
|
||||||
//@ts-expect-error
|
return false;
|
||||||
return (this.interaction as ComponentInteraction).type === InteractionType.MessageComponent;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,6 +196,10 @@ export class ComponentContext<Type extends keyof ComponentCommandInteractionMap>
|
|||||||
get member() {
|
get member() {
|
||||||
return this.interaction.member;
|
return this.interaction.member;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isComponent(): this is ComponentContext<keyof ComponentCommandInteractionMap> {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface ComponentCommandInteractionMap {
|
export interface ComponentCommandInteractionMap {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user