using SharedLibraryCore;
using SharedLibraryCore.Commands;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Interfaces;
using System;
using System.Threading.Tasks;
using static SharedLibraryCore.Database.Models.EFClient;
namespace IW4MAdmin.Application.Misc
{
///
/// generic script command implementation
///
public class ScriptCommand : Command
{
private readonly Action _executeAction;
public ScriptCommand(string name, string alias, string description, Permission permission,
CommandArgument[] args, Action executeAction, CommandConfiguration config, ITranslationLookup layout)
: base(config, layout)
{
_executeAction = executeAction;
Name = name;
Alias = alias;
Description = description;
Permission = permission;
Arguments = args;
}
public override Task ExecuteAsync(GameEvent E)
{
if (_executeAction == null)
{
throw new InvalidOperationException($"No execute action defined for command \"{Name}\"");
}
return Task.Run(() => _executeAction(E));
}
}
}