Merge pull request #12 from jondeaves/help-improve

feat: added improved help command with proper listing, alterantive co…
This commit is contained in:
Lance Krasniqi
2020-08-12 22:45:27 +02:00
committed by GitHub
4 changed files with 33 additions and 13 deletions

View File

@@ -4,5 +4,6 @@ export default interface ICommand {
name: string;
aliases?: string[];
description: string;
example?: string;
execute: (message: Discord.Message, args: string[], prefix?: string, commands?: Collection<string, ICommand>) => Promise<void>,
}

View File

@@ -1,18 +1,35 @@
import Discord, { Collection } from 'discord.js';
import ICommand from './ICommand';
import ConfigService from '../../core/services/config.service'
import container from '../../inversity.config';
const prefix = container.resolve<ConfigService>(ConfigService).get('BOT_TRIGGER');
const command: ICommand = {
name: 'help',
aliases: ['commands'],
description: 'Lists available commands.',
example: `\`${prefix}help ping\``,
description: 'Lists available commands!',
async execute(message: Discord.Message, args: string[], prefix: string, commands: Collection<string, ICommand>) {
const data = [];
if (!args.length) {
// Get for all commands
data.push('Here\'s a list of all my commands:\n');
data.push(commands.map(command => command.name).join(', '));
data.push('here\'s a list of all my commands:\n');
const cmds = commands.map(command => command.name);
let cmd;
cmds.forEach(element => {
cmd = commands.get(element) || commands.find(c => c.aliases && c.aliases.includes(element));
let response = `\`${prefix}${cmd.name}\` `;
if (cmd.description) {
response += `**${cmd.description}** `;
}
if (cmd.aliases) {
response += `\n\t\t\t*alternatively:* \`${prefix}${cmd.aliases.join(`\`, \`${prefix}`)}\``;
}
data.push(response);
data.push(cmd.example ? `\t\t\t*for example:* ${cmd.example}\n` : '');
});
data.push(`\nYou can send \`${prefix}help [command name]\` to get info on a specific command!`);
} else {
// Get description of single command
@@ -29,13 +46,12 @@ const command: ICommand = {
}
}
try {
await message.author.send(data, { split: true });
if (message.channel.type === 'dm')
return;
message.reply('I\'ve sent you a DM with all my commands!');
//await message.author.send(data, { split: true });
//if (message.channel.type === 'dm')
// return;
// message.reply('I\'ve sent you a DM with all my commands!');
message.reply(data, { split: true })
}
catch (error) {
console.error(`Could not send help DM to ${message.author.tag}.\n`, error);

View File

@@ -1,13 +1,12 @@
import Discord from 'discord.js';
import ICommand from './ICommand';
const command: ICommand = {
name: 'ping',
aliases: ['hello'],
aliases: ['hello', 'hi'],
description: 'Responds, kind of like telling you the bot is alive.',
async execute(message: Discord.Message, args: string[]) {
message.reply('Pong.');
message.reply('Pong!');
},
};

View File

@@ -1,9 +1,13 @@
import Discord from 'discord.js';
import ICommand from './ICommand';
import ConfigService from '../../core/services/config.service'
import container from '../../inversity.config';
const prefix = container.resolve<ConfigService>(ConfigService).get('BOT_TRIGGER');
const command: ICommand = {
name: 'see',
example: `\`${prefix}see\``,
description: 'Sends a DM telling you information about your user on given server.',
async execute(message: Discord.Message, args: string[]) {
message.author.send(`Server: ${message.guild.name}\nYour username: ${message.author.username}\nYour ID: ${message.author.id}`);