///
import { ClientOptions, Collection, Message, MessageEmbed, PresenceData } from 'discord.js';
import { EventEmitter } from 'events';
import { AdvancedClient, Command, CommandHandlerError, Event, Tag } from './';
export declare namespace CommandHandler {
/**
* The options for the default {@link HelpCommand | help} command.
*/
export interface HelpOptions {
/**
* Delete the help message after the delay, in seconds.
*/
deleteMessageAfterDelay?: number;
/**
* Exclude commands to the global help menu, exclude by name or alias.
*/
globalMenuExcludeCommands?: string[];
/**
* Use a list of commands instead of a list categories.
* Will only work for 25 commands max and throw an error if you use it with more commands.
*/
globalMenuUseList?: boolean;
}
/**
* The options for the default commands.
*/
interface DefaultCommandsOptions {
/**
* The default commands to exclude when loading the bot.
*/
exclude?: string[];
/**
* The options for the default {@link HelpCommand | help} command.
*/
helpOptions?: HelpOptions;
}
/**
* The options for the default {@link MessageCreateEvent | messageCreate} event.
*/
export interface MessageCreateOptions {
/**
* Exclude bot or not.
*
* @defaultValue true
*/
excludeBots?: boolean;
/**
* A list of global tags to apply before the commands is executed.
*/
globalTags?: Array;
/**
* Send the code error when a command execution is failed and an error is thrown.
*
* @defaultValue true
*/
sendCodeError?: boolean;
/**
* Send the code error only to owners when a command execution is failed and an error is thrown.
*
* @defaultValue true
*/
sendCodeErrorOnlyToOwners?: boolean;
/**
* A message to send to anyone (or not-owners if {@link sendCodeErrorOnlyToOwners} is set) when a command execution is failed and an error is thrown.
*/
sendWhenError?: MessageEmbed | string;
}
/**
* The options for the default events.
*/
interface DefaultEventsOptions {
/**
* The default events to exclude when loading the bot.
*/
exclude?: string[];
/**
* The options for the default {@link MessageCreateEvent | messageCreate} event.
*/
messageCreateOptions?: MessageCreateOptions;
}
/**
* The options for creating a new CommandHandler instance.
*/
export interface CreateCommandHandlerOptions {
/**
* The directory of your commands.
*/
commandsDir: string;
/**
* The directory of your events.
*/
eventsDir: string;
/**
* The owners IDs from discord of the bot.
*/
owners?: string[];
/**
* The prefixes for the CommandHandler.
*/
prefixes?: string[];
/**
* Save all the logs in these files.
*
* @remarks If one of the files is not found, it will create it.
*/
saveLogsInFile?: string[];
/**
* Add mention of the bot as prefixes.
*
* @defaultValue true
*/
useMentionAsPrefix?: boolean;
}
/**
* @internal
*/
export interface CommandCooldown {
/**
* The actual cooldown of the Command.
*/
cooldown: number;
/**
* The date the cooldown has started.
*/
executedAt: Date;
}
/**
* @internal
*/
export type CooldownUser = {
[k: string]: CommandCooldown;
};
/**
* Options for launching the CommandHandler.
*/
export interface LaunchCommandHandlerOptions {
/**
* Whether to add the bot owner or the team members (if bot is from a team) to the {@link owners}.
*
* @defaultValue true
*/
addBotAndTeamOwnersToOwners?: boolean;
/**
* The client options, see {@link https://discord.js.org/#/docs/main/stable/typedef/ClientOptions | ClientOptions}.
*/
clientOptions: ClientOptions;
/**
* If set to true, it will cycle between the {@link presences}.
*
* @defaultValue true
*/
cycleBetweenPresences?: boolean;
/**
* The duration in seconds between the cycle of two presences of {@link presences}.
*
* @defaultValue 60
*/
cycleDuration?: number;
/**
* The presence of your bot when launched.
*
* @remarks
* If {@link presences} is also set, it will overcome this property.
*/
presence?: PresenceData;
/**
* The presences of your bot, if this field is used it will cycle between all if {@link cycleBetweenPresences} options is set to true.
*
* @remarks
* If {@link presence} is also set, it will still cycle between presences.
*/
presences?: PresenceData[];
/**
* The token of your bot.
*/
token: string;
}
/**
* The CommandHandler events.
*
* @see {@link https://nodejs.org/api/events.html#events_class_eventemitter | EventEmitter}.
*/
export type CommandHandlerEvents = {
/**
* The event executed when creating the CommandHandler.
*/
create: [CreateCommandHandlerOptions];
/**
* The event executed when a CommandHandlerError is created.
*
* @remarks You need to add a listener to this event for every bots otherwise it will crash in some places with a weird error.
* @see {@link https://nodejs.org/api/errors.html#errors_err_unhandled_error}
*/
error: [CommandHandlerError];
/**
* The event executed when the CommandHandler starts its launch.
*/
launch: [LaunchCommandHandlerOptions];
/**
* The event executed when loading a Command.
*/
loadCommand: [Command];
/**
* The event executed when loading an Event.
*/
loadEvent: [Event];
/**
* The event executed when the CommandHandler has finished launching..
*/
launched: [];
};
/**
* The version of the handler.
*/
export const version: any;
/**
* The event emitter for the CommandHandler.
*
* @eventProperty
*/
export const emitter: EventEmitter;
/**
* The commands registered by the CommandHandler.
*/
export const commands: Collection;
/**
* The cooldowns mapped by ID and cooldown user.
*
* A simple explication :
* When a user executes a command with a cooldown, a new value is added.
* ```typescript
* [anyID]: {
* [commandName]: {
* executedAt: Date,
* cooldown: [command cooldown]
* }
* }
* ```
* So cooldowns are mapped by IDs (can be anything, user IDs recommended) then mapped by commands.
*/
export const cooldowns: Collection;
/**
* The events registered by the EventHandler.
*
* @remarks
* These events may not be bound to the {@link client}.
*/
export const events: Collection;
export let commandsDir: string;
export let eventsDir: string;
export let owners: string[];
export let prefixes: string[];
/**
* The client of the handler, null before {@link launch} function executed.
*/
export let client: AdvancedClient | null;
/**
* The interval of the cycling presences, undefined if you don't use it.
*/
export let presencesInterval: NodeJS.Timer;
/**
* Execute the event you want from the {@link emitter | listener} throughout the CommandHandler.
*
* @typeParam K - Event names of the CommandHandler listener.
* @param eventName - The event name.
* @param args - The arguments to pass.
*/
export function emit(eventName: K, ...args: CommandHandlerEvents[K]): void;
/**
* Adds a listener for the {@link eventName} event.
*
* @typeParam K - Event names of the CommandHandler listener.
* @param eventName - The event name.
* @param fn - The callback to execute.
*/
export function on(eventName: K, fn: (...args: CommandHandlerEvents[K]) => void): void;
/**
* Adds a one-time listener for the {@link eventName} event.
*
* @typeParam K - Event names of the CommandHandler listener.
* @param eventName - The event name.
* @param fn - The callback to execute.
*/
export function once(eventName: K, fn: (...args: CommandHandlerEvents[K]) => void): void;
/**
* Returns the list of names and aliases of all commands, useful to find a command by name.
*
* @returns - All the names and aliases in a flat array.
*/
export function getCommandAliasesAndNames(): string[];
/**
* Find a command by name or alias.
*
* @param name - The name or alias of the command.
* @returns - The command found or `undefined`.
*/
export function findCommand(name: string): Command | undefined;
/**
* Add the defaults events to your CommandHandler.
*
* @remarks
* Must use after {@link CommandHandler.create}.
* @see {@link https://ayfri.gitbook.io/advanced-command-handler/defaults | Default Events}
* @param options - The options for the default events.
* @returns - Itself so that afterward you can chain with other functions.
*/
export function useDefaultEvents(options?: DefaultEventsOptions): typeof CommandHandler;
/**
* Add the defaults commands to your CommandHandler.
*
* @remarks
* Must use after {@link CommandHandler.create}.
* @see {@link https://ayfri.gitbook.io/advanced-command-handler/defaults | Default Commands}
* @param options - The options for the default commands.
* @returns - Itself so that afterward you can chain with other functions.
*/
export function useDefaultCommands(options?: DefaultCommandsOptions): typeof CommandHandler;
/**
* Creates a new CommandHandler, wrap up the last one.
*
* @param options - Options for creating a new CommandHandler.
* @see {@link https://ayfri.gitbook.io/advanced-command-handler/concepts/command-handler#creating-your-commandhandler}
* @returns - Itself so that afterward you can chain with other functions.
*/
export function create(options: CreateCommandHandlerOptions): typeof CommandHandler;
/**
* Launches the CommandHandler, log in the client and load commands/events.
*
* @param options - Options for launching the CommandHandler, see {@link CreateCommandHandlerOptions}.
* @see {@link https://ayfri.gitbook.io/advanced-command-handler/concepts/command-handler#launching-the-commandhandler}
* @returns - Itself in a promise so that afterward you can chain with other functions.
*/
export function launch(options: LaunchCommandHandlerOptions): Promise;
/**
* Get the prefix from the prefixes defined in {@link CommandHandler.launch} or null.
*
* @param message - The message to get the prefix for.
* @returns - The prefix found or null if not.
*/
export function getPrefixFromMessage(message: Message): string | undefined;
/**
* Load a command from the directory & filename.
*
* @param path - The path of the command folder.
* @param name - The name of the command including the extension.
* @returns - The command itself.
*/
export function loadCommand(path: string, name: string): Promise;
/**
* Load all the commands from a directory.
*
* @remarks
* The path must be a directory containing sub-directories.
* @param path - The path of the directory to load the commands from.
*/
export function loadCommands(path: string): Promise;
/**
* Load an event from the directory and filename.
*
* @param path - The path of the event folder.
* @param name - The name of the event including the extension.
* @returns - The event itself.
*/
export function loadEvent(path: string, name: string): Promise;
/**
* Load all the events from a directory.
*
* @param path - The path of the directory to load the events from.
*/
export function loadEvents(path: string): Promise;
/**
* Unloads an event.
*
* @param name - The event to unload.
*/
export function unloadEvent(name: string): void;
/**
* Unloads a command.
*
* @param name - The command to unload.
*/
export function unloadCommand(name: string): void;
export {};
}