@a-djs-handler/framework
Version:
Simple command handler for discord.js v14.
209 lines (191 loc) • 11 kB
TypeScript
import * as discord_js from 'discord.js';
import { Collection, ClientOptions, Client, Guild, User, InteractionReplyOptions, ApplicationCommandOption, ChatInputCommandInteraction, ContextMenuCommandInteraction, AutocompleteInteraction, Interaction, ClientEvents, Awaitable, RESTPostAPIChatInputApplicationCommandsJSONBody, RESTPostAPIContextMenuApplicationCommandsJSONBody, ChatInputApplicationCommandData, SlashCommandBuilder, SlashCommandSubcommandsOnlyBuilder, SlashCommandOptionsOnlyBuilder, UserApplicationCommandData, MessageApplicationCommandData, ContextMenuCommandBuilder, ApplicationCommand, PermissionsString, ChannelType, ApplicationCommandOptionData, APIApplicationCommandOption, RESTPostAPIApplicationCommandsJSONBody, PermissionResolvable } from 'discord.js';
import * as _sapphire_result from '@sapphire/result';
import { Option, Result } from '@sapphire/result';
import { Job as Job$1 } from 'node-schedule';
declare const registries: Collection<string, CommandRegistry>;
declare const allGuildIdsToRegister: Set<string>;
declare function createRegistry(name: string): CommandRegistry;
interface MoodyClientOptions extends ClientOptions {
baseDir: string;
developers?: string[];
}
declare class MoodyClient<Ready extends boolean = boolean> extends Client<Ready> {
baseDir: string;
commands: Collection<string, Command>;
events: Collection<string, Listener>;
components: Collection<string, Component>;
jobs: Collection<string, Job>;
developers: string[];
constructor(options: MoodyClientOptions);
login(token?: string): Promise<string>;
registerPaths(): Promise<this>;
registerDefaultListeners(): this;
handleRegistryAPICalls(): Promise<void>;
}
declare class CommandContext<Interaction extends InteractionTypes> implements CommandContextOptions<Interaction> {
interaction: Interaction;
guild?: Guild;
author: User;
client: MoodyClient;
constructor(options: CommandContextOptions<Interaction>);
safeReply(options: InteractionReplyOptions): Promise<discord_js.Message<boolean> | discord_js.InteractionResponse<boolean>>;
}
declare class Command implements CommandOptions {
name: string;
description: string;
category: string;
preconditions: Precondition[];
options: ApplicationCommandOption[];
registry: CommandRegistry;
constructor(options: CommandOptions);
chatInputRun?(context: CommandContext<ChatInputCommandInteraction>): MaybePromise<unknown>;
contextMenuRun?(context: CommandContext<ContextMenuCommandInteraction>): MaybePromise<unknown>;
autocompleteRun?(interaction: AutocompleteInteraction): MaybePromise<unknown>;
registerCommand(registry: CommandRegistry): MaybePromise<unknown>;
}
declare namespace Command {
type Context<Interaction extends InteractionTypes> = CommandContext<Interaction>;
type ChatInputCommandInteraction<Cached extends discord_js.CacheType = discord_js.CacheType> = discord_js.ChatInputCommandInteraction<Cached>;
type ContextMenuCommandInteraction<Cached extends discord_js.CacheType = discord_js.CacheType> = discord_js.ContextMenuCommandInteraction<Cached>;
type AutocompleteInteraction<Cached extends discord_js.CacheType = discord_js.CacheType> = discord_js.AutocompleteInteraction<Cached>;
type Registry = CommandRegistry;
}
type MaybePromise<T> = Promise<T> | T;
declare abstract class Component implements ComponentOptions {
type: ComponentType;
name: string;
constructor(options: ComponentOptions);
abstract run(interaction: Interaction, data?: unknown): MaybePromise<unknown>;
parse(_interaction: Interaction): MaybePromise<Option<unknown>>;
some(): Option.Some<never>;
some<T>(data: T): Option.Some<T>;
none(): Option.None;
}
interface ComponentOptions {
type: ComponentType;
name: string;
}
declare enum ComponentType {
Button = 0,
SelectMenu = 1,
ModalSubmit = 2,
MessageComponent = 3
}
interface JobOptions {
name: string;
schedule: string;
runOnce?: boolean;
}
declare class Job implements JobOptions {
name: string;
schedule: string;
runOnce?: boolean;
scheduledJob?: Job$1;
constructor(options: JobOptions);
run?(client: MoodyClient): MaybePromise<unknown>;
init(client: MoodyClient): boolean;
}
interface ListenerOptions {
event: keyof ClientEvents;
name?: string;
once?: boolean;
}
declare abstract class Listener<E extends keyof ClientEvents = keyof ClientEvents> {
name: string;
event: string;
once: boolean;
private _listener;
constructor(options: ListenerOptions);
abstract run(client: MoodyClient, ...args: E extends keyof ClientEvents ? ClientEvents[E] : unknown[]): unknown;
private _run;
private _runOnce;
unload(client: MoodyClient): void;
}
type PreconditionResult = Awaitable<Result<unknown, PreconditionContext>>;
type AsyncPreconditionResult = Promise<Result<unknown, PreconditionContext>>;
interface PreconditionContext {
message: string;
identifier: string;
}
declare class Precondition {
chatInputRun?(context: CommandContext<ChatInputCommandInteraction>): MaybePromise<PreconditionResult>;
contextMenuRun?(context: CommandContext<ContextMenuCommandInteraction>): MaybePromise<PreconditionResult>;
ok(): _sapphire_result.Ok<unknown>;
error(context: PreconditionContext): _sapphire_result.Err<PreconditionContext>;
}
interface CommandOptions {
name: string;
description: string;
preconditions?: Precondition[];
category: string;
options?: ApplicationCommandOption[];
}
interface CommandContextOptions<Interaction extends InteractionTypes> {
interaction: Interaction;
client: MoodyClient;
author: User;
guild?: Guild;
}
type InteractionTypes = ChatInputCommandInteraction | ContextMenuCommandInteraction;
interface RegisterOptions {
guildId?: string;
commandIds?: string[];
}
type CommandData = RESTPostAPIChatInputApplicationCommandsJSONBody | RESTPostAPIContextMenuApplicationCommandsJSONBody;
declare class CommandRegistry {
name: string;
guildId?: string;
private globalCommandIds;
private guildCommandIds;
private chatInputCommands;
private contextMenuCommands;
private options;
constructor(name: string);
setOptions(options: RegisterOptions): void;
registerChatInputCommand(command: ChatInputApplicationCommandData | SlashCommandBuilder | SlashCommandSubcommandsOnlyBuilder | SlashCommandOptionsOnlyBuilder | Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'> | ((builder: SlashCommandBuilder) => unknown)): this;
registerContextMenuCommand(command: UserApplicationCommandData | MessageApplicationCommandData | ContextMenuCommandBuilder | ((builder: ContextMenuCommandBuilder) => unknown)): this;
initialize(globalCommands: Collection<string, ApplicationCommand>, client: MoodyClient): Promise<{
shouldGlobalDeploy: boolean;
shouldGuildDeploy: boolean;
allCommands: {
global: CommandData[];
guild: CommandData[];
};
}>;
}
declare const readablePermissions: Record<PermissionsString, string>;
declare const readableChannelTypes: Record<ChannelType, string>;
declare function normalizeChatInputCommand(command: ChatInputApplicationCommandData | SlashCommandBuilder | SlashCommandSubcommandsOnlyBuilder | SlashCommandOptionsOnlyBuilder | Omit<SlashCommandBuilder, 'addSubcommand' | 'addSubcommandGroup'> | ((builder: SlashCommandBuilder) => unknown)): RESTPostAPIChatInputApplicationCommandsJSONBody;
declare function normalizeContextMenuCommand(command: UserApplicationCommandData | MessageApplicationCommandData | ContextMenuCommandBuilder | ((builder: ContextMenuCommandBuilder) => unknown)): RESTPostAPIContextMenuApplicationCommandsJSONBody;
declare function transformOption(option: ApplicationCommandOptionData, received?: boolean): APIApplicationCommandOption;
declare function convertToApiData(command: ApplicationCommand): RESTPostAPIApplicationCommandsJSONBody;
declare function commandEquals(command1: RESTPostAPIApplicationCommandsJSONBody, command2: RESTPostAPIApplicationCommandsJSONBody): boolean;
declare class InteractionCreateListener extends Listener {
constructor();
run(client: MoodyClient, interaction: Interaction): Promise<void>;
}
declare class ReadyListener extends Listener<'ready'> {
constructor();
run(client: MoodyClient): Promise<void>;
}
declare class DeveloperOnly extends Precondition {
constructor();
sharedRun({ client, author }: CommandContext<ChatInputCommandInteraction | ContextMenuCommandInteraction>): Promise<_sapphire_result.Ok<unknown> | _sapphire_result.Err<PreconditionContext>>;
chatInputRun(context: CommandContext<ChatInputCommandInteraction>): Promise<_sapphire_result.Ok<unknown> | _sapphire_result.Err<PreconditionContext>>;
contextMenuRun(context: CommandContext<ContextMenuCommandInteraction>): Promise<_sapphire_result.Ok<unknown> | _sapphire_result.Err<PreconditionContext>>;
}
declare class UserPermissions extends Precondition {
permissions: PermissionResolvable;
constructor(permissions: PermissionResolvable);
chatInputRun({ interaction }: CommandContext<ChatInputCommandInteraction>): Promise<_sapphire_result.Ok<unknown> | _sapphire_result.Err<PreconditionContext>>;
contextMenuRun({ interaction }: CommandContext<ContextMenuCommandInteraction>): Promise<_sapphire_result.Ok<unknown> | _sapphire_result.Err<PreconditionContext>>;
}
declare class ChannelTypeOnly extends Precondition {
channelTypes: Exclude<ChannelType, ChannelType.DM | ChannelType.GroupDM>[];
constructor(channelTypes: Exclude<ChannelType, ChannelType.DM | ChannelType.GroupDM>[]);
sharedRun({ interaction }: CommandContext<ChatInputCommandInteraction | ContextMenuCommandInteraction>): Promise<_sapphire_result.Ok<unknown> | _sapphire_result.Err<PreconditionContext>>;
chatInputRun(context: CommandContext<ChatInputCommandInteraction>): Promise<_sapphire_result.Ok<unknown> | _sapphire_result.Err<PreconditionContext>>;
contextMenuRun(context: CommandContext<ContextMenuCommandInteraction>): Promise<_sapphire_result.Ok<unknown> | _sapphire_result.Err<PreconditionContext>>;
}
export { type AsyncPreconditionResult, ChannelTypeOnly, Command, CommandContext, type CommandContextOptions, type CommandData, type CommandOptions, CommandRegistry, Component, type ComponentOptions, ComponentType, DeveloperOnly, InteractionCreateListener, type InteractionTypes, Job, type JobOptions, Listener, type ListenerOptions, type MaybePromise, MoodyClient, type MoodyClientOptions, Precondition, type PreconditionContext, type PreconditionResult, ReadyListener, type RegisterOptions, UserPermissions, allGuildIdsToRegister, commandEquals, convertToApiData, createRegistry, normalizeChatInputCommand, normalizeContextMenuCommand, readableChannelTypes, readablePermissions, registries, transformOption };