using SharedLibraryCore; using SharedLibraryCore.Commands; using SharedLibraryCore.Configuration; using SharedLibraryCore.Database.Models; using SharedLibraryCore.Interfaces; using System; using System.Threading.Tasks; namespace ClanTagRankCommands.Commands { /// /// Example script command /// public class ResetRankCommand : Command { readonly string rank = "rank"; string rank_string; private readonly IMetaService _metaService; private readonly IConfigurationHandler _configurationHandler; private Configuration Config; public ResetRankCommand(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 = "ResetRank"; Description = "set a user's clan tag Rank (does not give permissions)"; Alias = "rr"; Permission = EFClient.Permission.Administrator; RequiresTarget = true; Arguments = new[] { new CommandArgument() { //Name = "rank", //Required = false } }; } public override async Task ExecuteAsync(GameEvent E) { //var S = E.Owner; rank_string = "none"; if(E.Target is object) { await _metaService.AddPersistentMeta(rank, rank_string, E.Target); rank_string = E.Target.Level.ClanTag(Config); E.Origin.Tell(E.Target.Name + "'s rank has been reset to: " + rank_string); if (E.Target.IsIngame && E.Target is object) { await E.Owner.ExecuteCommandAsync("setclantag" + " " + E.Target.ClientNumber.ToString() + " " + rank_string.ToString()); //await E.Owner.SetDvarAsync("sv_iw4madmin_role", "setRole;" + E.Target.ClientNumber.ToString() + ";" + rank_string.ToString()); await E.Owner.ExecuteCommandAsync("setrole " + E.Target.ClientNumber.ToString() + " " + rank_string.ToString()); } } } } }