do things

This commit is contained in:
Isaac
2021-03-31 22:12:30 +01:00
parent 591cc6e0a6
commit 1e3721b5da
6 changed files with 32 additions and 42 deletions

View File

@@ -8,9 +8,9 @@ module.exports = class Command {
* @param {Object} data - Command data
* @param {string} data.name - The name of the command (3-32)
* @param {string} data.description - The description of the command (1-100)
* @param {boolean} [data.slash] - Register as a slash command? **Defaults to `true`**
* @param {boolean} [data.staff_only] - Only allow staff to use this command?
* @param {string[]} [data.permissions] - Array of permissions needed for a user to use this command
* @param {boolean} [data.process_args] - Should the command handler process named arguments?
* @param {CommandArgument[]} [data.args] - The command's arguments
*/
constructor(client, data) {
@@ -48,8 +48,9 @@ module.exports = class Command {
/**
* Only allow staff to use this command?
* @type {boolean}
*/
this.staff_only = data.staff_only;
* @default false
*/
this.staff_only = data.staff_only === true ? true : false;
/**
* Array of permissions needed for a user to use this command
@@ -57,6 +58,13 @@ module.exports = class Command {
*/
this.permissions = data.permissions;
/**
* Should the command handler process named arguments?
* @type {boolean}
* @default false
*/
this.process_args = data.process_args === true ? true : false;
/**
* The command options
* @type {CommandArgument[]}
@@ -90,8 +98,8 @@ module.exports = class Command {
* The code to be executed when a command is invoked
* @abstract
* @param {Message} message - The message that invoked this command
* @param {object?} args - Command arguments
* @param {(object|string)?} args - Named command arguments, or the message content with the prefix and command removed
*/
async execute(message, args) { }
async execute(message, args) { } // eslint-disable-line no-unused-vars
};

View File

@@ -81,9 +81,12 @@ module.exports = class CommandManager {
const cmd = this.commands.find(cmd => cmd.aliases.includes(cmd_name));
if (!cmd);
let data = [ ...raw_args.matchAll(/(\w+)\??\s?:\s?(["`'](.*)["`'];|[\w<>@!#]+)/gmi) ];
let args = {};
data.forEach(arg => args[arg[1]] = arg[3] || arg[2]);
let args = raw_args;
if (cmd.process_args) {
args = {};
let data = [...raw_args.matchAll(/(\w+)\??\s?:\s?(["`'](.*)["`'];|[\w<>@!#]+)/gmi)];
data.forEach(arg => args[arg[1]] = arg[3] || arg[2]);
}
const no_perm = cmd.permissions instanceof Array && !message.member.hasPermission(cmd.permissions);
if (no_perm) {