UNPKG

commandbot

Version:

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

112 lines (111 loc) 3.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.CommandNotFound = exports.OperationSuccess = exports.MissingParameterError = exports.ParameterTypeError = exports.PermissionsError = void 0; /** * Error indicating that a caller doesn't have enough permissions to execute a command * @class * @extends {Error} */ class PermissionsError extends Error { /** * @constructor * @param {Command} command - command that user wanted and failed to invoke * @param {?GuildMember} [user] - user that doesn't have the permissions */ constructor(command, user) { super(); this.command = command; this.user = user || null; } /** * Converts error object to user-readable message * @returns {string} Formatted error message * @public */ toString() { var _a; return `User ${(_a = this.user) === null || _a === void 0 ? void 0 : _a.user.tag} doesn't have enough permissions to run "${this.command.name}" command`; } } exports.PermissionsError = PermissionsError; /** * Error indicating that an input value cannot be converted to a expected type * @class * @extends {TypeError} */ class ParameterTypeError extends TypeError { /** * @constructor * @param {ParameterResolvable} s - value with an invalid type * @param {ParameterType} type - expected type */ constructor(s, type) { var _a; super(); this.stringContent = (_a = s === null || s === void 0 ? void 0 : s.toString()) !== null && _a !== void 0 ? _a : ""; this.type = type; } /** * Converts error object to user-readable message * @returns {string} Formatted error message * @public */ toString() { return `Parameter "${this.stringContent}" cannot be converted to ${this.type}`; } } exports.ParameterTypeError = ParameterTypeError; /** * Error indicating that a required parameter is missing in the request * @class * @extends {ReferenceError} */ class MissingParameterError extends ReferenceError { /** * @constructor * @param {Parameter<any>} a - missing parameter object */ constructor(a) { super(); this.argument = a; } /** * Converts error object to user-readable message * @returns {string} Formatted error message * @public */ toString() { return `Your request is missing a "${this.argument.name}" parameter which is not optional`; } } exports.MissingParameterError = MissingParameterError; /** * Object indicating command execution success * @class */ class OperationSuccess { /** * @constructor * @param {Command} c - command that succeeded */ constructor(c) { this.command = c; } } exports.OperationSuccess = OperationSuccess; /** * Error thrown when there is no command with the given name * @class * @extends {Error} */ class CommandNotFound extends Error { /** * @constructor * @param {?string} [q] - user query */ constructor(q) { super("Command not found"); this.query = q; } } exports.CommandNotFound = CommandNotFound;