Start help command tests

This commit is contained in:
Ethan Lane 2022-01-01 17:08:02 +00:00
parent ceb5f6c148
commit 6994a339b6
Signed by: Vylpes
GPG key ID: EED233CC06D12504
2 changed files with 228 additions and 11 deletions

View file

@ -3,9 +3,10 @@ import { ICommandContext } from "../contracts/ICommandContext";
import ErrorEmbed from "../helpers/embeds/ErrorEmbed";
import PublicEmbed from "../helpers/embeds/PublicEmbed";
import StringTools from "../helpers/StringTools";
import ICommandReturnContext from "../contracts/ICommandReturnContext";
import { Command } from "../type/command";
interface ICommandData {
export interface ICommandData {
Exists: boolean;
Name?: string;
Category?: string;
@ -19,15 +20,15 @@ export default class Help extends Command {
super._category = "General";
}
public override execute(context: ICommandContext) {
public override execute(context: ICommandContext): ICommandReturnContext {
if (context.args.length == 0) {
this.SendAll(context);
return this.SendAll(context);
} else {
this.SendSingle(context);
return this.SendSingle(context);
}
}
private SendAll(context: ICommandContext) {
public SendAll(context: ICommandContext): ICommandReturnContext {
const allCommands = this.GetAllCommandData();
const cateogries = this.DetermineCategories(allCommands);
@ -40,15 +41,24 @@ export default class Help extends Command {
});
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [ embed ]
};
}
private SendSingle(context: ICommandContext) {
public SendSingle(context: ICommandContext): ICommandReturnContext {
const command = this.GetCommandData(context.args[0]);
if (!command.Exists) {
const errorEmbed = new ErrorEmbed(context, "Command does not exist");
errorEmbed.SendToCurrentChannel();
return;
return {
commandContext: context,
embeds: [ errorEmbed ]
};
}
const embed = new PublicEmbed(context, StringTools.Capitalise(command.Name!), "");
@ -56,9 +66,14 @@ export default class Help extends Command {
embed.addField("Required Roles", StringTools.Capitalise(command.Roles!.join(", ")) || "*none*");
embed.SendToCurrentChannel();
return {
commandContext: context,
embeds: [ embed ]
};
}
private GetAllCommandData(): ICommandData[] {
public GetAllCommandData(): ICommandData[] {
const result: ICommandData[] = [];
const folder = process.env.FOLDERS_COMMANDS!;
@ -82,7 +97,7 @@ export default class Help extends Command {
return result;
}
private GetCommandData(name: string): ICommandData {
public GetCommandData(name: string): ICommandData {
const folder = process.env.FOLDERS_COMMANDS!;
const path = `${process.cwd()}/${folder}/${name}.ts`;
@ -105,7 +120,7 @@ export default class Help extends Command {
return data;
}
private DetermineCategories(commands: ICommandData[]): string[] {
public DetermineCategories(commands: ICommandData[]): string[] {
const result: string[] = [];
commands.forEach(cmd => {
@ -116,4 +131,4 @@ export default class Help extends Command {
return result;
}
}
}