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);
|
||||
}
|
||||
|
||||
isChat(): this is CommandContext {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
@ -4,9 +4,9 @@ import {
|
||||
toSnakeCase,
|
||||
type InteractionCreateBodyRequest,
|
||||
type InteractionMessageUpdateBodyRequest,
|
||||
type ModalCreateBodyRequest,
|
||||
type UnionToTuple,
|
||||
type When,
|
||||
type ModalCreateBodyRequest,
|
||||
} from '../../common';
|
||||
import {
|
||||
Message,
|
||||
@ -152,4 +152,16 @@ export class MenuCommandContext<
|
||||
get 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 {
|
||||
Message,
|
||||
User,
|
||||
type ChatInputCommandInteraction,
|
||||
type ComponentInteraction,
|
||||
type MessageCommandInteraction,
|
||||
type UserCommandInteraction,
|
||||
} from '../structures';
|
||||
import type { MessageCommandInteraction, UserCommandInteraction } from '../structures';
|
||||
import type { CommandContext } from './applications/chatcontext';
|
||||
import type { MenuCommandContext } from './applications/menucontext';
|
||||
import type { UsingClient } from './applications/shared';
|
||||
@ -20,26 +12,22 @@ export class BaseContext {
|
||||
}
|
||||
|
||||
isChat(): this is CommandContext {
|
||||
//@ts-expect-error
|
||||
return this.message || (this.interaction as ChatInputCommandInteraction).type === ApplicationCommandType.ChatInput;
|
||||
return false;
|
||||
}
|
||||
|
||||
isMenu(): this is MenuCommandContext<UserCommandInteraction | MessageCommandInteraction> {
|
||||
return this.isMenuUser() || this.isMenuMessage();
|
||||
return false;
|
||||
}
|
||||
|
||||
isMenuUser(): this is MenuCommandContext<UserCommandInteraction> {
|
||||
//@ts-expect-error
|
||||
return this.target instanceof User;
|
||||
return false;
|
||||
}
|
||||
|
||||
isMenuMessage(): this is MenuCommandContext<MessageCommandInteraction> {
|
||||
//@ts-expect-error
|
||||
return this.target instanceof Message;
|
||||
return false;
|
||||
}
|
||||
|
||||
isComponent(): this is ComponentContext<keyof ComponentCommandInteractionMap> {
|
||||
//@ts-expect-error
|
||||
return (this.interaction as ComponentInteraction).type === InteractionType.MessageComponent;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -196,6 +196,10 @@ export class ComponentContext<Type extends keyof ComponentCommandInteractionMap>
|
||||
get member() {
|
||||
return this.interaction.member;
|
||||
}
|
||||
|
||||
isComponent(): this is ComponentContext<keyof ComponentCommandInteractionMap> {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
export interface ComponentCommandInteractionMap {
|
||||
|
Loading…
x
Reference in New Issue
Block a user