Binato/server/commands/Help.ts

41 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-09-10 12:59:22 +01:00
import Channel from "../objects/Channel";
import User from "../objects/User";
import BaseCommand from "./BaseCommand";
import Shared from "../objects/Shared";
import ICommand from "../interfaces/ICommand";
2023-08-20 13:03:01 +01:00
2023-09-10 12:59:22 +01:00
export default class HelpCommand extends BaseCommand {
2023-08-20 13:03:01 +01:00
public readonly helpDescription:string = "Shows this message! :)";
private readonly commandList:{ [id:string]: ICommand };
private commandKeys:Array<string> = new Array<string>();
public constructor(shared:Shared, commands:{ [id:string]: ICommand }) {
super(shared);
this.commandList = commands;
}
public exec(channel:Channel, sender:User, args:Array<string>) {
if (this.commandKeys.length === 0) {
this.commandKeys = Object.keys(this.commandList);
}
// All commands
if (args.length === 0) {
let constructedHelp = "Help:\n";
for (const key of this.commandKeys) {
2023-08-20 13:03:01 +01:00
constructedHelp += ` !${key} - ${this.commandList[key].helpDescription}\n`;
}
channel.SendBotMessage(constructedHelp.slice(0, constructedHelp.length - 1));
return;
}
// Command page
const commandName = args[0].toLowerCase();
if (commandName in this.commandList) {
channel.SendBotMessage(this.commandList[commandName].helpText);
} else {
channel.SendBotMessage("No help page was found for that command");
}
}
}