Skip to content

Commit

Permalink
feat: Add arguments property in Command & SubCommand classes.
Browse files Browse the repository at this point in the history
  • Loading branch information
Ayfri committed Aug 31, 2021
1 parent 0b0fd99 commit bafdfef
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/classes/commands/Command.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {GuildChannel, GuildMember, Message, Permissions, PermissionString, Snowflake, TextChannel, User} from 'discord.js';
import {CommandHandler} from '../../CommandHandler';
import {isOwner, isPermission, Logger} from '../../utils';
import {Argument} from '../arguments';
import {CommandContext, SubCommandContext} from '../contexts';
import {CommandError, CommandErrorBuilder, CommandErrorType} from '../errors';
import {RunSubCommandFunction, SubCommandOptions} from './SubCommand';
Expand Down Expand Up @@ -110,6 +111,7 @@ export abstract class Command {
* The aliases of the command.
*/
public aliases?: string[];
public arguments: Record<string, Argument<any>> = {};
/**
* The category of the command.
*
Expand Down Expand Up @@ -223,9 +225,9 @@ export abstract class Command {

await this.run(ctx);
for (const subCommand of this.subCommands) {
if (subCommand.nameAndAliases.includes([...ctx.args].splice(0, subCommand.name.split(' ').length).join(' '))) {
if (subCommand.nameAndAliases.includes([...ctx.rawArgs].splice(0, subCommand.name.split(' ').length).join(' '))) {
ctx = new SubCommandContext({
args: ctx.args.slice(subCommand.name.split(' ').length),
rawArgs: ctx.rawArgs.slice(subCommand.name.split(' ').length),
command: this,
message: ctx.message,
handler: ctx.handler,
Expand Down Expand Up @@ -272,7 +274,7 @@ export abstract class Command {
/**
* Returns the missing permissions from the client & user for a context.
*
* @param ctx - The context to check permissions for.
* @param ctx - The context to validate permissions for.
* @returns - The missing permissions.
*/
public getMissingPermissions(ctx: CommandContext) {
Expand Down Expand Up @@ -490,6 +492,7 @@ export class SubCommand extends Command {
this.description = options.description;
this.tags = options.tags;
this.usage = options.usage;
this.arguments = options.arguments ?? {};
this.runFunction = runFunction;
}
}
3 changes: 3 additions & 0 deletions src/classes/commands/SubCommand.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// Note : The SubCommand class is in the Command.ts file, see the class to know why.

import {Argument} from '../arguments';
import {SubCommandContext} from '../contexts';
import {Tag} from './Command';

Expand All @@ -13,6 +14,8 @@ export interface SubCommandOptions {
* The aliases of the SubCommand.
*/
aliases?: string[];

arguments?: Record<string, Argument<any>>;
/**
* The channels where the SubCommand can be executed.
*/
Expand Down

0 comments on commit bafdfef

Please sign in to comment.