UNPKG

@biskyjs/framework

Version:
132 lines 4.59 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Command = void 0; const command_1 = require("../interfaces/command"); const args_1 = require("../parsers/args"); const flag_unordered_strategy_1 = require("../strategies/flag-unordered-strategy"); const lexure_1 = require("@sapphire/lexure"); const pieces_1 = require("@sapphire/pieces"); class Command extends pieces_1.AliasPiece { constructor(context, options) { super(context, options); /** * Command description. */ Object.defineProperty(this, "description", { enumerable: true, configurable: true, writable: true, value: void 0 }); /** * Extra data for the command, such as help, more information, etc. Useful for help commands. * TypeScript users can augment the CommandMetadata interface to add their own data. * @see [TypeScript Augment](https://www.typescriptlang.org/docs/handbook/declaration-merging.html) */ Object.defineProperty(this, "metadata", { enumerable: true, configurable: true, writable: true, value: void 0 }); /** * Command category. * The command category can be used to categorize the commands in a help command, etc. */ Object.defineProperty(this, "category", { enumerable: true, configurable: true, writable: true, value: void 0 }); /** * The strategy to use for the lexer. */ Object.defineProperty(this, "strategy", { enumerable: true, configurable: true, writable: true, value: void 0 }); /** * Mark commands as NSFW. */ Object.defineProperty(this, "nsfw", { enumerable: true, configurable: true, writable: true, value: void 0 }); /** * Client Permissions * Permissions that the clientr (bot) needs to execute the action. */ Object.defineProperty(this, "clientPermissions", { enumerable: true, configurable: true, writable: true, value: void 0 }); /** * User Permissions * Permissions that the user (author of message) needs to execute the action. */ Object.defineProperty(this, "userPermissions", { enumerable: true, configurable: true, writable: true, value: void 0 }); /** * The lexer to be used for command parsing * @private */ Object.defineProperty(this, "lexer", { enumerable: true, configurable: true, writable: true, value: void 0 }); this.description = options.description; this.metadata = options.metadata; this.nsfw = options.nsfw ?? false; this.clientPermissions = options.clientPermissions; this.strategy = new flag_unordered_strategy_1.FlagUnorderedStrategy(options); this.lexer = new lexure_1.Lexer({ quotes: options.quotes ?? [ ['"', '"'], ["“", "”"], ["「", "」"], ["«", "»"] // French quotes (guillemets) ] }); if (options.category) this.category = options.category; else this.category = this.location.directories.length > 0 ? this.location.directories[0] : null; } toJSON() { return { ...super.toJSON(), description: this.description ?? null, category: this.description ?? null, metadata: this.metadata ?? {} }; } /** * The pre-parse method. This method can be overridden by plugins to define their own argument parser. * @param message The message that triggered the command. * @param parameters The raw parameters as a single string. */ preParse(message, parameters, context) { const parser = new lexure_1.Parser(this.strategy); const args = new lexure_1.ArgumentStream(parser.run(this.lexer.run(parameters))); // rome-ignore lint/suspicious/noExplicitAny: no return new args_1.Args(message, this, args, context); } } exports.Command = Command; //# sourceMappingURL=command.js.map