UNPKG

commandbot

Version:

A framework that helps you create your own Discord bot easier.

249 lines (248 loc) 7.64 kB
import { CategoryChannel, Guild, GuildMember, Interaction, Message, NewsChannel, Role, StageChannel, StoreChannel, TextChannel, VoiceChannel } from "discord.js"; import { Command } from "../commands/base/Command.js"; /** * Parameter type values * - **string** - text value * - **boolean** - True or False * - **number** - number (double) value * @type */ export declare type ParameterType = "string" | "boolean" | "number" | ObjectIdType; /** * Input parameter value resolvable selector * @type */ export declare type InputParameterValue<T extends ParameterType> = T extends "string" ? string : T extends "boolean" ? boolean : T extends "number" ? number : T extends "user" ? ObjectID<"user"> : T extends "role" ? ObjectID<"role"> : T extends "channel" ? ObjectID<"channel"> : T extends "mentionable" ? ObjectID<"mentionable"> : never; /** * All parameter resolvables * @type */ export declare type ParameterResolvable = string | boolean | number | ObjectID<any> | TargetID<any> | null; /** * Properties required to build a {@link Parameter} object * @interface */ export interface ParameterSchema { /** * Parameter name * @type {string} */ name: string; /** * Parameter description * @type {?string} */ description?: string; /** * Whether this parameter is optional * @type {boolean} */ optional: boolean; /** * Type of parameter data * @type {ParameterType} */ type: ParameterType; /** * List of value choices * @type {?Array<string>} * @remarks Available only when type is set to "string" */ choices?: string[]; } /** * Types of Discord objects (IDs contained in an {@link ObjectID} wrapper) * - **user** - server users list shown as selection menu in Discord * - **role** - server roles list shown as selection menu in Discord * - **channel** - server text, voice, stage, and category channels list shown as selection menu in Discord * - **mentionable** - all objects that can be mentioned list shown as selection menu in Discord * @type */ export declare type ObjectIdType = "user" | "role" | "channel" | "mentionable"; /** * *ObjectID.prototype.toObject()* return type selector * @type */ export declare type ObjectIdReturnType<T extends ObjectIdType> = T extends "channel" ? TextChannel | VoiceChannel | CategoryChannel | NewsChannel | StageChannel | StoreChannel | null : T extends "user" ? GuildMember | null : T extends "role" ? Role | null : T extends "mentionable" ? TextChannel | VoiceChannel | CategoryChannel | NewsChannel | StageChannel | StoreChannel | GuildMember | Role | null : never; /** * Types of Discord context menu targets (IDs contained in a {@link TargetID} wrapper) * @type */ export declare type TargetType = "MESSAGE" | "USER"; /** * *TargetID.prototype.toObject()* return type selector * @type */ export declare type TargetIdReturnType<T extends TargetType> = T extends "USER" ? GuildMember : T extends "MESSAGE" ? Message : never; /** * Representation of command parameter * @class */ export declare class Parameter<T extends ParameterType> { /** * Command associated with this parameter * @type {Command} * @public * @readonly */ readonly command: Command; /** * Parameter name * @type {string} * @public * @readonly */ readonly name: string; /** * Parameter description * @type {string} * @public * @readonly */ readonly description: string; /** * Whether this parameter is optional * @type {boolean} * @public * @readonly */ readonly optional: boolean; /** * Parameter input type * @type {ParameterType} * @public * @readonly */ readonly type: T; /** * List of value choices (available only when type is set to "STRING") * @type {?Array<string>} * @public * @readonly */ readonly choices?: string[]; /** * Parameter name check regular expression * @type {RegExp} * @public * @static */ static nameRegExp: RegExp; /** * Parameter description check regular expression * @type {RegExp} * @public * @static */ static descriptionRegExp: RegExp; /** * @constructor * @param {Command} command - parameter parent command * @param {ParameterSchema} options - options used to compute a Parameter object */ constructor(command: Command, options: ParameterSchema); } export declare class DefaultParameter<T extends "string"> extends Parameter<T> { constructor(command: Command); } /** * Parameter with input value from interaction (reffered to as argument) * @class */ export declare class InputParameter<T extends ParameterType> extends Parameter<T> { /** * Value of an argument * @type {InputParameterValue<T>} * @public * @readonly */ readonly value: InputParameterValue<T>; /** * @constructor * @param {Parameter<T>} param - parent parameter * @param {?InputParameterValue<T>} value - input value */ constructor(param: Parameter<T>, value: InputParameterValue<T> | null); } /** * Wrapped representation of Discord user, role, channel or other mentionable Discord arugment object * @class */ export declare class ObjectID<T extends ObjectIdType> { /** * Object ID * @type {string} * @public * @readonly */ readonly id: string; /** * Guild needed to convert the object * @type {?Guild} * @public * @readonly */ readonly guild?: Guild; /** * Object type * @type {T} * @public * @readonly */ readonly type: T; /** * @constructor * @param {string} id - object Discord ID * @param {ObjectIdType} type - object type * @param {?Guild} [guild] - guild needed to convert the object */ constructor(id: string, type: T, guild?: Guild); /** * Uses informations associated with the object to generate a Discord.js representation * @returns {?Promise<ObjectIdReturnType<T>>} A fetched object (or null) * @public * @async */ toObject(): Promise<ObjectIdReturnType<T> | null>; } /** * Wrapped representation of Discord target object (target of context menu interactions) * @class */ export declare class TargetID<T extends TargetType> { /** * Object ID * @type {string} * @public * @readonly */ readonly id: string; /** * Interaction associated with the target * @type {Interaction | Message} * @public * @readonly */ readonly interaction: Interaction | Message; /** * Target type * @type {T} * @private * @readonly */ private readonly type; /** * @constructor * @param {string} id - object Discord ID * @param {TargetType} - target type * @param {Interaction | Message} [interaction] - interaction associated with the target */ constructor(id: string, type: T, interaction: Interaction | Message); /** * Uses informations associated with the object to generate a Discord.js representation * @returns {?Promise<TargetIdReturnType<T>>} A fetched object (or null) * @public * @async */ toObject(): TargetIdReturnType<T> | null; }