2020-01-26 19:06:50 -05:00
|
|
|
|
using System.Collections.Generic;
|
2015-08-20 01:06:44 -04:00
|
|
|
|
using System.Linq;
|
2017-05-26 18:49:27 -04:00
|
|
|
|
using System.Threading.Tasks;
|
2020-01-26 19:06:50 -05:00
|
|
|
|
using SharedLibraryCore.Commands;
|
|
|
|
|
using SharedLibraryCore.Configuration;
|
2018-11-05 22:01:29 -05:00
|
|
|
|
using SharedLibraryCore.Database.Models;
|
2020-01-26 19:06:50 -05:00
|
|
|
|
using SharedLibraryCore.Interfaces;
|
2017-11-25 20:29:58 -05:00
|
|
|
|
|
2018-04-08 02:44:42 -04:00
|
|
|
|
namespace SharedLibraryCore
|
2015-08-20 01:06:44 -04:00
|
|
|
|
{
|
2020-01-26 19:06:50 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Abstract class for command
|
|
|
|
|
/// </summary>
|
|
|
|
|
public abstract class Command : IManagerCommand
|
2017-11-15 16:04:13 -05:00
|
|
|
|
{
|
2020-01-26 19:06:50 -05:00
|
|
|
|
private readonly CommandConfiguration _config;
|
|
|
|
|
protected readonly ITranslationLookup _translationLookup;
|
2020-05-16 12:54:01 -04:00
|
|
|
|
protected ILogger logger;
|
2017-11-15 16:04:13 -05:00
|
|
|
|
|
2020-01-26 19:06:50 -05:00
|
|
|
|
public Command(CommandConfiguration config, ITranslationLookup layout)
|
|
|
|
|
{
|
|
|
|
|
_config = config;
|
|
|
|
|
_translationLookup = layout;
|
2015-08-20 01:06:44 -04:00
|
|
|
|
}
|
|
|
|
|
|
2020-01-26 19:06:50 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Executes the command
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="E"></param>
|
|
|
|
|
/// <returns></returns>
|
2018-04-13 02:32:30 -04:00
|
|
|
|
abstract public Task ExecuteAsync(GameEvent E);
|
2015-08-20 01:06:44 -04:00
|
|
|
|
|
2020-01-26 19:06:50 -05:00
|
|
|
|
/// <summary>
|
|
|
|
|
/// Specifies the name and string that triggers the command
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Name
|
|
|
|
|
{
|
|
|
|
|
get => name;
|
|
|
|
|
protected set
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
name = _config?.Commands[GetType().Name].Name ?? value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (KeyNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
name = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private string name;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Specifies the command description
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Description { get; protected set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Helper property to provide the syntax of the command
|
|
|
|
|
/// </summary>
|
2020-07-31 21:40:03 -04:00
|
|
|
|
public string Syntax => $"{_translationLookup["COMMAND_HELP_SYNTAX"]} {_config.CommandPrefix}{Alias} {string.Join(" ", Arguments.Select(a => $"<{(a.Required ? "" : _translationLookup["COMMAND_HELP_OPTIONAL"] + " ")}{a.Name}>"))}";
|
2020-01-26 19:06:50 -05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Alternate name for this command to be executed by
|
|
|
|
|
/// </summary>
|
|
|
|
|
public string Alias
|
|
|
|
|
{
|
|
|
|
|
get => alias;
|
|
|
|
|
protected set
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
alias = _config?.Commands[GetType().Name].Alias ?? value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (KeyNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
alias = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private string alias;
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Helper property to determine the number of required args
|
|
|
|
|
/// </summary>
|
2017-11-15 16:04:13 -05:00
|
|
|
|
public int RequiredArgumentCount => Arguments.Count(c => c.Required);
|
2020-01-26 19:06:50 -05:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Indicates if the command requires a target to execute on
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool RequiresTarget { get; protected set; }
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Minimum permission level to execute command
|
|
|
|
|
/// </summary>
|
|
|
|
|
public EFClient.Permission Permission
|
|
|
|
|
{
|
|
|
|
|
get => permission;
|
|
|
|
|
protected set
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
permission = _config?.Commands[GetType().Name].MinimumPermission ?? value;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
catch (KeyNotFoundException)
|
|
|
|
|
{
|
|
|
|
|
permission = value;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
private EFClient.Permission permission;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Argument list for the command
|
|
|
|
|
/// </summary>
|
|
|
|
|
public CommandArgument[] Arguments { get; protected set; } = new CommandArgument[0];
|
2020-04-26 22:12:49 -04:00
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// indicates if this command allows impersonation (run as)
|
|
|
|
|
/// </summary>
|
|
|
|
|
public bool AllowImpersonation { get; set; }
|
2020-07-31 21:40:03 -04:00
|
|
|
|
|
|
|
|
|
public bool IsBroadcast { get; set; }
|
2015-08-20 01:06:44 -04:00
|
|
|
|
}
|
|
|
|
|
}
|