"help" command

This commit is contained in:
Isaac 2021-05-17 21:16:58 +01:00
parent 98c986e715
commit 37adac1dd0
No known key found for this signature in database
GPG Key ID: F6812DBC6719B4E3
14 changed files with 122 additions and 26 deletions

View File

@ -1,5 +1,6 @@
const Command = require('../modules/commands/command');
const { MessageEmbed } = require('discord.js');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
module.exports = class AddCommand extends Command {
constructor(client) {
@ -27,6 +28,11 @@ module.exports = class AddCommand extends Command {
});
}
/**
* @param {Message} message
* @param {string} args
* @returns {Promise<void|any>}
*/
async execute(message, args) {
let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale);

View File

@ -1,5 +1,6 @@
const Command = require('../modules/commands/command');
const { MessageEmbed } = require('discord.js');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
module.exports = class BlacklistCommand extends Command {
constructor(client) {
@ -24,6 +25,11 @@ module.exports = class BlacklistCommand extends Command {
});
}
/**
* @param {Message} message
* @param {string} args
* @returns {Promise<void|any>}
*/
async execute(message, args) {
let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale);

View File

@ -1,5 +1,6 @@
const Command = require('../modules/commands/command');
const { MessageEmbed, MessageMentions } = require('discord.js');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, MessageMentions, Message } = require('discord.js');
const { Op } = require('sequelize');
const toTime = require('to-time-monthsfork');
const { footer } = require('../utils/discord');
@ -48,6 +49,11 @@ module.exports = class CloseCommand extends Command {
});
}
/**
* @param {Message} message
* @param {*} args
* @returns {Promise<void|any>}
*/
async execute(message, args) {
const arg_ticket = this.args[0].name;
const arg_reason = this.args[1].name;

View File

@ -1,5 +1,6 @@
const Command = require('../modules/commands/command');
const { MessageEmbed } = require('discord.js');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
module.exports = class HelpCommand extends Command {
constructor(client) {
@ -24,8 +25,41 @@ module.exports = class HelpCommand extends Command {
});
}
/**
* @param {Message} message
* @param {string} args
* @returns {Promise<void|any>}
*/
async execute(message, args) {
let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale);
const cmd = this.manager.commands.find(command => command.aliases.includes(args.toLowerCase()));
if (cmd) {
return await cmd.sendUsage(message.channel, args);
} else {
let commands = this.manager.commands.filter(async command => {
if (command.permissions.length >= 1) return !message.member.hasPermission(command.permissions);
else if (command.staff_only) return await message.member.isStaff();
});
let list = commands.map(command => {
// let description = command.description;
let description = command.description.length > 50
? command.description.substring(0, 50) + '...'
: command.description;
return `**\`${settings.command_prefix}${command.name}\` ·** ${description}`;
});
return await message.channel.send(
new MessageEmbed()
.setColor(settings.colour)
.setTitle(i18n('commands.help.response.list.title'))
.setDescription(i18n('commands.help.response.list.description', {
prefix: settings.command_prefix,
}))
.addField(i18n('commands.help.response.list.fields.commands'), list.join('\n'))
.setFooter(settings.footer, message.guild.iconURL())
);
}
}
};

View File

@ -1,5 +1,6 @@
const Command = require('../modules/commands/command');
const { MessageEmbed } = require('discord.js');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
const { footer } = require('../utils/discord');
const { letters } = require('../utils/emoji');
const { wait } = require('../utils');
@ -28,6 +29,11 @@ module.exports = class NewCommand extends Command {
});
}
/**
* @param {Message} message
* @param {string} args
* @returns {Promise<void|any>}
*/
async execute(message, args) {
let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale);

View File

