//
// 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 NosSmooth.ChatCommands;
using NosSmooth.Core.Client;
using NosSmooth.Packets.Enums;
using NosSmooth.Packets.Enums.Chat;
using NosSmooth.Packets.Server.Chat;
using Remora.Commands.Groups;
using Remora.Results;
namespace WalkCommands.Commands;
///
/// Group for detaching command that detaches the dll.
///
public class DetachCommand : CommandGroup
{
private readonly CancellationTokenSource _dllStop;
private readonly FeedbackService _feedbackService;
///
/// Initializes a new instance of the class.
///
/// The cancellation token source to stop the client.
/// The feedback service.
public DetachCommand(CancellationTokenSource dllStop, FeedbackService feedbackService)
{
_dllStop = dllStop;
_feedbackService = feedbackService;
}
///
/// Detach the dll.
///
/// A result that may or may not have succeeded.
public async Task HandleDetach()
{
var receiveResult = await _feedbackService.SendInfoMessageAsync("Going to detach!", CancellationToken);
if (!receiveResult.IsSuccess)
{
return receiveResult;
}
_dllStop.Cancel();
return Result.FromSuccess();
}
}