UNPKG

@beni69/cmd

Version:

The command handler from my discord bot

124 lines 4.36 kB
/// <reference types="node" /> import { Client, Collection, ColorResolvable, EmojiIdentifierResolvable, MessageEmbed, Snowflake } from "discord.js"; import EventEmitter from "events"; import Command from "./Command"; import { HelpSettings } from "./HelpCommand"; import { Logger, LoggerOptions } from "./Logging"; import Trigger from "./Trigger"; export interface Handler { on<U extends keyof HandlerEvents>(event: U, listener: HandlerEvents[U]): this; emit<U extends keyof HandlerEvents>(event: U, ...args: Parameters<HandlerEvents[U]>): boolean; } export declare class Handler extends EventEmitter { readonly client: Client<boolean>; commands: Commands; private commandsDir; private opts; private listening; readonly v: boolean; private db; private paused; private logger?; /** * Create a new command handler * @param {HandlerConstructor} opts - Put all options in this object. Only the client, prefix and commands directory are requred, everthing else is optional. */ constructor({ client, prefix, commandsDir, verbose, admins, testServers, triggers, helpCommand, logging: loggerOptions, mongodb, blacklist, pauseCommand, ignoreBots, testMode, }: HandlerConstructor); get isPaused(): boolean; set pause(v: boolean); get getOpts(): HandlerOpions; get getCommands(): Commands; get getLogger(): Logger | undefined; /** * **This will be called internally, you dont have to run this yourself** * Recursively reads a directory and loads all .js and .ts files * (if these files don't export a command they will just be ignored) * @param {string} dir - The directory to use */ loadCommands(dir: string): Promise<void>; /** * Listen for messages */ private listen; /** * Validate whether a user can execute a command in the provided context */ validateCommand(trigger: Trigger): Promise<true | undefined>; /** * Execute a command. * (this is the function used internally for launching the commands) * @param {Trigger} trigger - The trigger that lauhched the command * @returns true if successful, false if command falied */ executeCommand(trigger: Trigger): Promise<boolean>; /** * Find a command from any of its aliases * (this is the function used internally for finding commands) * @param {string} name - Name or names of a command * @returns The command or undefined if no command was found */ getCommand(name: string | string[]): Command | undefined; /** * Connect to the database (for cooldowns) * @param {string} uri - MongoDB connection string */ private dbConnect; private Error; /** * A utility function to create nice embeds. * @param title * @param desc * @param color * @param thumbnail */ makeEmbed(title: string, desc: string, color?: ColorResolvable, thumbnail?: string): MessageEmbed; } export default Handler; export declare type Commands = Collection<string, Command>; export declare type HandlerOpions = { prefix: string; admins: Set<Snowflake>; testServers: Set<Snowflake>; triggers: Collection<string, EmojiIdentifierResolvable>; helpCommand?: HelpSettings; blacklist: Array<Snowflake>; pauseCommand?: string; ignoreBots?: boolean; testMode?: boolean; forceRegister?: boolean; errMsg?: { tooFewArgs?: string; tooManyArgs?: string; noAdmin?: string; cooldown?: string; globalCooldown?: string; blacklist?: string; noDM?: string; }; }; export declare type HandlerConstructor = { readonly client: Client; prefix: string; commandsDir: string; verbose?: boolean; admins?: Array<Snowflake>; testServers?: Array<Snowflake>; triggers?: Array<Array<string>>; helpCommand?: HelpSettings; logging?: LoggerOptions; mongodb?: string; blacklist?: Array<Snowflake>; pauseCommand?: string; ignoreBots?: boolean; testMode?: boolean; forceRegister?: boolean; }; export declare type HandlerEvents = { ready: () => void; dbConnected: () => void; dbConnectFailed: (err: unknown) => void; dbSynced: () => void; }; export interface HandlerError extends Error { } //# sourceMappingURL=Handler.d.ts.map