54 lines
1.8 KiB
C#
54 lines
1.8 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)
|
|
{
|
|
var token = gameEvent.Owner.Manager.CancellationToken;
|
|
|
|
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");
|
|
}
|
|
}
|
|
}
|