Skip to content

Commit

Permalink
refactor: Use arguments for default help command.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayfri committed Sep 3, 2021
1 parent d868480 commit 05039b9
Showing 1 changed file with 8 additions and 17 deletions.
25 changes: 8 additions & 17 deletions src/defaults/commands/HelpCommand.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import dayjs from 'dayjs';
import durationPlugin from 'dayjs/plugin/duration';
import {BetterEmbed} from 'discord.js-better-embed';
import {CommandHandler} from '../../';
import {commandArgument, CommandHandler} from '../../';
import {Command, CommandContext, Tag} from '../../classes';

dayjs.extend(durationPlugin);
Expand All @@ -26,13 +26,17 @@ function groupBy<T, K extends keyof any>(array: T[], predicate: (item: T) => K):

export class HelpCommand extends Command {
override aliases = ['h'];
override arguments = {
command: commandArgument({optional: true}),
};
override category = 'utils';
override description = 'Get the list of commands or more information for one.';
override name = 'help';
override usage = 'help\nhelp <command>';

public override async run(ctx: CommandContext) {
if (!ctx.isCallingASubCommand) await HelpCommand.sendGlobalHelp(ctx);
const command = await ctx.argument<Command>('command');
if (command) await HelpCommand.sendCommandHelp(ctx, command);
else await HelpCommand.sendGlobalHelp(ctx);
}

public static async sendGlobalHelp(ctx: CommandContext) {
Expand Down Expand Up @@ -76,14 +80,7 @@ export class HelpCommand extends Command {
});

if (command.usage) embed.addField('Usage :', command.usage);
else
embed.addField(
'Syntax :',
command.signatures({
showDefaultValues: true,
showTypes: true,
})
);
else embed.addField('Syntax :', command.signatures({showDefaultValues: true}));
if (command.aliases) embed.addField('Aliases : ', `\`${command.aliases.sort().join('\n')}\``);
if (command.tags)
embed.addField(
Expand Down Expand Up @@ -117,11 +114,5 @@ export class HelpCommand extends Command {
},
HelpCommand.sendGlobalHelp
);

CommandHandler.commands.forEach(c => {
this.subCommand(c.name, {aliases: c.aliases}, async ctx => {
await HelpCommand.sendCommandHelp(ctx, c);
});
});
}
}

0 comments on commit 05039b9

Please sign in to comment.