2024-05-25 04:43:43 +00:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Text;
|
|
|
|
|
|
2024-05-27 12:29:01 +00:00
|
|
|
|
namespace Elisa.GameServer.Commands;
|
2024-05-25 04:43:43 +00:00
|
|
|
|
|
|
|
|
|
[CommandHandler("help", "Print out all commands with their description and example", "help")]
|
|
|
|
|
public class HelpCommand : Command
|
|
|
|
|
{
|
|
|
|
|
static readonly Dictionary<Type, CommandHandler?> commandAttributes = [];
|
|
|
|
|
|
|
|
|
|
public override void Execute(Dictionary<string, string> args)
|
|
|
|
|
{
|
|
|
|
|
base.Execute(args);
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder();
|
|
|
|
|
|
|
|
|
|
sb.AppendLine("Available Commands: ");
|
|
|
|
|
foreach (var command in CommandHandlerFactory.Commands.Where(x => x.Usage.HasFlag(CommandUsage.Console)))
|
|
|
|
|
{
|
|
|
|
|
if (!commandAttributes.TryGetValue(command.GetType(), out var attr))
|
|
|
|
|
{
|
|
|
|
|
attr = command.GetType().GetCustomAttribute(typeof(CommandHandler)) as CommandHandler;
|
|
|
|
|
commandAttributes[command.GetType()] = attr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (attr != null)
|
|
|
|
|
sb.AppendLine($" {attr.Name} - {attr.Description} (Example: {attr.Example})");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Console.Write(sb.ToString());
|
|
|
|
|
}
|
|
|
|
|
}
|