90 lines
3.6 KiB
C#
90 lines
3.6 KiB
C#
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using Data.Models;
|
|
using Data.Models.Client;
|
|
using SharedLibraryCore;
|
|
using SharedLibraryCore.Commands;
|
|
using SharedLibraryCore.Configuration;
|
|
using SharedLibraryCore.Dtos;
|
|
using SharedLibraryCore.Interfaces;
|
|
|
|
|
|
namespace ClanTagRankCommands.Commands
|
|
{
|
|
public class InviteGuestCommand : Command
|
|
{
|
|
private readonly IMetaServiceV2 _metaService;
|
|
|
|
|
|
public InviteGuestCommand(CommandConfiguration config, ITranslationLookup layout, IMetaServiceV2 metaService) :
|
|
base(config, layout)
|
|
{
|
|
Name = "inviteGuest";
|
|
Description = "invite a guest to play on donator server (use !find to get @id to invite)";
|
|
Alias = "guest";
|
|
Permission = EFClient.Permission.Trusted;
|
|
RequiresTarget = true;
|
|
Arguments = new[]
|
|
{
|
|
new CommandArgument
|
|
{
|
|
Name = "Player",
|
|
Required = true
|
|
}
|
|
};
|
|
|
|
_metaService = metaService;
|
|
}
|
|
|
|
public override async Task ExecuteAsync(GameEvent gameEvent)
|
|
{
|
|
if (gameEvent.Target.Level >= gameEvent.Origin.Level && gameEvent.Origin.Level != EFClient.Permission.Creator)
|
|
{
|
|
gameEvent.Origin.Tell("You can't invite someone with the same or higher permissions than you");
|
|
return;
|
|
}
|
|
var token = gameEvent.Owner.Manager.CancellationToken;
|
|
var clienttag = await _metaService.GetPersistentMetaByLookup("ClientTagV2", "ClientTagNameV2", gameEvent.Target.ClientId, token);
|
|
if (gameEvent.Target is not null && gameEvent.Target.IsIngame && (gameEvent.Target.Tag is null))
|
|
{
|
|
|
|
gameEvent.Target.Tell($"you have been temporarily invited to join Donator servers by {gameEvent.Origin.Name}");
|
|
}
|
|
if (gameEvent.Target is not null && clienttag is not null)
|
|
{
|
|
if ((clienttag?.Value.Contains("Guest") ?? false))
|
|
{
|
|
gameEvent.Target.Tag = null;
|
|
await _metaService.RemovePersistentMeta(EFMeta.ClientTagV2, gameEvent.Target.ClientId, gameEvent.Owner.Manager.CancellationToken);
|
|
gameEvent.Target.Tell($"Your guest invite has been revoked by {gameEvent.Origin.Name}");
|
|
gameEvent.Origin.Tell($"Guest invite has been revoked for {gameEvent.Target.Name}");
|
|
return;
|
|
|
|
}
|
|
else if((clienttag?.Value.Contains("Donator") ?? false) || (clienttag?.Value.Contains("VIP") ?? false))
|
|
{
|
|
gameEvent.Origin.Tell($"Can't set {clienttag?.Value} {gameEvent.Target.Name} to Guest, they already have a rank.");
|
|
return;
|
|
}
|
|
}
|
|
else if(gameEvent.Target is null)
|
|
{
|
|
gameEvent.Origin.Tell($"Target player is undefined");
|
|
return;
|
|
}
|
|
|
|
|
|
|
|
|
|
var availableTags = await _metaService.GetPersistentMetaValue<List<LookupValue<string>>>(EFMeta.ClientTagNameV2, token);
|
|
var matchingTag = availableTags.FirstOrDefault(tag => tag.Value == "Guest".Trim());
|
|
|
|
gameEvent.Target.Tag = matchingTag.Value;
|
|
await _metaService.SetPersistentMetaForLookupKey(EFMeta.ClientTagV2, EFMeta.ClientTagNameV2, matchingTag.Id,
|
|
gameEvent.Target.ClientId, token);
|
|
gameEvent.Origin.Tell($"Temporarily set {gameEvent.Target.Name} to Guest");
|
|
}
|
|
}
|
|
}
|