From 840619d7c5cca1546af0aa0b4a85a7125f2d3953 Mon Sep 17 00:00:00 2001 From: Jacob Nguyen <76754747+jacoobes@users.noreply.github.com> Date: Sat, 12 Mar 2022 00:56:24 -0600 Subject: [PATCH] feat(command.ts) throw error on alias present on slash command --- .../structures/commands/command-creator.ts | 1 + src/handler/structures/commands/command.ts | 16 +++++++++++----- src/handler/structures/errors.ts | 4 ++-- 3 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/handler/structures/commands/command-creator.ts b/src/handler/structures/commands/command-creator.ts index e69de29..8b13789 100644 --- a/src/handler/structures/commands/command-creator.ts +++ b/src/handler/structures/commands/command-creator.ts @@ -0,0 +1 @@ + diff --git a/src/handler/structures/commands/command.ts b/src/handler/structures/commands/command.ts index 85c049c..ec557cc 100644 --- a/src/handler/structures/commands/command.ts +++ b/src/handler/structures/commands/command.ts @@ -4,6 +4,7 @@ import Context from "../context"; import type * as Utils from '../../utilities/preprocessors/args'; import { None, Ok } from "ts-results"; import { CommandType } from "../../sern"; +import { SernError } from "../errors"; export abstract class Command { @@ -15,22 +16,27 @@ export abstract class Command { protected _alias : string[] | undefined; protected constructor ( commandType : CommandType, + alias : string[] | [], options?: ApplicationCommandOptionData[], - alias? : string[], name? : string | undefined ) { this._name = name; this._commandType = commandType; switch ( commandType ) { case CommandType.TEXT : { + this._options = undefined; this._alias = alias; - this._options = undefined; } break; - case CommandType.SLASH : case CommandType.BOTH : { - this._alias = undefined + case CommandType.SLASH : { + if(alias.length < 0) throw Error(SernError.NO_ALIAS); + this._options = options; + } break; + case CommandType.BOTH : { this._options = options; + this._alias = alias; } break; - + + } } diff --git a/src/handler/structures/errors.ts b/src/handler/structures/errors.ts index 7a09f2a..0a70ccc 100644 --- a/src/handler/structures/errors.ts +++ b/src/handler/structures/errors.ts @@ -1,4 +1,4 @@ export enum SernError { - RESERVED_EVENT = 'Cannot register the reserved ready event. Please use the init property.' - + RESERVED_EVENT = 'Cannot register the reserved ready event. Please use the init property.', + NO_ALIAS = 'You cannot provide an array with elements to a slash command.' }