//
// DetachCommand.cs
//
// Copyright (c) František Boháček. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
using NosCore.Packets.Enumerations;
using NosCore.Packets.ServerPackets.Chats;
using NosSmooth.Core.Client;
using Remora.Results;
namespace WalkCommands.Commands;
///
/// Group for detaching command that detaches the dll.
///
public class DetachCommand
{
private readonly CancellationTokenSource _dllStop;
private readonly INostaleClient _client;
///
/// Initializes a new instance of the class.
///
/// The cancellation token source to stop the client.
/// The nostale client.
public DetachCommand(CancellationTokenSource dllStop, INostaleClient client)
{
_dllStop = dllStop;
_client = client;
}
///
/// Detach the dll.
///
/// A result that may or may not have succeeded.
public async Task HandleDetach()
{
var receiveResult = await _client.ReceivePacketAsync(new SayPacket
{
Message = "Going to detach!",
Type = SayColorType.Green
});
if (!receiveResult.IsSuccess)
{
return receiveResult;
}
_dllStop.Cancel();
return Result.FromSuccess();
}
}