Replace nancy with kestrel

This commit is contained in:
runebaas 2018-05-14 02:33:49 +02:00
parent 3004b19209
commit 8c107de92e
No known key found for this signature in database
GPG key ID: 2677AF508D0300D6
13 changed files with 222 additions and 117 deletions

View file

@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
namespace Geekbot.net.WebApi.Controllers.Commands
{
public class CommandDto
{
public string Name { get; set; }
public string Category { get; set; }
public string Summary { get; set; }
public bool IsAdminCommand { get; set; }
public Array Aliases { get; set; }
public List<CommandParamDto> Params { get; set; }
}
}

View file

@ -0,0 +1,9 @@
namespace Geekbot.net.WebApi.Controllers.Commands
{
public class CommandParamDto
{
public string Summary { get; set; }
public string Default { get; set; }
public string Type { get; set; }
}
}

View file

@ -0,0 +1,41 @@
using System.Linq;
using Discord.Commands;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
namespace Geekbot.net.WebApi.Controllers.Commands
{
[EnableCors("AllowSpecificOrigin")]
public class HelpController : Controller
{
private readonly CommandService _commands;
public HelpController(CommandService commands)
{
_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,
Default = cmdParam.DefaultValue?.ToString() ?? null,
Type = cmdParam.Type?.ToString()
})
.ToList()
let param = string.Join(", !", cmd.Aliases)
select new CommandDto
{
Name = cmd.Name,
Summary = cmd.Summary,
IsAdminCommand = (param.Contains("admin")),
Aliases = cmd.Aliases.ToArray(),
Params = cmdParamsObj
}).ToList();
return Ok(commandList);
}
}
}

View file

@ -0,0 +1,9 @@
namespace Geekbot.net.WebApi.Controllers.Status
{
public class ApiStatusDto
{
public string GeekbotVersion { get; set; }
public string ApiVersion { get; set; }
public string Status { get; set; }
}
}

View file

@ -0,0 +1,22 @@
using Geekbot.net.Lib;
using Microsoft.AspNetCore.Cors;
using Microsoft.AspNetCore.Mvc;
namespace Geekbot.net.WebApi.Controllers.Status
{
[EnableCors("AllowSpecificOrigin")]
public class StatusController : Controller
{
[Route("/")]
public IActionResult GetCommands()
{
var responseBody = new ApiStatusDto
{
GeekbotVersion = Constants.BotVersion(),
ApiVersion = Constants.ApiVersion.ToString(),
Status = "Online"
};
return Ok(responseBody);
}
}
}