50 lines
1.7 KiB
C#
50 lines
1.7 KiB
C#
using System.Collections.Generic;
|
|
using System.Text;
|
|
using DeukBot4.MessageHandlers.Permissions;
|
|
|
|
namespace DeukBot4.MessageHandlers.CommandHandler
|
|
{
|
|
public static class HelpCommandGenerator
|
|
{
|
|
public static string GenerateFullHelp(PermissionLevel level)
|
|
{
|
|
var dic = new Dictionary<string, Dictionary<string, string>>();
|
|
foreach (var command in CommandHandler.Commands)
|
|
{
|
|
if (command.Value.Permission > level)
|
|
continue;
|
|
if (!command.Value.HasHelp)
|
|
continue;
|
|
if (!dic.TryGetValue(command.Value.CommandContainer.Name, out var entry))
|
|
{
|
|
dic.Add(command.Value.CommandContainer.Name, new Dictionary<string, string>());
|
|
entry = dic[command.Value.CommandContainer.Name];
|
|
}
|
|
entry.Add(command.Value.Name, command.Value.ShortHelp);
|
|
}
|
|
var sb = new StringBuilder();
|
|
foreach (var entry in dic)
|
|
{
|
|
sb.Append($"**{entry.Key}**\n");
|
|
foreach (var cmd in entry.Value)
|
|
{
|
|
sb.Append($"``{cmd.Key}`` - {cmd.Value}\n");
|
|
}
|
|
}
|
|
|
|
return sb.ToString();
|
|
}
|
|
|
|
public static string GenerateSpecificHelp(string command, PermissionLevel level)
|
|
{
|
|
if (!CommandHandler.Commands.TryGetValue(command, out var cmd))
|
|
return null;
|
|
if (cmd.Permission > level)
|
|
return null;
|
|
if (!cmd.HasHelp)
|
|
return null;
|
|
|
|
return $"**{cmd.Name}** - *{cmd.LongHelp}*";
|
|
}
|
|
}
|
|
} |