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

@ -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'
],
]
}
};

View File

@ -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);
}
};

View File

@ -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."
}

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}
* @default false
*/
this.staff_only = data.staff_only;
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 args = raw_args;
if (cmd.process_args) {
args = {};
let data = [...raw_args.matchAll(/(\w+)\??\s?:\s?(["`'](.*)["`'];|[\w<>@!#]+)/gmi)];
let args = {};
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) {

View File

@ -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}