~ruther/NosSmooth

ref: 5b880eadd917d5af4c6f84bea3b1640d63a65722 NosSmooth/Samples/WalkCommands/Commands/DetachCommand.cs -rw-r--r-- 1.6 KiB
5b880ead — František Boháček feat(packets)!: let the user add the default packet converters 3 years ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
//
//  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;

/// <summary>
/// Group for detaching command that detaches the dll.
/// </summary>
public class DetachCommand : CommandGroup
{
    private readonly CancellationTokenSource _dllStop;
    private readonly FeedbackService _feedbackService;

    /// <summary>
    /// Initializes a new instance of the <see cref="DetachCommand"/> class.
    /// </summary>
    /// <param name="dllStop">The cancellation token source to stop the client.</param>
    /// <param name="feedbackService">The feedback service.</param>
    public DetachCommand(CancellationTokenSource dllStop, FeedbackService feedbackService)
    {
        _dllStop = dllStop;
        _feedbackService = feedbackService;
    }

    /// <summary>
    /// Detach the dll.
    /// </summary>
    /// <returns>A result that may or may not have succeeded.</returns>
    public async Task<Result> HandleDetach()
    {
        var receiveResult = await _feedbackService.SendInfoMessageAsync("Going to detach!", CancellationToken);

        if (!receiveResult.IsSuccess)
        {
            return receiveResult;
        }

        _dllStop.Cancel();
        return Result.FromSuccess();
    }
}
Do not follow this link