geekbot/Geekbot.net/Modules/Help.cs

48 lines
1.6 KiB
C#
Raw Normal View History

2017-09-15 22:56:03 +02:00
using System.Linq;
using System.Text;
using System.Threading.Tasks;
2017-04-17 16:58:48 +02:00
using Discord.Commands;
namespace Geekbot.net.Modules
{
public class Help : ModuleBase
{
2017-09-15 22:56:03 +02:00
private readonly CommandService commands;
public Help(CommandService commands)
{
this.commands = commands;
}
[Command("help", RunMode = RunMode.Async)]
[Summary("List all Commands")]
2017-04-17 16:58:48 +02:00
public async Task GetHelp()
{
2017-09-15 22:56:03 +02:00
var sb = new StringBuilder();
sb.AppendLine("```");
sb.AppendLine("**Geekbot Command list**");
sb.AppendLine("");
sb.AppendLine(tp("Name", 15) + tp("Parameters", 19) + "Description");
foreach (var cmd in commands.Commands)
2017-04-17 16:58:48 +02:00
{
2017-09-15 22:56:03 +02:00
var param = string.Join(", !", cmd.Aliases);
2017-04-17 16:58:48 +02:00
if (!param.Contains("admin"))
2017-09-15 22:56:03 +02:00
if (cmd.Parameters.Any())
sb.AppendLine(tp(param, 15) +
tp(string.Join(",", cmd.Parameters.Select(e => e.Summary)), 19) +
cmd.Summary);
else
sb.AppendLine(tp(param, 34) + cmd.Summary);
2017-04-17 16:58:48 +02:00
}
2017-09-15 22:56:03 +02:00
sb.AppendLine("```");
var dm = await Context.User.GetOrCreateDMChannelAsync();
await dm.SendMessageAsync(sb.ToString());
}
// Table Padding, short function name because of many usages
private string tp(string text, int shouldHave)
{
return text.PadRight(shouldHave);
2017-04-17 16:58:48 +02:00
}
}
}