2023-05-10 04:19:49 +02:00
|
|
|
import { AutocompleteInteraction, PermissionsBitField } from "discord.js";
|
2023-05-08 08:53:06 +02:00
|
|
|
import { RESTPostAPIApplicationCommandsJSONBody } from "discord.js";
|
|
|
|
import { ApplicationCommandOption, ApplicationCommandType, ChatInputCommandInteraction, LocalizationMap, MessageInteraction, PermissionResolvable, UserSelectMenuInteraction } from "discord.js";
|
|
|
|
|
|
|
|
type InteractionTypeMap = {
|
|
|
|
[ApplicationCommandType.ChatInput]: [ChatInputCommandInteraction, string];
|
|
|
|
[ApplicationCommandType.Message]: [MessageInteraction, never];
|
|
|
|
[ApplicationCommandType.User]: [UserSelectMenuInteraction, never];
|
|
|
|
};
|
|
|
|
|
|
|
|
interface Command<Type extends keyof InteractionTypeMap = ApplicationCommandType> {
|
|
|
|
readonly name: string;
|
|
|
|
readonly name_localizations?: LocalizationMap;
|
|
|
|
readonly description: InteractionTypeMap[Type][1];
|
|
|
|
readonly description_localizations?: LocalizationMap;
|
|
|
|
readonly options?: ApplicationCommandOption[];
|
|
|
|
readonly default_member_permissions?: PermissionResolvable;
|
|
|
|
readonly type: Type;
|
|
|
|
readonly nsfw?: boolean;
|
|
|
|
readonly dm_permission?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
abstract class Command<Type extends keyof InteractionTypeMap = ApplicationCommandType> {
|
|
|
|
abstract execute(interaction: InteractionTypeMap[Type][0]): Promise<void>;
|
|
|
|
|
2023-05-10 04:19:49 +02:00
|
|
|
autocomplete?(interaction: Type extends ApplicationCommandType.ChatInput ? AutocompleteInteraction : never ): Promise<void>;
|
|
|
|
|
2023-05-08 08:53:06 +02:00
|
|
|
toRESTPostApplicationCommands(): RESTPostAPIApplicationCommandsJSONBody {
|
|
|
|
return {
|
|
|
|
name: this.name,
|
|
|
|
name_localizations: this.name_localizations,
|
|
|
|
description: this.description,
|
|
|
|
description_localizations: this.description_localizations,
|
|
|
|
options: this.options,
|
|
|
|
default_member_permissions: this.default_member_permissions !== undefined ? new PermissionsBitField(this.default_member_permissions).bitfield.toString() : undefined,
|
|
|
|
type: this.type,
|
|
|
|
nsfw: this.nsfw,
|
|
|
|
dm_permission: this.dm_permission,
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
export default Command;
|