2018-05-14 02:33:49 +02:00
|
|
|
|
using System.Linq;
|
|
|
|
|
using Discord.Commands;
|
|
|
|
|
using Microsoft.AspNetCore.Cors;
|
|
|
|
|
using Microsoft.AspNetCore.Mvc;
|
|
|
|
|
|
|
|
|
|
namespace Geekbot.net.WebApi.Controllers.Commands
|
|
|
|
|
{
|
|
|
|
|
[EnableCors("AllowSpecificOrigin")]
|
2018-05-15 01:18:26 +02:00
|
|
|
|
public class CommandController : Controller
|
2018-05-14 02:33:49 +02:00
|
|
|
|
{
|
|
|
|
|
private readonly CommandService _commands;
|
|
|
|
|
|
2018-05-15 01:18:26 +02:00
|
|
|
|
public CommandController(CommandService commands)
|
2018-05-14 02:33:49 +02:00
|
|
|
|
{
|
|
|
|
|
_commands = commands;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
[Route("/v1/commands")]
|
|
|
|
|
public IActionResult GetCommands()
|
|
|
|
|
{
|
|
|
|
|
var commandList = (from cmd in _commands.Commands
|
|
|
|
|
let cmdParamsObj = cmd.Parameters.Select(cmdParam => new CommandParamDto
|
|
|
|
|
{
|
|
|
|
|
Summary = cmdParam.Summary,
|
2018-05-15 01:18:26 +02:00
|
|
|
|
Default = cmdParam.DefaultValue?.ToString(),
|
2018-05-14 02:33:49 +02:00
|
|
|
|
Type = cmdParam.Type?.ToString()
|
|
|
|
|
})
|
|
|
|
|
.ToList()
|
|
|
|
|
let param = string.Join(", !", cmd.Aliases)
|
|
|
|
|
select new CommandDto
|
|
|
|
|
{
|
|
|
|
|
Name = cmd.Name,
|
|
|
|
|
Summary = cmd.Summary,
|
2018-05-15 01:18:26 +02:00
|
|
|
|
IsAdminCommand = param.Contains("admin") || param.Contains("owner"),
|
2018-09-05 21:13:43 +02:00
|
|
|
|
Aliases = cmd.Aliases.ToList(),
|
2018-05-14 02:33:49 +02:00
|
|
|
|
Params = cmdParamsObj
|
|
|
|
|
}).ToList();
|
2018-09-05 21:13:43 +02:00
|
|
|
|
return Ok(commandList.FindAll(e => !e.Aliases[0].StartsWith("owner")));
|
2018-05-14 02:33:49 +02:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|