Replace nancy with kestrel
This commit is contained in:
parent
3004b19209
commit
8c107de92e
13 changed files with 222 additions and 117 deletions
15
Geekbot.net/WebApi/Controllers/Commands/CommandDto.cs
Normal file
15
Geekbot.net/WebApi/Controllers/Commands/CommandDto.cs
Normal 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; }
|
||||
}
|
||||
}
|
|
@ -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; }
|
||||
}
|
||||
}
|
41
Geekbot.net/WebApi/Controllers/Commands/HelpController.cs
Normal file
41
Geekbot.net/WebApi/Controllers/Commands/HelpController.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
9
Geekbot.net/WebApi/Controllers/Status/ApiStatusDto.cs
Normal file
9
Geekbot.net/WebApi/Controllers/Status/ApiStatusDto.cs
Normal 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; }
|
||||
}
|
||||
}
|
22
Geekbot.net/WebApi/Controllers/Status/StatusController.cs
Normal file
22
Geekbot.net/WebApi/Controllers/Status/StatusController.cs
Normal 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);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue