~ruther/NosSmooth

ref: 8b69e5448f0d365eb4830396b2767b3b3400665f NosSmooth/Core/NosSmooth.Game/Apis/DialogHandler.cs -rw-r--r-- 1.8 KiB
8b69e544 — František Boháček chore: bump versions 2 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
53
54
55
56
//
//  DialogHandler.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.Core.Client;
using NosSmooth.Game.Data.Dialogs;
using Remora.Results;

namespace NosSmooth.Game.Apis;

/// <summary>
/// Handles accepting and denying of dialogs.
/// </summary>
public class DialogHandler
{
    private readonly INostaleClient _client;

    /// <summary>
    /// Initializes a new instance of the <see cref="DialogHandler"/> class.
    /// </summary>
    /// <param name="client">The client.</param>
    public DialogHandler(INostaleClient client)
    {
        _client = client;
    }

    /// <summary>
    /// Accept the operation the dialog does.
    /// </summary>
    /// <param name="dialog">The opened dialog.</param>
    /// <param name="ct">The cancellation token used for cancelling the operation.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public Task<Result> AcceptAsync(Dialog dialog, CancellationToken ct = default)
        => _client.SendPacketAsync(dialog.AcceptCommand, ct);

    /// <summary>
    /// Try to deny the operation the dialog does.
    /// </summary>
    /// <remarks>
    /// Some dialogs do not allow denying, they are just ignored instead.
    /// </remarks>
    /// <param name="dialog">The opened dialog.</param>
    /// <param name="ct">The cancellation token used for cancelling the operation.</param>
    /// <returns>A result that may or may not have succeeded.</returns>
    public Task<Result> DenyAsync(Dialog dialog, CancellationToken ct = default)
    {
        if (dialog.DenyCommand is null)
        {
            return Task.FromResult(Result.FromSuccess());
        }

        return _client.SendPacketAsync(dialog.DenyCommand, ct);
    }
}
Do not follow this link