From 1e3721b5daa711ecf4d5fdc53ce4715d8d840320 Mon Sep 17 00:00:00 2001 From: Isaac Date: Wed, 31 Mar 2021 22:12:30 +0100 Subject: [PATCH] do things --- .eslintrc.js | 16 +++++++++++----- src/commands/new.js | 8 ++------ src/locales/en-GB.json | 1 - src/modules/commands/command.js | 18 +++++++++++++----- src/modules/commands/manager.js | 9 ++++++--- src/utils/discord.js | 22 ---------------------- 6 files changed, 32 insertions(+), 42 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index 0338e65..e6c717b 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -1,23 +1,29 @@ module.exports = { 'env': { + 'commonjs': true, + 'es2021': true, 'node': true }, 'extends': 'eslint:recommended', 'parserOptions': { - 'ecmaVersion': 2021 + 'ecmaVersion': 12 }, 'rules': { 'indent': [ - 'warn', + 'error', 'tab' ], - 'quotes': [ + 'linebreak-style': [ 'warn', + 'windows' + ], + 'quotes': [ + 'error', 'single' ], 'semi': [ 'error', 'always' - ], + ] } -}; \ No newline at end of file +}; diff --git a/src/commands/new.js b/src/commands/new.js index dc0f9bd..71796d2 100644 --- a/src/commands/new.js +++ b/src/commands/new.js @@ -12,6 +12,7 @@ module.exports = class NewCommand extends Command { i18n('commands.new.aliases.open'), i18n('commands.new.aliases.create'), ], + process_args: false, args: [ { name: i18n('commands.new.args.category.name'), @@ -27,7 +28,7 @@ module.exports = class NewCommand extends Command { }); } - async execute(message, args, raw_args) { + async execute(message, args) { let settings = await message.guild.settings; const i18n = this.client.i18n.get(settings.locale); @@ -36,13 +37,8 @@ module.exports = class NewCommand extends Command { new MessageEmbed() .setColor(settings.colour) .setTitle(i18n('bot.version', require('../../package.json').version)) - .setDescription(args.topic) ); - // console.log(this.aliases) - // console.log(args.category) - // console.log(args.topic) - // this.client.tickets.create(message.guild.id, message.member.id, '825861413687787560', args.topic); } }; \ No newline at end of file diff --git a/src/locales/en-GB.json b/src/locales/en-GB.json index 919766c..f007495 100644 --- a/src/locales/en-GB.json +++ b/src/locales/en-GB.json @@ -32,7 +32,6 @@ } } }, - "must_be_slash": "❌ This command must be invoked by a slash command interaction (`/%s`).", "no_perm": "❌ You do not have the permissions required to use this command:\n%s", "staff_only": "❌ You must be a member of staff to use this command." } \ No newline at end of file diff --git a/src/modules/commands/command.js b/src/modules/commands/command.js index bf90c15..25e259d 100644 --- a/src/modules/commands/command.js +++ b/src/modules/commands/command.js @@ -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 }; \ No newline at end of file diff --git a/src/modules/commands/manager.js b/src/modules/commands/manager.js index ce81581..a99080f 100644 --- a/src/modules/commands/manager.js +++ b/src/modules/commands/manager.js @@ -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) { diff --git a/src/utils/discord.js b/src/utils/discord.js index f5bb8ac..8dd5e09 100644 --- a/src/utils/discord.js +++ b/src/utils/discord.js @@ -1,30 +1,8 @@ -const Discord = require('discord.js'); - const config = require('../../user/config'); let current_presence = -1; module.exports = { - /** - * Resolves data and files so embeds can be sent as a response to a slash command - * @param {Discord.Client} client - The Discord Client - * @param {string} channel_id - Text channel ID - * @param {*} content - Message content - * @returns {Object} - */ - createMessage: async (client, channel_id, content) => { - let msg = await Discord.APIMessage.create(client.channels.resolve(channel_id), content) - .resolveData() - .resolveFiles(); - return { ...msg.data, files: msg.files }; - }, - - /** - * Generate flags - * @param {boolean} secret - Ephemeral message? - */ - flags: (secret) => secret ? 1 << 64 : undefined, - /** * Select a presence from the config * @returns {Discord.PresenceData}