Splitting and renaming userinfo.cs, adding commands endpoint to api, minor refactor in other places
This commit is contained in:
parent
92015d8880
commit
09dbb6b14d
9 changed files with 364 additions and 230 deletions
75
Geekbot.net/WebApi/HelpController.cs
Normal file
75
Geekbot.net/WebApi/HelpController.cs
Normal file
|
@ -0,0 +1,75 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Reflection;
|
||||
using System.Threading.Tasks;
|
||||
using Discord;
|
||||
using Discord.Commands;
|
||||
using Nancy;
|
||||
using Geekbot.net.Lib;
|
||||
|
||||
namespace Geekbot.net.WebApi
|
||||
{
|
||||
public class HelpController : NancyModule
|
||||
{
|
||||
public HelpController()
|
||||
{
|
||||
Get("/v1/commands", args =>
|
||||
{
|
||||
var commands = getCommands().Result;
|
||||
|
||||
var commandList = new List<CommandDto>();
|
||||
foreach (var cmd in commands.Commands)
|
||||
{
|
||||
var cmdParamsObj = new List<CommandParamDto>();
|
||||
foreach (var cmdParam in cmd.Parameters)
|
||||
{
|
||||
var singleParamObj = new CommandParamDto()
|
||||
{
|
||||
Summary = cmdParam.Summary,
|
||||
Default = cmdParam?.DefaultValue?.ToString() ?? null,
|
||||
Type = cmdParam?.Type?.ToString()
|
||||
};
|
||||
cmdParamsObj.Add(singleParamObj);
|
||||
}
|
||||
|
||||
var param = string.Join(", !", cmd.Aliases);
|
||||
var cmdObj = new CommandDto()
|
||||
{
|
||||
Name = cmd.Name,
|
||||
Summary = cmd.Summary,
|
||||
IsAdminCommand = (param.Contains("admin")),
|
||||
Aliases = cmd.Aliases.ToArray(),
|
||||
Params = cmdParamsObj
|
||||
};
|
||||
commandList.Add(cmdObj);
|
||||
}
|
||||
return Response.AsJson(commandList);
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
private async Task<CommandService> getCommands()
|
||||
{
|
||||
var commands = new CommandService();
|
||||
await commands.AddModulesAsync(Assembly.GetEntryAssembly());
|
||||
return commands;
|
||||
}
|
||||
}
|
||||
|
||||
public class CommandDto
|
||||
{
|
||||
public string Name { get; set; }
|
||||
public string Summary { get; set; }
|
||||
public bool IsAdminCommand { get; set; }
|
||||
public Array Aliases { get; set; }
|
||||
public List<CommandParamDto> Params { get; set; }
|
||||
}
|
||||
|
||||
public class CommandParamDto
|
||||
{
|
||||
public string Summary { get; set; }
|
||||
public string Default { get; set; }
|
||||
public string Type { get; set; }
|
||||
}
|
||||
}
|
|
@ -1,17 +1,18 @@
|
|||
using Nancy;
|
||||
using Geekbot.net.Lib;
|
||||
|
||||
namespace Geekbot.net.WebApi
|
||||
{
|
||||
public class Status : NancyModule
|
||||
public class StatusController : NancyModule
|
||||
{
|
||||
public Status()
|
||||
public StatusController()
|
||||
{
|
||||
Get("/", args =>
|
||||
{
|
||||
var responseBody = new ApiStatusDto()
|
||||
{
|
||||
GeekbotVersion = "3.4",
|
||||
ApiVersion = "0.1",
|
||||
GeekbotVersion = Constants.BotVersion.ToString(),
|
||||
ApiVersion = Constants.ApiVersion.ToString(),
|
||||
Status = "Online"
|
||||
};
|
||||
return Response.AsJson(responseBody);
|
Loading…
Add table
Add a link
Reference in a new issue