BaseCommand structure

This commit is contained in:
mmacierzanka committed 2021-09-04 18:32:38 +02:00
1 parent 3ff3086e3e
commit 996c3733a0
2 files changed
+34

No files matched your search

+27
View File
@@ -0,0 +1,27 @@
import { CommandType, BaseCommandInit } from "../types/BaseCommand";
export class BaseCommand {
public readonly name: string;
public readonly description: string;
public readonly type: CommandType;
public static nameRegExp: RegExp = /^[a-zA-Z]{1,32}$/;
public static descriptionRegExp: RegExp = /^[a-zA-Z]{1,100}$/;
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;
}
}
+7
View File
@@ -0,0 +1,7 @@
export interface BaseCommandInit {
name: string;
description?: string;
type: CommandType;
}
export type CommandType = "CHAT" | "MESSAGE" | "USER";