using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using SharedLibraryCore.Commands;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
namespace SharedLibraryCore
{
///
/// Abstract class for command
///
public abstract class Command : IManagerCommand
{
private readonly CommandConfiguration _config;
protected readonly ITranslationLookup _translationLookup;
public Command(CommandConfiguration config, ITranslationLookup layout)
{
_config = config;
_translationLookup = layout;
}
///
/// Executes the command
///
///
///
abstract public Task ExecuteAsync(GameEvent E);
///
/// Specifies the name and string that triggers the command
///
public string Name
{
get => name;
protected set
{
try
{
name = _config?.Commands[GetType().Name].Name ?? value;
}
catch (KeyNotFoundException)
{
name = value;
}
}
}
private string name;
///
/// Specifies the command description
///
public string Description { get; protected set; }
///
/// Helper property to provide the syntax of the command
///
public string Syntax => $"{_translationLookup["COMMAND_HELP_SYNTAX"]} !{Alias} {string.Join(" ", Arguments.Select(a => $"<{(a.Required ? "" : _translationLookup["COMMAND_HELP_OPTIONAL"] + " ")}{a.Name}>"))}";
///
/// Alternate name for this command to be executed by
///
public string Alias
{
get => alias;
protected set
{
try
{
alias = _config?.Commands[GetType().Name].Alias ?? value;
}
catch (KeyNotFoundException)
{
alias = value;
}
}
}
private string alias;
///
/// Helper property to determine the number of required args
///
public int RequiredArgumentCount => Arguments.Count(c => c.Required);
///
/// Indicates if the command requires a target to execute on
///
public bool RequiresTarget { get; protected set; }
///
/// Minimum permission level to execute command
///
public EFClient.Permission Permission
{
get => permission;
protected set
{
try
{
permission = _config?.Commands[GetType().Name].MinimumPermission ?? value;
}
catch (KeyNotFoundException)
{
permission = value;
}
}
}
private EFClient.Permission permission;
///
/// Argument list for the command
///
public CommandArgument[] Arguments { get; protected set; } = new CommandArgument[0];
}
}