Archived
TextCommand as an extension of BaseCommand
This commit is contained in:
1 parent
108bfb38d3
commit
e7ce848325
3 files changed
+41
-40
No files matched your search
@@ -1,27 +1,28 @@
|
||||
import { CommandType, BaseCommandInit } from "../types/BaseCommand";
|
||||
|
||||
export class BaseCommand {
|
||||
/**
|
||||
* Command name
|
||||
* @type {string}
|
||||
*/
|
||||
public readonly name: string;
|
||||
public readonly description: string;
|
||||
/**
|
||||
* Application command type
|
||||
* @type {CommandType}
|
||||
*/
|
||||
public readonly type: CommandType;
|
||||
public static nameRegExp: RegExp = /^[a-zA-Z]{1,32}$/;
|
||||
public static descriptionRegExp: RegExp = /^[a-zA-Z]{1,100}$/;
|
||||
|
||||
/**
|
||||
* @constructor
|
||||
* @param {BaseCommandInit} o - BaseCommand initialization options
|
||||
*/
|
||||
constructor(o: BaseCommandInit) {
|
||||
if (BaseCommand.nameRegExp.test(o.name)) {
|
||||
this.name = o.name;
|
||||
} else {
|
||||
throw new Error("Incorrect command name");
|
||||
}
|
||||
if (o.description) {
|
||||
if (BaseCommand.descriptionRegExp.test(o.description)) {
|
||||
this.description = o.description;
|
||||
} else {
|
||||
throw new Error("Incorrect command description");
|
||||
}
|
||||
} else {
|
||||
this.description = "No description";
|
||||
}
|
||||
this.type = o.type;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user