using SharedLibraryCore;
using SharedLibraryCore.Commands;
using SharedLibraryCore.Configuration;
using SharedLibraryCore.Database.Models;
using SharedLibraryCore.Interfaces;
using System.Threading.Tasks;
namespace ClanTagRankCommands.Commands
{
///
/// Example script command
///
///
public class GetRankCommand : Command
{
readonly string rank = "rank";
string rank_string;
private readonly IMetaService _metaService;
private readonly IConfigurationHandler _configurationHandler;
private Configuration Config;
public GetRankCommand(CommandConfiguration config, ITranslationLookup lookup, IMetaService metaService, IConfigurationHandlerFactory configurationHandlerFactory) : base(config, lookup)
{
_metaService = metaService;
_configurationHandler = configurationHandlerFactory.GetConfigurationHandler("ClanTagRankCommands");
if (_configurationHandler.Configuration() == null)
{
_configurationHandler.Set((Configuration)new Configuration().Generate());
_configurationHandler.Save();
}
Config = _configurationHandler.Configuration();
Name = "GetRank";
Description = "Get a user's clan tag Rank (does not give permissions)";
Alias = "Gr";
Permission = EFClient.Permission.Trusted;
RequiresTarget = true;
Arguments = new[]
{
new CommandArgument()
{
}
};
}
public override async Task ExecuteAsync(GameEvent E)
{
//var S = E.Owner;
rank_string = "none";
if(E.Target is not null)
{
var rank_player_var = await _metaService.GetPersistentMeta(rank, E.Target);
if (rank_player_var == null)
{
await _metaService.AddPersistentMeta(rank, "none", E.Target);
rank_player_var = await _metaService.GetPersistentMeta(rank, E.Target);
}
if (rank_string.Length > 0 && rank_string.Length < 9)
{
//await _metaService.AddPersistentMeta(rank, rank_string, E.Target);
rank_player_var = await _metaService.GetPersistentMeta(rank, E.Target);
if(rank_player_var.Value == "none" || rank_player_var.Value == "None" || rank_player_var.Value == "NONE")
{
//E.Origin.Tell(E.Target.Name + "'s rank has been reset");
rank_string = E.Target.Level.ClanTag(Config);
E.Origin.Tell("[" + rank_string + "]" + E.Target.Name );
}
else
{
rank_string = rank_player_var.Value;
E.Origin.Tell("[" + rank_player_var.Value + "]" + E.Target.Name);
}
}
}
}
}
}