DeukBot4/DeukBot4/MessageHandlers/CommandHandler/Command.cs

55 lines
2.0 KiB
C#

using System.Diagnostics;
using System.Reflection;
using System.Threading.Tasks;
using DeukBot4.MessageHandlers.CommandHandler.RequestStructure;
using DeukBot4.MessageHandlers.Permissions;
using Discord.WebSocket;
namespace DeukBot4.MessageHandlers.CommandHandler
{
public class Command
{
public Command(string name, PermissionLevel permission, string shortHelp, string longHelp,
ParameterMatcher.ParameterType[][] parameterTypes, MethodInfo function, CommandContainerBase commandContainer)
{
Name = name;
Permission = permission;
ShortHelp = shortHelp;
LongHelp = longHelp;
Function = function;
CommandContainer = commandContainer;
ParameterTypes = parameterTypes;
HasHelp = true;
}
public Command(string name, PermissionLevel permission, ParameterMatcher.ParameterType[][] parameterTypes,
MethodInfo function, CommandContainerBase commandContainer)
{
Name = name;
Permission = permission;
Function = function;
CommandContainer = commandContainer;
ParameterTypes = parameterTypes;
HasHelp = false;
}
public string Name { get; }
public PermissionLevel Permission { get; }
public string ShortHelp { get; }
public string LongHelp { get; }
public MethodInfo Function { get; }
public CommandContainerBase CommandContainer { get; }
public bool HasHelp { get; }
public ParameterMatcher.ParameterType[][] ParameterTypes { get; }
private string[] _parameterMatchers;
public string[] ParametersMatchers =>
_parameterMatchers ?? (_parameterMatchers = ParameterMatcher.GenerateRegex(this));
public async Task Invoke(CommandRequest request)
{
await (Task) Function.Invoke(CommandContainer, new object[] {request});
}
}
}