@ -1,5 +1,6 @@
const Command = require('../modules/commands/command');
const { MessageEmbed } = require('discord.js');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
const { some, wait } = require('../utils');
const { emojify } = require('node-emoji');
@ -56,6 +57,11 @@ module.exports = class PanelCommand extends Command {
});
}
/**
* @param {Message} message
* @param {*} args
* @returns {Promise<void|any>}
*/
async execute(message, args) {
// localised command and arg names are a pain
const arg_title = this.args[0].name;

View File

@ -1,5 +1,6 @@
const Command = require('../modules/commands/command');
const { MessageEmbed } = require('discord.js');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
module.exports = class RemoveCommand extends Command {
constructor(client) {
@ -27,6 +28,11 @@ module.exports = class RemoveCommand extends Command {
});
}
/**
* @param {Message} message
* @param {string} args
* @returns {Promise<void|any>}
*/
async execute(message, args) {
let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale);

View File

@ -26,7 +26,7 @@ module.exports = class SettingsCommand extends Command {
/**
* @param {Message} message
* @param {*} args
* @param {string} args
* @returns {Promise<void|any>}
*/
async execute(message) {

View File

@ -1,6 +1,7 @@
const Command = require('../modules/commands/command');
const Keyv = require('keyv');
const { MessageEmbed } = require('discord.js');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
module.exports = class StatsCommand extends Command {
constructor(client) {
@ -20,6 +21,11 @@ module.exports = class StatsCommand extends Command {
});
}
/**
* @param {Message} message
* @param {string} args
* @returns {Promise<void|any>}
*/
async execute(message) {
let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale);
@ -34,7 +40,6 @@ module.exports = class StatsCommand extends Command {
guild: message.guild.id
}
});
stats = { // maths
tickets: tickets.count,
messages: settings.log_messages

View File

@ -1,5 +1,6 @@
const Command = require('../modules/commands/command');
const { MessageEmbed } = require('discord.js');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
module.exports = class TopicCommand extends Command {
constructor(client) {
@ -21,6 +22,11 @@ module.exports = class TopicCommand extends Command {
});
}
/**
* @param {Message} message
* @param {string} args
* @returns {Promise<void|any>}
*/
async execute(message, args) {
let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale);

View File

@ -181,7 +181,7 @@
"commands": "commands"
},
"args": {
"member": {
"command": {
"description": "The command to display information about",
"example": "new",
"name": "command"
@ -189,7 +189,15 @@
},
"description": "List commands you have access to, or find out more about a command",
"name": "help",
"response": {}
"response": {
"list": {
"description": "The commands you have access to are listed below. For more information about a command, type `{prefix}help [command]`.To create a ticket, type `{prefix}new [topic]`.",
"fields": {
"commands": "Commands"
},
"title": "❔ Help"
}
}
},
"new": {
"aliases": {

View File

@ -1,4 +1,5 @@
const { MessageEmbed } = require('discord.js');
// eslint-disable-next-line no-unused-vars
const { MessageEmbed, Message } = require('discord.js');
/**
* A command
@ -66,7 +67,7 @@ module.exports = class Command {
* Array of permissions needed for a user to use this command
* @type {string[]}
*/
this.permissions = data.permissions;
this.permissions = data.permissions ?? [];
/**
* Should the command handler process named arguments?
@ -115,12 +116,12 @@ module.exports = class Command {
/**
* Send a message with the command usage
* @param {TextChannel} channel - The channel to send the message to
* @param {string} [cmd_name] - The command alias
* @param {string} [alias] - The command alias
* @returns {Message}
*/
async sendUsage(channel, cmd_name) {
async sendUsage(channel, alias) {
let settings = await channel.guild.settings;
if (!cmd_name) cmd_name = this.name;
if (!alias) alias = this.name;
const prefix = settings.command_prefix;
const i18n = this.client.i18n.getLocale(settings.locale);
@ -137,18 +138,18 @@ module.exports = class Command {
embed;
if (this.process_args) {
usage = `${prefix + cmd_name} ${this.args.map(arg => arg.required ? `<${arg.name}>` : `[${arg.name}]`).join(' ')}`;
example = `${prefix + cmd_name} \n${this.args.map(arg => `--${arg.name} ${arg.example || ''}`).join('\n')}`;
usage = `${prefix + alias} ${this.args.map(arg => arg.required ? `<${arg.name}>` : `[${arg.name}]`).join(' ')}`;
example = `${prefix + alias} \n${this.args.map(arg => `--${arg.name} ${arg.example || ''}`).join('\n')}`;
embed = new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('cmd_usage.title', cmd_name))
.setTitle(i18n('cmd_usage.title', alias))
.setDescription(i18n('cmd_usage.named_args') + i18n('cmd_usage.description', usage, example));
} else {
usage = `${prefix + cmd_name} ${this.args.map(arg => arg.required ? `<${arg.name}>` : `[${arg.name}]`).join(' ')}`;
example = `${prefix + cmd_name} ${this.args.map(arg => `${arg.example || ''}`).join(' ')}`;
usage = `${prefix + alias} ${this.args.map(arg => arg.required ? `<${arg.name}>` : `[${arg.name}]`).join(' ')}`;
example = `${prefix + alias} ${this.args.map(arg => `${arg.example || ''}`).join(' ')}`;
embed = new MessageEmbed()
.setColor(settings.error_colour)
.setTitle(i18n('cmd_usage.title', cmd_name))
.setTitle(i18n('cmd_usage.title', alias))
.setDescription(i18n('cmd_usage.description', usage, example));
}

View File

@ -19,7 +19,10 @@ module.exports = class CommandManager {
/** The Discord Client */
this.client = client;
/** A discord.js Collection (Map) of loaded commands */
/**
* A discord.js Collection (Map) of loaded commands
* @type {Collection<string, import('./command')>}
*/
this.commands = new Collection();
}

View File

@ -15,7 +15,10 @@ module.exports = class PluginManager {
/** The Discord Client */
this.client = client;
/** A discord.js Collection (Map) of loaded plugins */
/**
* A discord.js Collection (Map) of loaded plugins
* @type {Collection<string, import('./plugin')>}
*/
this.plugins = new Collection();
/** Array of official plugins to be used to check if a plugin is official */