update help command to use per game commands

This commit is contained in:
RaidMax
2021-11-20 20:32:15 -06:00
parent 61a131be9d
commit 12cc5f1820
5 changed files with 98 additions and 74 deletions

View File

@ -503,80 +503,6 @@ namespace SharedLibraryCore.Commands
}
}
/// <summary>
/// Prints help information
/// </summary>
public class HelpCommand : Command
{
public HelpCommand(CommandConfiguration config, ITranslationLookup translationLookup) : base(config, translationLookup)
{
Name = "help";
Description = _translationLookup["COMMANDS_HELP_DESC"];
Alias = "h";
Permission = Permission.User;
RequiresTarget = false;
Arguments = new[]
{
new CommandArgument()
{
Name = _translationLookup["COMMANDS_ARGS_COMMANDS"],
Required = false
}
};
}
public override Task ExecuteAsync(GameEvent E)
{
string cmd = E.Data.Trim();
if (cmd.Length > 2)
{
bool found = false;
foreach (var command in E.Owner.Manager.GetCommands())
{
if (command.Name == cmd.ToLower() ||
command.Alias == cmd.ToLower())
{
E.Origin.Tell($"[^3{command.Name}^7] {command.Description}");
E.Origin.Tell(command.Syntax);
found = true;
}
}
if (!found)
{
E.Origin.Tell(_translationLookup["COMMANDS_HELP_NOTFOUND"]);
}
}
else
{
int count = 0;
StringBuilder helpResponse = new StringBuilder();
var CommandList = E.Owner.Manager.GetCommands();
foreach (Command C in CommandList)
{
if (E.Origin.Level >= C.Permission)
{
helpResponse.Append(" [^3" + C.Name + "^7] ");
if (count >= 4)
{
E.Origin.Tell(helpResponse.ToString());
helpResponse = new StringBuilder();
count = 0;
}
count++;
}
}
E.Origin.Tell(helpResponse.ToString());
E.Origin.Tell(_translationLookup["COMMANDS_HELP_MOREINFO"]);
}
return Task.CompletedTask;
}
}
/// <summary>
/// Fast restarts the map
/// </summary>