"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 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 { module.exports = class AddCommand extends Command {
constructor(client) { 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) { async execute(message, args) {
let settings = await message.guild.settings; let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);

View File

@ -1,5 +1,6 @@
const Command = require('../modules/commands/command'); 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 { module.exports = class BlacklistCommand extends Command {
constructor(client) { 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) { async execute(message, args) {
let settings = await message.guild.settings; let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);

View File

@ -1,5 +1,6 @@
const Command = require('../modules/commands/command'); 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 { Op } = require('sequelize');
const toTime = require('to-time-monthsfork'); const toTime = require('to-time-monthsfork');
const { footer } = require('../utils/discord'); 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) { async execute(message, args) {
const arg_ticket = this.args[0].name; const arg_ticket = this.args[0].name;
const arg_reason = this.args[1].name; const arg_reason = this.args[1].name;

View File

@ -1,5 +1,6 @@
const Command = require('../modules/commands/command'); 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 { module.exports = class HelpCommand extends Command {
constructor(client) { 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) { async execute(message, args) {
let settings = await message.guild.settings; let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); 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 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 { footer } = require('../utils/discord');
const { letters } = require('../utils/emoji'); const { letters } = require('../utils/emoji');
const { wait } = require('../utils'); 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) { async execute(message, args) {
let settings = await message.guild.settings; let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);

View File

@ -1,5 +1,6 @@
const Command = require('../modules/commands/command'); 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 { some, wait } = require('../utils');
const { emojify } = require('node-emoji'); 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) { async execute(message, args) {
// localised command and arg names are a pain // localised command and arg names are a pain
const arg_title = this.args[0].name; const arg_title = this.args[0].name;

View File

@ -1,5 +1,6 @@
const Command = require('../modules/commands/command'); 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 { module.exports = class RemoveCommand extends Command {
constructor(client) { 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) { async execute(message, args) {
let settings = await message.guild.settings; let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);

View File

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

View File

@ -1,6 +1,7 @@
const Command = require('../modules/commands/command'); const Command = require('../modules/commands/command');
const Keyv = require('keyv'); 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 { module.exports = class StatsCommand extends Command {
constructor(client) { 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) { async execute(message) {
let settings = await message.guild.settings; let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
@ -34,7 +40,6 @@ module.exports = class StatsCommand extends Command {
guild: message.guild.id guild: message.guild.id
} }
}); });
stats = { // maths stats = { // maths
tickets: tickets.count, tickets: tickets.count,
messages: settings.log_messages messages: settings.log_messages

View File

@ -1,5 +1,6 @@
const Command = require('../modules/commands/command'); 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 { module.exports = class TopicCommand extends Command {
constructor(client) { 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) { async execute(message, args) {
let settings = await message.guild.settings; let settings = await message.guild.settings;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);

View File

@ -181,7 +181,7 @@
"commands": "commands" "commands": "commands"
}, },
"args": { "args": {
"member": { "command": {
"description": "The command to display information about", "description": "The command to display information about",
"example": "new", "example": "new",
"name": "command" "name": "command"
@ -189,7 +189,15 @@
}, },
"description": "List commands you have access to, or find out more about a command", "description": "List commands you have access to, or find out more about a command",
"name": "help", "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": { "new": {
"aliases": { "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 * A command
@ -66,7 +67,7 @@ module.exports = class Command {
* Array of permissions needed for a user to use this command * Array of permissions needed for a user to use this command
* @type {string[]} * @type {string[]}
*/ */
this.permissions = data.permissions; this.permissions = data.permissions ?? [];
/** /**
* Should the command handler process named arguments? * Should the command handler process named arguments?
@ -115,12 +116,12 @@ module.exports = class Command {
/** /**
* Send a message with the command usage * Send a message with the command usage
* @param {TextChannel} channel - The channel to send the message to * @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} * @returns {Message}
*/ */
async sendUsage(channel, cmd_name) { async sendUsage(channel, alias) {
let settings = await channel.guild.settings; let settings = await channel.guild.settings;
if (!cmd_name) cmd_name = this.name; if (!alias) alias = this.name;
const prefix = settings.command_prefix; const prefix = settings.command_prefix;
const i18n = this.client.i18n.getLocale(settings.locale); const i18n = this.client.i18n.getLocale(settings.locale);
@ -137,18 +138,18 @@ module.exports = class Command {
embed; embed;
if (this.process_args) { if (this.process_args) {
usage = `${prefix + cmd_name} ${this.args.map(arg => arg.required ? `<${arg.name}>` : `[${arg.name}]`).join(' ')}`; usage = `${prefix + alias} ${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')}`; example = `${prefix + alias} \n${this.args.map(arg => `--${arg.name} ${arg.example || ''}`).join('\n')}`;
embed = new MessageEmbed() embed = new MessageEmbed()
.setColor(settings.error_colour) .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)); .setDescription(i18n('cmd_usage.named_args') + i18n('cmd_usage.description', usage, example));
} else { } else {
usage = `${prefix + cmd_name} ${this.args.map(arg => arg.required ? `<${arg.name}>` : `[${arg.name}]`).join(' ')}`; usage = `${prefix + alias} ${this.args.map(arg => arg.required ? `<${arg.name}>` : `[${arg.name}]`).join(' ')}`;
example = `${prefix + cmd_name} ${this.args.map(arg => `${arg.example || ''}`).join(' ')}`; example = `${prefix + alias} ${this.args.map(arg => `${arg.example || ''}`).join(' ')}`;
embed = new MessageEmbed() embed = new MessageEmbed()
.setColor(settings.error_colour) .setColor(settings.error_colour)
.setTitle(i18n('cmd_usage.title', cmd_name)) .setTitle(i18n('cmd_usage.title', alias))
.setDescription(i18n('cmd_usage.description', usage, example)); .setDescription(i18n('cmd_usage.description', usage, example));
} }

View File

@ -19,7 +19,10 @@ module.exports = class CommandManager {
/** The Discord Client */ /** The Discord Client */
this.client = 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(); this.commands = new Collection();
} }

View File

@ -15,7 +15,10 @@ module.exports = class PluginManager {
/** The Discord Client */ /** The Discord Client */
this.client = 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(); this.plugins = new Collection();
/** Array of official plugins to be used to check if a plugin is official */ /** Array of official plugins to be used to check if a plugin is official */