2018-05-03 00:56:06 +02:00
|
|
|
|
using System.Linq;
|
2017-10-03 00:22:26 +02:00
|
|
|
|
using System.Reflection;
|
|
|
|
|
using System.Threading.Tasks;
|
|
|
|
|
using Discord.Commands;
|
|
|
|
|
using Geekbot.net.Lib;
|
2018-04-30 23:44:19 +02:00
|
|
|
|
using Nancy;
|
2017-10-03 00:22:26 +02:00
|
|
|
|
|
2018-05-03 00:56:06 +02:00
|
|
|
|
namespace Geekbot.net.WebApi.Help
|
2017-10-03 00:22:26 +02:00
|
|
|
|
{
|
|
|
|
|
public class HelpController : NancyModule
|
|
|
|
|
{
|
|
|
|
|
public HelpController()
|
|
|
|
|
{
|
|
|
|
|
Get("/v1/commands", args =>
|
|
|
|
|
{
|
2018-04-30 23:44:19 +02:00
|
|
|
|
var commands = GetCommands().Result;
|
2017-10-03 00:22:26 +02:00
|
|
|
|
|
2018-04-30 23:44:19 +02:00
|
|
|
|
var commandList = (from cmd in commands.Commands
|
|
|
|
|
let cmdParamsObj = cmd.Parameters.Select(cmdParam => new CommandParamDto
|
2017-10-03 00:22:26 +02:00
|
|
|
|
{
|
|
|
|
|
Summary = cmdParam.Summary,
|
2018-04-30 23:44:19 +02:00
|
|
|
|
Default = cmdParam.DefaultValue?.ToString() ?? null,
|
|
|
|
|
Type = cmdParam.Type?.ToString()
|
|
|
|
|
})
|
|
|
|
|
.ToList()
|
|
|
|
|
let param = string.Join(", !", cmd.Aliases)
|
|
|
|
|
select new CommandDto
|
2017-10-03 00:22:26 +02:00
|
|
|
|
{
|
|
|
|
|
Name = cmd.Name,
|
|
|
|
|
Summary = cmd.Summary,
|
2017-10-12 16:34:10 +02:00
|
|
|
|
Category = cmd.Remarks ?? CommandCategories.Uncategorized,
|
2017-10-03 00:22:26 +02:00
|
|
|
|
IsAdminCommand = (param.Contains("admin")),
|
|
|
|
|
Aliases = cmd.Aliases.ToArray(),
|
|
|
|
|
Params = cmdParamsObj
|
2018-04-30 23:44:19 +02:00
|
|
|
|
}).ToList();
|
2017-10-03 00:22:26 +02:00
|
|
|
|
return Response.AsJson(commandList);
|
|
|
|
|
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2018-04-30 23:44:19 +02:00
|
|
|
|
private async Task<CommandService> GetCommands()
|
2017-10-03 00:22:26 +02:00
|
|
|
|
{
|
|
|
|
|
var commands = new CommandService();
|
|
|
|
|
await commands.AddModulesAsync(Assembly.GetEntryAssembly());
|
|
|
|
|
return commands;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|